Skip to content

Commit

Permalink
Finish
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometrically committed Jul 24, 2024
1 parent a32070e commit b506fb7
Show file tree
Hide file tree
Showing 39 changed files with 1,398 additions and 586 deletions.
4 changes: 2 additions & 2 deletions apps/app-frontend/src/pages/Browse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ async function refreshSearch() {
if (hideAlreadyInstalled.value) {
const installedMods = Object.values(instanceProjects.value)
.filter((x) => x.metadata.type === 'modrinth')
.filter((x) => x.metadata)
.map((x) => x.metadata.project_id)
installedMods.map((x) => [`project_id != ${x}`]).forEach((x) => formattedFacets.push(x))
Expand Down Expand Up @@ -253,7 +253,7 @@ async function refreshSearch() {
if (instanceContext.value) {
for (const val of rawResults.result.hits) {
val.installed = Object.values(instanceProjects.value).some(
(x) => x.metadata.type === 'modrinth' && x.metadata.project_id === val.project_id,
(x) => x.metadata && x.metadata.project_id === val.project_id,
)
}
}
Expand Down
62 changes: 24 additions & 38 deletions apps/app-frontend/src/pages/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ watch(
setSettings.hooks.post_exit = null
}
if (!setSettings.custom_dir) {
setSettings.custom_dir = null
}
await set(setSettings)
},
{ deep: true },
Expand Down Expand Up @@ -109,31 +113,17 @@ async function signInAfter() {
await fetchCredentials()
}
// async function findLauncherDir() {
// const newDir = await open({
// multiple: false,
// directory: true,
// title: 'Select a new app directory',
// })
//
// const writeable = await is_dir_writeable(newDir)
//
// if (!writeable) {
// handleError('The selected directory does not have proper permissions for write access.')
// return
// }
//
// if (newDir) {
// settingsDir.value = newDir
// await refreshDir()
// }
// }
//
// async function refreshDir() {
// await change_config_dir(settingsDir.value).catch(handleError)
// settings.value = await accessSettings().catch(handleError)
// settingsDir.value = settings.value.loaded_config_dir
// }
async function findLauncherDir() {
const newDir = await open({
multiple: false,
directory: true,
title: 'Select a new app directory',
})
if (newDir) {
settings.value.custom_dir = newDir
}
}
</script>
<template>
Expand Down Expand Up @@ -168,19 +158,15 @@ async function signInAfter() {
The directory where the launcher stores all of its files.
</span>
</label>
<!-- <div class="app-directory">-->
<!-- <div class="iconified-input">-->
<!-- <BoxIcon />-->
<!-- <input id="appDir" v-model="settingsDir" type="text" class="input" />-->
<!-- <Button class="r-btn" @click="findLauncherDir">-->
<!-- <FolderSearchIcon />-->
<!-- </Button>-->
<!-- </div>-->
<!-- <Button large @click="refreshDir">-->
<!-- <UpdatedIcon />-->
<!-- Refresh-->
<!-- </Button>-->
<!-- </div>-->
<div class="app-directory">
<div class="iconified-input">
<BoxIcon />
<input id="appDir" v-model="settings.custom_dir" type="text" class="input" />
<Button class="r-btn" @click="findLauncherDir">
<FolderSearchIcon />
</Button>
</div>
</div>
</Card>
<Card>
<div class="label">
Expand Down
4 changes: 2 additions & 2 deletions apps/app-frontend/src/pages/instance/Mods.vue
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ const initProjects = async () => {
const fetchVersions = []
for (const value of Object.values(profileProjects)) {
if (value.metadata.type === 'modrinth') {
if (value.metadata) {
fetchProjects.push(value.metadata.project_id)
fetchVersions.push(value.metadata.version_id)
}
Expand All @@ -465,7 +465,7 @@ const initProjects = async () => {
])
for (const [path, file] of Object.entries(profileProjects)) {
if (file.metadata.type === 'modrinth') {
if (file.metadata) {
const project = modrinthProjects.find((x) => file.metadata.project_id === x.id)
const version = modrinthVersions.find((x) => file.metadata.version_id === x.id)
const org = project.organization
Expand Down
2 changes: 1 addition & 1 deletion apps/app-frontend/src/pages/project/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ async function fetchProjectData() {
if (instanceProjects.value) {
const installedFile = Object.values(instanceProjects.value).find(
(x) => x.metadata.type === 'modrinth' && x.metadata.project_id === data.value.id,
(x) => x.metadata && x.metadata.project_id === data.value.id,
)
if (installedFile) {
installed.value = true
Expand Down
2 changes: 1 addition & 1 deletion apps/app-frontend/src/store/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const install = async (projectId, versionId, instancePath, source, callba
: true)
) {
for (const [path, file] of Object.entries(instanceProjects)) {
if (file.metadata.type === 'modrinth' && file.metadata.project_id === project.id) {
if (file.metadata && file.metadata.project_id === project.id) {
await remove_project(instance.path, path)
}
}
Expand Down
130 changes: 65 additions & 65 deletions apps/app-playground/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,72 +43,72 @@ async fn main() -> theseus::Result<()> {
// Initialize state
State::init().await?;

if minecraft_auth::users().await?.is_empty() {
println!("No users found, authenticating.");
authenticate_run().await?; // could take credentials from here direct, but also deposited in state users
}
// if minecraft_auth::users().await?.is_empty() {
// println!("No users found, authenticating.");
// authenticate_run().await?; // could take credentials from here direct, but also deposited in state users
// }
// //
// // st.settings
// // .write()
// // .await
// // .java_globals
// // .insert(JAVA_8_KEY.to_string(), check_jre(path).await?.unwrap());
// // Clear profiles
// println!("Clearing profiles.");
// {
// let h = profile::list().await?;
// for profile in h.into_iter() {
// profile::remove(&profile.path).await?;
// }
// }
//
// st.settings
// .write()
// .await
// .java_globals
// .insert(JAVA_8_KEY.to_string(), check_jre(path).await?.unwrap());
// Clear profiles
println!("Clearing profiles.");
{
let h = profile::list().await?;
for profile in h.into_iter() {
profile::remove(&profile.path).await?;
}
}

println!("Creating/adding profile.");

let name = "Example".to_string();
let game_version = "1.21".to_string();
let modloader = ModLoader::Fabric;
let loader_version = "stable".to_string();

let pack = CreatePackLocation::FromVersionId {
project_id: "1KVo5zza".to_string(),
version_id: "lKloE8SA".to_string(),
title: "Fabulously Optimized".to_string(),
icon_url: Some("https://cdn.modrinth.com/data/1KVo5zza/d8152911f8fd5d7e9a8c499fe89045af81fe816e.png".to_string()),
};

let profile = get_profile_from_pack(pack.clone());
let profile_path = profile_create(
profile.name,
profile.game_version,
profile.modloader,
profile.loader_version,
None,
None,
None,
)
.await?;
install_zipped_mrpack(pack, profile_path.to_string()).await?;

let projects = profile::get_projects(&profile_path).await?;

for (path, file) in projects {
println!(
"{path} {} {:?} {:?}",
file.file_name, file.update_version_id, file.metadata
)
}

println!("running");
// Run a profile, running minecraft and store the RwLock to the process
let process = profile::run(&profile_path).await?;

println!("Minecraft PID: {}", process.pid);

println!("All running process UUID {:?}", process::get_all().await?);

// hold the lock to the process until it ends
println!("Waiting for process to end...");
process.wait_for().await?;
// println!("Creating/adding profile.");
//
// let name = "Example".to_string();
// let game_version = "1.21".to_string();
// let modloader = ModLoader::Fabric;
// let loader_version = "stable".to_string();
//
// let pack = CreatePackLocation::FromVersionId {
// project_id: "1KVo5zza".to_string(),
// version_id: "lKloE8SA".to_string(),
// title: "Fabulously Optimized".to_string(),
// icon_url: Some("https://cdn.modrinth.com/data/1KVo5zza/d8152911f8fd5d7e9a8c499fe89045af81fe816e.png".to_string()),
// };
//
// let profile = get_profile_from_pack(pack.clone());
// let profile_path = profile_create(
// profile.name,
// profile.game_version,
// profile.modloader,
// profile.loader_version,
// None,
// None,
// None,
// )
// .await?;
// install_zipped_mrpack(pack, profile_path.to_string()).await?;
//
// let projects = profile::get_projects(&profile_path).await?;
//
// for (path, file) in projects {
// println!(
// "{path} {} {:?} {:?}",
// file.file_name, file.update_version_id, file.metadata
// )
// }
//
// println!("running");
// // Run a profile, running minecraft and store the RwLock to the process
// let process = profile::run(&profile_path).await?;
//
// println!("Minecraft PID: {}", process.pid);
//
// println!("All running process UUID {:?}", process::get_all().await?);
//
// // hold the lock to the process until it ends
// println!("Waiting for process to end...");
// process.wait_for().await?;

Ok(())
}
5 changes: 2 additions & 3 deletions apps/app/src/api/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ pub async fn profile_check_installed(

if let Ok(projects) = profile::get_projects(path).await {
Ok(projects.into_iter().any(|(_, project)| {
if let FileMetadata::Modrinth { project_id, .. } = &project.metadata
{
check_project_id == project_id
if let Some(metadata) = &project.metadata {
check_project_id == metadata.project_id
} else {
false
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/app-lib/migrations/20240711194701_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ CREATE TABLE settings (
hook_wrapper TEXT NULL,
hook_post_exit TEXT NULL,

custom_dir TEXT NULL,
prev_custom_dir TEXT NULL,
migrated INTEGER NOT NULL DEFAULT FALSE,

PRIMARY KEY (id)
);

Expand Down
4 changes: 2 additions & 2 deletions packages/app-lib/src/api/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ macro_rules! impl_cache_methods {
) -> crate::Result<Option<$type>>
{
let state = crate::State::get().await?;
Ok(CachedEntry::[<get_ $variant:snake _many>](&[id], None, &state.pool, &state.fetch_semaphore).await?.into_iter().next())
Ok(CachedEntry::[<get_ $variant:snake _many>](&[id], None, &state.pool, &state.api_semaphore).await?.into_iter().next())
}

#[tracing::instrument]
Expand All @@ -23,7 +23,7 @@ macro_rules! impl_cache_methods {
{
let state = crate::State::get().await?;
let entries =
CachedEntry::[<get_ $variant:snake _many>](ids, None, &state.pool, &state.fetch_semaphore).await?;
CachedEntry::[<get_ $variant:snake _many>](ids, None, &state.pool, &state.api_semaphore).await?;

Ok(entries)
}
Expand Down
Loading

0 comments on commit b506fb7

Please sign in to comment.