feat(desktop): add close behavior prompt with quit-on-close setting

Co-authored-by: cherlin <544026227@qq.com>
This commit is contained in:
cherlinbest-pixelandcherlin authored and GitHub committed 2026-06-21 00:04:52 +08:00
1 parent f32298743d
commit 28a23de604
16 files changed
+243 -3

No files matched your search

@@ -0,0 +1,55 @@
import { ref } from "vue";
import { useSettingsStore } from "@/stores/settingsStore";
import { isTauriRuntime } from "@/lib/tauriRuntime";
export function useCloseActionPrompt() {
const settingsStore = useSettingsStore();
const showCloseActionPrompt = ref(false);
const unlistenHandles: Array<() => void> = [];
async function applyCloseChoice(quitOnClose: boolean) {
showCloseActionPrompt.value = false;
await settingsStore.updateDesktopSettings({
quit_on_close: quitOnClose,
close_action_prompted: true,
});
if (!isTauriRuntime()) return;
if (quitOnClose) {
const { exit } = await import("@tauri-apps/plugin-process");
await exit(0);
return;
}
const { getCurrentWindow } = await import("@tauri-apps/api/window");
await getCurrentWindow().hide();
}
function chooseQuit() {
void applyCloseChoice(true);
}
function chooseMinimize() {
void applyCloseChoice(false);
}
function setupCloseActionPromptListener() {
if (!isTauriRuntime()) return;
void import("@tauri-apps/api/event").then(({ listen }) => {
listen("dbx-close-action-prompt", () => {
showCloseActionPrompt.value = true;
}).then((unlisten) => unlistenHandles.push(unlisten));
});
}
function cleanupCloseActionPromptListener() {
unlistenHandles.forEach((unlisten) => unlisten());
unlistenHandles.length = 0;
}
return {
showCloseActionPrompt,
chooseQuit,
chooseMinimize,
setupCloseActionPromptListener,
cleanupCloseActionPromptListener,
};
}