fix: 正式包去掉调试入口并让窗口框跟随主题
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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/"
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user