diff --git a/cmd/desktop/main.go b/cmd/desktop/main.go index f36a1482..8b68817f 100644 --- a/cmd/desktop/main.go +++ b/cmd/desktop/main.go @@ -140,6 +140,9 @@ window.open=function(url){ }; })();` +// wailsThemeSyncJS:与 index.html 首屏一致,在 DomReady 再跑一遍,覆盖 Ctrl+R 后 runtime 就绪时机 +const wailsThemeSyncJS = `(function(){try{var t=localStorage.getItem('WeKnora_theme')||'light';if(t==='system')t=window.matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light';var bg=t==='dark'?'#181818':'#eee';document.documentElement.setAttribute('theme-mode',t);document.documentElement.style.background=bg;document.documentElement.style.minHeight='100%';document.documentElement.style.colorScheme=t==='dark'?'dark':'light';if(document.body){document.body.style.background=bg;document.body.style.minHeight='100%';}var w=window.runtime;if(!w)return;if(t==='dark'){if(w.WindowSetDarkTheme)w.WindowSetDarkTheme();if(w.WindowSetBackgroundColour)w.WindowSetBackgroundColour(24,24,24,255);}else{if(w.WindowSetLightTheme)w.WindowSetLightTheme();if(w.WindowSetBackgroundColour)w.WindowSetBackgroundColour(238,238,238,255);}}catch(e){}})()` + func main() { // For macOS .app bundle, the working directory is usually "/" or the MacOS folder. // We need to change the working directory to the Resources folder where our configs are. @@ -286,6 +289,7 @@ func main() { StartHidden: false, // Show window on startup OnStartup: app.startup, OnDomReady: func(ctx context.Context) { + wailsruntime.WindowExecJS(ctx, wailsThemeSyncJS) wailsruntime.WindowExecJS(ctx, dragHandlerJS) // 注入真实 API 根路径(与 window.location.origin 不同);无 Go 绑定时仍可显示。 if u := strings.TrimSpace(app.backendURL); u != "" { diff --git a/frontend/index.html b/frontend/index.html index f5538ceb..f09ede50 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -15,8 +15,58 @@ + +
+ diff --git a/frontend/src/App.vue b/frontend/src/App.vue index d04429fa..0e9dfc90 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -145,6 +145,11 @@ onMounted(() => { diff --git a/frontend/src/components/menu.vue b/frontend/src/components/menu.vue index afcda1d9..dd62b2a7 100644 --- a/frontend/src/components/menu.vue +++ b/frontend/src/components/menu.vue @@ -61,6 +61,14 @@