Fix: Exit Button Works

This commit is contained in:
Youwes09
2026-05-16 15:31:13 -05:00
parent 93cedca6b5
commit 6b56db7cf2
9 changed files with 121 additions and 42 deletions
+8 -36
View File
@@ -3,9 +3,6 @@
import { invoke } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event";
import { getCurrentWindow } from "@tauri-apps/api/window";
import { defaultWindowIcon } from "@tauri-apps/api/app";
import { TrayIcon } from "@tauri-apps/api/tray";
import { Menu } from "@tauri-apps/api/menu";
import { platform } from "@tauri-apps/plugin-os";
import { store, updateSettings, setActiveDownloads } from "@store/state.svelte";
import { downloadStore } from "@features/downloads/store/downloadState.svelte";
@@ -48,8 +45,13 @@
}
async function doQuit() {
if (store.settings.autoStartServer) await invoke("kill_server").catch(() => {});
await win.destroy();
if (store.settings.autoStartServer) {
await Promise.race([
invoke("kill_server").catch(() => {}),
new Promise(res => setTimeout(res, 2000)),
]);
}
await invoke("exit_app");
}
async function doHide() {
@@ -123,36 +125,6 @@
applyZoom();
});
const menu = await Menu.new({
items: [
{
id: "show",
text: "Show Moku",
action: async () => {
await win.show();
await win.setFocus();
},
},
{
id: "quit",
text: "Quit",
action: doQuit,
},
],
});
await TrayIcon.new({
icon: await defaultWindowIcon(),
menu,
menuOnLeftClick: false,
tooltip: "Moku",
action: async (e) => {
if (e.type === "Click") {
await win.show();
await win.setFocus();
}
},
});
const unlistenClose = await win.listen("tauri://close-requested", handleCloseRequested);
@@ -215,7 +187,7 @@
{/if}
<div id="app-shell" class="root">
{#if !store.activeChapter}<TitleBar />{/if}
{#if !store.activeChapter}<TitleBar onClose={handleCloseRequested} />{/if}
<div class="content">
{#if store.activeChapter}<Reader />{:else}<Layout />{/if}
</div>
+4 -2
View File
@@ -3,6 +3,8 @@
import { getCurrentWindow } from "@tauri-apps/api/window";
import { platform } from "@tauri-apps/plugin-os";
const { onClose }: { onClose: () => void } = $props();
const win = getCurrentWindow();
const os = platform();
const isMac = os === "macos";
@@ -31,7 +33,7 @@
<button onclick={() => win.toggleMaximize()} title="Maximize" aria-label="Maximize">
<svg width="9" height="9" viewBox="0 0 9 9"><rect x="0.75" y="0.75" width="7.5" height="7.5" rx="1" fill="none" stroke="currentColor" stroke-width="1.5" /></svg>
</button>
<button class="close" onclick={() => win.close()} title="Close" aria-label="Close">
<button class="close" onclick={onClose} title="Close" aria-label="Close">
<svg width="10" height="10" viewBox="0 0 10 10">
<line x1="1" y1="1" x2="9" y2="9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" />
<line x1="9" y1="1" x2="1" y2="9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" />
@@ -50,7 +52,7 @@
<polyline points="4,9 1,9 1,6" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
<button class="close" onclick={() => win.close()} title="Close" aria-label="Close">
<button class="close" onclick={onClose} title="Close" aria-label="Close">
<svg width="10" height="10" viewBox="0 0 10 10">
<line x1="1" y1="1" x2="9" y2="9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" />
<line x1="9" y1="1" x2="1" y2="9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" />