From 69c7df85d328719851bfc6320b849c2331ad96b5 Mon Sep 17 00:00:00 2001 From: Nixevol Date: Sun, 25 Oct 2026 08:45:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=AD=A3=E5=BC=8F=E5=8C=85=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E8=B0=83=E8=AF=95=E5=85=A5=E5=8F=A3=E5=B9=B6=E8=AE=A9?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E6=A1=86=E8=B7=9F=E9=9A=8F=E4=B8=BB=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- desktop/src-tauri/capabilities/default.json | 3 ++ desktop/src-tauri/tauri.release.conf.json | 12 +++++ desktop/src/main.ts | 2 + desktop/src/shared/chrome.ts | 49 +++++++++++++++++++++ desktop/src/shared/theme.ts | 2 + 5 files changed, 68 insertions(+) create mode 100644 desktop/src/shared/chrome.ts diff --git a/desktop/src-tauri/capabilities/default.json b/desktop/src-tauri/capabilities/default.json index fcf725f..9d28b2b 100644 --- a/desktop/src-tauri/capabilities/default.json +++ b/desktop/src-tauri/capabilities/default.json @@ -5,6 +5,9 @@ "windows": ["main"], "permissions": [ "core:default", + "core:window:allow-set-theme", + "core:window:allow-set-background-color", + "core:webview:allow-set-webview-background-color", "opener:default", { "identifier": "opener:allow-open-path", diff --git a/desktop/src-tauri/tauri.release.conf.json b/desktop/src-tauri/tauri.release.conf.json index 6c6a651..9fd236c 100644 --- a/desktop/src-tauri/tauri.release.conf.json +++ b/desktop/src-tauri/tauri.release.conf.json @@ -1,4 +1,16 @@ { + "app": { + "windows": [ + { + "title": "NqiTools", + "width": 1180, + "height": 780, + "minWidth": 980, + "minHeight": 640, + "devtools": false + } + ] + }, "bundle": { "resources": { "../../backend/build/nqi-backend/": "nqi-backend/" diff --git a/desktop/src/main.ts b/desktop/src/main.ts index 8d6a5ff..2969c8c 100644 --- a/desktop/src/main.ts +++ b/desktop/src/main.ts @@ -1,5 +1,7 @@ import { createApp } from "vue"; import App from "./App.vue"; +import { installChrome } from "./shared/chrome"; import "./styles.css"; +installChrome(); createApp(App).mount("#app"); diff --git a/desktop/src/shared/chrome.ts b/desktop/src/shared/chrome.ts new file mode 100644 index 0000000..e82acf3 --- /dev/null +++ b/desktop/src/shared/chrome.ts @@ -0,0 +1,49 @@ +import { getCurrentWebview } from "@tauri-apps/api/webview"; +import { getCurrentWindow } from "@tauri-apps/api/window"; + +const LIGHT = "#f3f4f6"; +const DARK = "#0f172a"; + +function inTauri() { + return "__TAURI_INTERNALS__" in window; +} + +function canEdit(target: EventTarget | null) { + if (!(target instanceof Element)) return false; + const field = target.closest("input, textarea, [contenteditable='true'], .n-input, .n-input-number"); + if (!field) return false; + if (field instanceof HTMLInputElement) { + const skip = ["button", "checkbox", "color", "file", "hidden", "image", "radio", "range", "reset", "submit"]; + if (skip.includes(field.type)) return false; + } + return true; +} + +export function installChrome() { + document.addEventListener("contextmenu", (event) => { + if (canEdit(event.target)) return; + event.preventDefault(); + }); + + if (!import.meta.env.PROD) return; + document.addEventListener("keydown", (event) => { + const key = event.key.toLowerCase(); + const inspect = + event.key === "F12" || + (event.ctrlKey && event.shiftKey && (key === "i" || key === "j" || key === "c")) || + (event.ctrlKey && key === "u"); + if (inspect) event.preventDefault(); + }); +} + +export function applyWindowTheme(dark: boolean) { + if (!inTauri()) return; + const color = dark ? DARK : LIGHT; + const theme = dark ? "dark" : "light"; + const current = getCurrentWindow(); + void Promise.all([ + current.setTheme(theme), + current.setBackgroundColor(color), + getCurrentWebview().setBackgroundColor(color), + ]).catch(() => undefined); +} diff --git a/desktop/src/shared/theme.ts b/desktop/src/shared/theme.ts index 2c214de..f896c4f 100644 --- a/desktop/src/shared/theme.ts +++ b/desktop/src/shared/theme.ts @@ -1,4 +1,5 @@ import { ref, watch } from "vue"; +import { applyWindowTheme } from "./chrome"; const stored = localStorage.getItem("nqi-theme"); export const isDark = ref(stored === "dark"); @@ -6,6 +7,7 @@ export const isDark = ref(stored === "dark"); watch(isDark, (value) => { localStorage.setItem("nqi-theme", value ? "dark" : "light"); document.documentElement.dataset.theme = value ? "dark" : "light"; + applyWindowTheme(value); }, { immediate: true }); export function toggleTheme() {