From e9286c4b648f3e750f8ab43ba59d9b7da82c2723 Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Tue, 28 Jul 2026 12:59:16 -0700 Subject: [PATCH] Improve moving data system --- src-tauri/capabilities/default.json | 1 + src-tauri/src/lib.rs | 6 ----- src/app/main/layout.tsx | 8 ------- src/app/main/settings/page.tsx | 35 ++++++++++++++++++++--------- src/providers/GlobalProvider.tsx | 2 -- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index 1d68c9c..3ddc0c7 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -19,6 +19,7 @@ "core:window:allow-toggle-maximize", "core:window:allow-request-user-attention", "core:window:allow-show", + "core:window:allow-hide", "core:webview:allow-create-webview-window", "fs:default", "fs:allow-remove", diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 859ff78..9046c35 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -635,11 +635,6 @@ async fn move_game_data(app: AppHandle, destination: String) -> Result<(), Strin Ok(()) } -#[tauri::command] -fn restart_app(app: AppHandle) { - app.restart(); -} - #[tauri::command] fn open_game_folder(app: AppHandle, version: String) -> Result<(), String> { let dir = data_dir(&app)?; @@ -718,7 +713,6 @@ pub fn run() { verify_signature, cancel_download, move_game_data, - restart_app, open_game_folder, remove_stale_executable ]) diff --git a/src/app/main/layout.tsx b/src/app/main/layout.tsx index 3854473..19164ff 100644 --- a/src/app/main/layout.tsx +++ b/src/app/main/layout.tsx @@ -56,7 +56,6 @@ export default function RootLayout ({ const [loading, setLoading] = useState(true) const [version, setVersion] = useState(null) const [platformName, setPlatformName] = useState(null) - const [movingData, setMovingData] = useState(false) const [serverVersionList, setServerVersionList] = useState(null) @@ -906,8 +905,6 @@ export default function RootLayout ({ accountId, accountName, accountAdmin, - movingData, - setMovingData, managingGame, setManagingGame, needsRevisionUpdate, @@ -980,11 +977,6 @@ export default function RootLayout ({ )} - {movingData && ( -
-

Moving data...

-
- )} )} diff --git a/src/app/main/settings/page.tsx b/src/app/main/settings/page.tsx index 2800bd9..b90e903 100644 --- a/src/app/main/settings/page.tsx +++ b/src/app/main/settings/page.tsx @@ -4,14 +4,15 @@ import { Setting } from '@/components/Setting' import { useGlobal } from '@/providers/GlobalProvider' import { copyToClipboard } from '@/lib/clipboard' import { platform } from '@tauri-apps/plugin-os' -import { message, open } from '@tauri-apps/plugin-dialog' +import { confirm, message, open } from '@tauri-apps/plugin-dialog' import { invoke } from '@tauri-apps/api/core' import Dropdown from '@/components/Dropdown' import { WebviewWindow } from '@tauri-apps/api/webviewWindow' -import { relaunch } from '@tauri-apps/plugin-process' +import { exit, relaunch } from '@tauri-apps/plugin-process' import { BaseDirectory, exists, readDir, remove } from '@tauri-apps/plugin-fs' import { openPath } from '@tauri-apps/plugin-opener' import { appLocalDataDir } from '@tauri-apps/api/path' +import { getCurrentWindow } from '@tauri-apps/api/window' export default function SettingsPage () { const { @@ -25,8 +26,7 @@ export default function SettingsPage () { linuxWineCommand, theme, customDataLocation, - downloadProgress, - setMovingData + downloadProgress } = useGlobal() return ( @@ -73,12 +73,19 @@ export default function SettingsPage () { onChange={async () => { if (customDataLocation) { try { - setMovingData(true) + const confirmation = await confirm( + 'Data will be moved back to the original location. The launcher will restart when completed and will not be visible until the restart.', + { title: 'Moving data', kind: 'warning' } + ) + if (!confirmation) return + + const window = getCurrentWindow() + await window.hide() await invoke('move_game_data', { destination: '' }) await settings?.set('customDataLocation', '') - await invoke('restart_app') + await relaunch() } catch { - setMovingData(false) + await exit(1) } } else { const selected = await open({ @@ -87,12 +94,20 @@ export default function SettingsPage () { }) if (!selected || typeof selected !== 'string') return try { - setMovingData(true) + const confirmation = await confirm( + `Data will be moved to the directory "${selected}". The launcher will restart when completed and will not be visible until the restart.`, + { title: 'Moving data', kind: 'warning' } + ) + if (!confirmation) return + + const window = getCurrentWindow() + await window.hide() await invoke('move_game_data', { destination: selected }) await settings?.set('customDataLocation', selected) - await invoke('restart_app') + await relaunch() } catch { - setMovingData(false) + await exit(1) + await exit(1) } } }} diff --git a/src/providers/GlobalProvider.tsx b/src/providers/GlobalProvider.tsx index 4b21436..710b356 100644 --- a/src/providers/GlobalProvider.tsx +++ b/src/providers/GlobalProvider.tsx @@ -67,8 +67,6 @@ type GlobalCtxType = { accountId: string | null accountName: string | null accountAdmin: boolean - movingData: boolean - setMovingData: Dispatch> managingGame: number | null setManagingGame: Dispatch> needsRevisionUpdate: (