fix: 正式包去掉调试入口并让窗口框跟随主题

This commit is contained in:
2026-10-25 08:45:17 +08:00
parent c05516d5ec
commit 69c7df85d3
5 changed files with 68 additions and 0 deletions
+2
View File
@@ -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");
+49
View File
@@ -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);
}
+2
View File
@@ -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() {