From 855d421eaadaa20176e5faf2678caab12ac27afa Mon Sep 17 00:00:00 2001 From: emirsassan Date: Thu, 26 Jun 2025 20:48:48 +0300 Subject: [PATCH] feat: global game settings and notifications notification system needs some work still --- .../frontend/src/components/Navbar.tsx | 23 ++- .../launcher/cluster/ClusterCreation.tsx | 4 +- .../components/overlay/NotificationToasts.tsx | 132 ++++++++++++++++++ .../overlay/popups/NotificationPopup.tsx | 98 +++++++++++++ .../frontend/src/hooks/useNotification.tsx | 81 +++++++++++ .../frontend/src/hooks/usePopState.ts | 20 +++ apps/onelauncher/frontend/src/main.tsx | 7 +- .../frontend/src/routes/__root.tsx | 3 + .../frontend/src/routes/app/browser/index.tsx | 53 +++++++ .../frontend/src/routes/app/cluster/index.tsx | 12 +- .../frontend/src/routes/app/index.tsx | 23 ++- .../src/routes/app/settings/index.tsx | 20 ++- .../src/routes/app/settings/minecraft.tsx | 57 +++++--- packages/core/src/api/tauri/commands.rs | 26 ++++ .../web_common/src/components/Dropdown.tsx | 4 +- 15 files changed, 515 insertions(+), 48 deletions(-) create mode 100644 apps/onelauncher/frontend/src/components/overlay/NotificationToasts.tsx create mode 100644 apps/onelauncher/frontend/src/components/overlay/popups/NotificationPopup.tsx create mode 100644 apps/onelauncher/frontend/src/hooks/useNotification.tsx create mode 100644 apps/onelauncher/frontend/src/hooks/usePopState.ts diff --git a/apps/onelauncher/frontend/src/components/Navbar.tsx b/apps/onelauncher/frontend/src/components/Navbar.tsx index e5ab57d7..9009e5c4 100644 --- a/apps/onelauncher/frontend/src/components/Navbar.tsx +++ b/apps/onelauncher/frontend/src/components/Navbar.tsx @@ -1,5 +1,6 @@ import type { ToOptions } from '@tanstack/react-router'; import { bindings } from '@/main'; +import useNotifications from '@/hooks/useNotification'; import { useCommand } from '@onelauncher/common'; import { Button, Menu } from '@onelauncher/common/components'; import { Link } from '@tanstack/react-router'; @@ -8,9 +9,12 @@ import { MenuTrigger } from 'react-aria-components'; import OneLauncherText from '../assets/logos/onelauncher_text.svg'; import PlayerHead from './content/PlayerHead'; import AccountPopup from './overlay/popups/AccountPopup'; +import NotificationPopup from './overlay/popups/NotificationPopup'; function Navbar() { const defaultUser = useCommand('getDefaultUser', () => bindings.core.getDefaultUser(false)); + const { list } = useNotifications(); + const notificationCount = Object.keys(list).length; return (
@@ -37,24 +41,19 @@ function Navbar() { {/* Notification Manager Button */}
- - - Hello World - + - - {/* el.classList.add('right-0')} - setVisible={setNotificationMenuOpen} - visible={notificationMenuOpen} - /> */}
diff --git a/apps/onelauncher/frontend/src/components/launcher/cluster/ClusterCreation.tsx b/apps/onelauncher/frontend/src/components/launcher/cluster/ClusterCreation.tsx index 6d6cfa78..512ee0db 100644 --- a/apps/onelauncher/frontend/src/components/launcher/cluster/ClusterCreation.tsx +++ b/apps/onelauncher/frontend/src/components/launcher/cluster/ClusterCreation.tsx @@ -262,9 +262,9 @@ function ClusterInformation({
-

{name}

+

+ {name} +

{mc_loader} {' '} diff --git a/apps/onelauncher/frontend/src/routes/app/settings/index.tsx b/apps/onelauncher/frontend/src/routes/app/settings/index.tsx index 6b754f2c..4e41866e 100644 --- a/apps/onelauncher/frontend/src/routes/app/settings/index.tsx +++ b/apps/onelauncher/frontend/src/routes/app/settings/index.tsx @@ -1,5 +1,6 @@ import DiscordIcon from '@/assets/logos/discord.svg'; import SettingsRow from '@/components/SettingsRow'; +import usePopState from '@/hooks/usePopState'; import { bindings } from '@/main'; import { useCommand } from '@onelauncher/common'; import { Button, Switch } from '@onelauncher/common/components'; @@ -14,7 +15,16 @@ export const Route = createFileRoute('/app/settings/')({ }); function RouteComponent() { - const _result = useCommand('getGlobalProfile', bindings.core.getGlobalProfile); + const result = useCommand('readSettings', bindings.core.readSettings); + + const save = useCommand('writeSettings', () => bindings.core.writeSettings(result.data!), { + enabled: false, + subscribed: false, + }); + + usePopState(() => { + save.refetch(); + }); const openLauncherDir = async () => { const dir = await dataDir(); @@ -32,7 +42,13 @@ function RouteComponent() { icon={} title="Discord RPC" > - + { + if (result.data) + result.data.discord_enabled = val; + }} + /> bindings.core.writeSettings(result.data!), { + enabled: false, + subscribed: false, + }); + + usePopState(() => { + save.refetch(); + }); + return (

Minecraft Settings

- + {/* */} @@ -27,7 +42,13 @@ function RouteComponent() { ); } -export function GameSettings() { +interface GameSettingProps { + settings: SettingProfileModel; +} + +export function GameSettings(props: GameSettingProps) { + const { settings } = props; + return ( <> Game @@ -37,7 +58,12 @@ export function GameSettings() { icon={} title="Force Fullscreen" > - + { + settings.force_fullscreen = val; + }} + /> { + settings.res!.width = Number(e.target.value); + }} type="number" /> { + settings.res!.height = Number(e.target.value); + }} type="number" />
@@ -65,21 +99,12 @@ export function GameSettings() { >
- Min: -
- -
- Max: - { + settings.mem_max = Number(e.target.value); + }} type="number" />
diff --git a/packages/core/src/api/tauri/commands.rs b/packages/core/src/api/tauri/commands.rs index 0b84a6c5..e0440266 100644 --- a/packages/core/src/api/tauri/commands.rs +++ b/packages/core/src/api/tauri/commands.rs @@ -2,6 +2,7 @@ use interpulse::api::minecraft::Version; use onelauncher_entity::{clusters, icon::Icon, loader::GameLoader, prelude::entity}; use sea_orm::ActiveValue::Set; use serde::Serialize; +use crate::store::{Settings, State}; use tauri::{AppHandle, Runtime}; use crate::{api::{self, cluster::dao::ClusterId}, error::{LauncherError, LauncherResult}, store::{credentials::MinecraftCredentials, Core}}; @@ -64,6 +65,13 @@ pub trait TauriLauncherApi { #[taurpc(alias = "openMsaLogin")] async fn open_msa_login(app_handle: AppHandle) -> LauncherResult>; + + // Settings + #[taurpc(alias = "readSettings")] + async fn read_settings() -> LauncherResult; + + #[taurpc(alias = "writeSettings")] + async fn write_settings(setting: Settings) -> LauncherResult<()>; } @@ -262,4 +270,22 @@ impl TauriLauncherApi for TauriLauncherApiImpl { Ok(None) } + + async fn read_settings(self) -> LauncherResult { + let state = State::get().await?; + let settings = state.settings.read().await; + + Ok(settings.clone()) + } + + async fn write_settings(self, setting: Settings) -> LauncherResult<()> { + let state = State::get().await?; + let mut settings = state.settings.write().await; + + *settings = setting; + + settings.save().await?; + + Ok(()) + } } diff --git a/packages/web_common/src/components/Dropdown.tsx b/packages/web_common/src/components/Dropdown.tsx index 2a228f33..c3ea1783 100644 --- a/packages/web_common/src/components/Dropdown.tsx +++ b/packages/web_common/src/components/Dropdown.tsx @@ -36,8 +36,8 @@ const dropdownStyles = tv({ triggerCustomIcon: 'w-4 h-4', popover: [ - // width is not full instead it behaves like w-screen for some fucking reason - 'mt-1 rounded-lg shadow-md', + // i'll fix this if i dont forget + 'mt-1 w-full rounded-lg shadow-md', 'bg-component-bg border border-component-border', 'data-[entering]:animate-in data-[entering]:fade-in data-[entering]:zoom-in-95', 'data-[exiting]:animate-out data-[exiting]:fade-out data-[exiting]:zoom-out-95',