Merge branch 'refactor/frontend' of https://github.com/Polyfrost/OneLauncher into refactor/frontend
This commit is contained in:
commit
583e241f67
4 changed files with 85 additions and 8 deletions
|
|
@ -1,6 +1,9 @@
|
|||
import type { ProfileUpdate } from '@/bindings.gen';
|
||||
import ScrollableContainer from '@/components/ScrollableContainer';
|
||||
import usePopState from '@/hooks/usePopState';
|
||||
import { bindings } from '@/main';
|
||||
import { useCommand } from '@onelauncher/common';
|
||||
import { Button } from '@onelauncher/common/components';
|
||||
import { createFileRoute } from '@tanstack/react-router';
|
||||
import { GameSettings, ProcessSettings } from '../settings/minecraft';
|
||||
import Sidebar from '../settings/route';
|
||||
|
|
@ -13,17 +16,29 @@ function RouteComponent() {
|
|||
const { id } = Route.useSearch();
|
||||
|
||||
const cluster = useCommand('getClusterById', () => bindings.core.getClusterById(Number(id.toString()) as unknown as bigint));
|
||||
const _result = useCommand('getProfileOrDefault', () => bindings.core.getProfileOrDefault(cluster.data?.name as string), {
|
||||
enabled: !!cluster.data?.name,
|
||||
const _result = useCommand('getProfileOrDefault', () => bindings.core.getProfileOrDefault(cluster.data?.setting_profile_name as string), {
|
||||
enabled: !!cluster.data?.setting_profile_name,
|
||||
});
|
||||
|
||||
const save = useCommand('updateClusterProfile', () => bindings.core.updateClusterProfile(cluster.data?.name as string, _result.data!), {
|
||||
enabled: false,
|
||||
subscribed: false,
|
||||
});
|
||||
|
||||
usePopState(() => {
|
||||
save.refetch();
|
||||
});
|
||||
|
||||
if (_result.isPending)
|
||||
return <p>loading...</p>;
|
||||
|
||||
return (
|
||||
<Sidebar.Page>
|
||||
<ScrollableContainer>
|
||||
<div className="h-full">
|
||||
<h1>Minecraft Settings</h1>
|
||||
|
||||
<GameSettings />
|
||||
<GameSettings key={_result.data?.name} settings={_result.data!} />
|
||||
|
||||
<ProcessSettings />
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ export function GameSettings(props: GameSettingProps) {
|
|||
title="Force Fullscreen"
|
||||
>
|
||||
<Switch
|
||||
defaultSelected={settings.force_fullscreen ?? false}
|
||||
defaultSelected={settings.force_fullscreen!}
|
||||
onChange={(val) => {
|
||||
settings.force_fullscreen = val;
|
||||
}}
|
||||
|
|
@ -101,11 +101,11 @@ export function GameSettings(props: GameSettingProps) {
|
|||
<div className="flex flex-row items-center gap-x-2">
|
||||
<TextField
|
||||
className="text-center"
|
||||
defaultValue={settings.mem_max?.toString()}
|
||||
onChange={(e) => {
|
||||
settings.mem_max = Number(e.target.value);
|
||||
}}
|
||||
type="number"
|
||||
value={settings.mem_max?.toString()}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ pub struct JavaInfo {
|
|||
pub struct JavaPackage {
|
||||
pub download_url: String,
|
||||
pub name: PathBuf,
|
||||
pub jav_version: Vec<u32>,
|
||||
pub java_version: Vec<u32>,
|
||||
}
|
||||
|
||||
const JAVA_INFO_CLASS: &[u8] = include_bytes!("../../../assets/java/JavaInfo.class");
|
||||
|
|
@ -346,7 +346,7 @@ pub async fn install_java_from_major(version: u32) -> LauncherResult<PathBuf> {
|
|||
let packages = get_zulu_packages().await?;
|
||||
|
||||
let package = packages.into_iter()
|
||||
.find(|p| p.jav_version.contains(&version))
|
||||
.find(|p| p.java_version.contains(&version))
|
||||
.ok_or_else(|| anyhow::anyhow!(
|
||||
"Could not find a java package for version {}",
|
||||
version
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use interpulse::api::minecraft::Version;
|
||||
use onelauncher_entity::{clusters, icon::Icon, loader::GameLoader, prelude::entity};
|
||||
use onelauncher_entity::{clusters, icon::Icon, loader::GameLoader, prelude::entity, resolution::Resolution};
|
||||
use sea_orm::ActiveValue::Set;
|
||||
use serde::Serialize;
|
||||
use crate::store::{Settings, State};
|
||||
|
|
@ -39,6 +39,9 @@ pub trait TauriLauncherApi {
|
|||
#[taurpc(alias = "getGlobalProfile")]
|
||||
async fn get_global_profile() -> SettingsProfile;
|
||||
|
||||
#[taurpc(alias = "updateClusterProfile")]
|
||||
async fn update_cluster_profile(name: String, profile: ProfileUpdate) -> LauncherResult<SettingsProfile>;
|
||||
|
||||
// Game Metadata
|
||||
#[taurpc(alias = "getGameVersions")]
|
||||
async fn get_game_versions() -> LauncherResult<Vec<Version>>;
|
||||
|
|
@ -90,6 +93,17 @@ pub struct ClusterUpdate {
|
|||
icon_url: Option<Icon>,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, specta::Type, Clone)]
|
||||
pub struct ProfileUpdate {
|
||||
pub res: Option<Resolution>,
|
||||
pub force_fullscreen: Option<bool>,
|
||||
pub mem_max: Option<u32>,
|
||||
pub launch_args: Option<String>,
|
||||
pub launch_env: Option<String>,
|
||||
pub hook_pre: Option<String>,
|
||||
pub hook_wrapper: Option<String>,
|
||||
pub hook_post: Option<String>,
|
||||
}
|
||||
|
||||
#[taurpc::ipc_type]
|
||||
pub struct TauriLauncherApiImpl;
|
||||
|
|
@ -122,6 +136,13 @@ impl TauriLauncherApi for TauriLauncherApiImpl {
|
|||
})
|
||||
.await?;
|
||||
|
||||
api::cluster::dao::update_cluster_by_id(cluster.id, |mut active_model: ClusterPartial| async move {
|
||||
active_model.setting_profile_name = Set(Some(options.name.clone()));
|
||||
|
||||
Ok(active_model)
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(cluster)
|
||||
}
|
||||
|
||||
|
|
@ -173,6 +194,47 @@ impl TauriLauncherApi for TauriLauncherApiImpl {
|
|||
api::setting_profiles::dao::get_profile_or_default(name.as_ref()).await
|
||||
}
|
||||
|
||||
// please kill this with fire
|
||||
async fn update_cluster_profile(self, name: String, profile: ProfileUpdate) -> LauncherResult<SettingsProfile> {
|
||||
let profile = api::setting_profiles::dao::update_profile_by_name(&name, |mut active_model: SettingsProfilePartial| async move {
|
||||
if let Some(res) = profile.res {
|
||||
active_model.res = Set(Some(res));
|
||||
}
|
||||
|
||||
if let Some(force_fullscreen) = profile.force_fullscreen {
|
||||
active_model.force_fullscreen = Set(Some(force_fullscreen));
|
||||
}
|
||||
|
||||
if let Some(mem_max) = profile.mem_max {
|
||||
active_model.mem_max = Set(Some(mem_max));
|
||||
}
|
||||
|
||||
if let Some(launch_args) = profile.launch_args {
|
||||
active_model.launch_args = Set(Some(launch_args));
|
||||
}
|
||||
|
||||
if let Some(launch_env) = profile.launch_env {
|
||||
active_model.launch_env = Set(Some(launch_env));
|
||||
}
|
||||
|
||||
if let Some(hook_pre) = profile.hook_pre {
|
||||
active_model.hook_pre = Set(Some(hook_pre));
|
||||
}
|
||||
|
||||
if let Some(hook_wrapper) = profile.hook_wrapper {
|
||||
active_model.hook_wrapper = Set(Some(hook_wrapper));
|
||||
}
|
||||
|
||||
if let Some(hook_post) = profile.hook_post {
|
||||
active_model.hook_post = Set(Some(hook_post));
|
||||
}
|
||||
|
||||
Ok(active_model)
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(profile)
|
||||
}
|
||||
|
||||
// Game Metadata
|
||||
async fn get_loaders_for_version(self, mc_version: String) -> LauncherResult<Vec<GameLoader>> {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue