From fa0ff18643c4c484b932b153b5728dbc43c71cb3 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 24 Sep 2026 12:43:21 +0800 Subject: [PATCH] =?UTF-8?q?gui:=20Settings=20=E2=86=92=20Tray=20icon=20cho?= =?UTF-8?q?oses=20whether=20a=20click=20opens=20the=20quick=20panel=20or?= =?UTF-8?q?=20the=20main=20window=20(#7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/gui/app.go | 9 +++++++++ internal/gui/assets/app.js | 10 +++++++--- internal/gui/assets/i18n.js | 4 ++++ internal/gui/assets/index.html | 4 ++++ internal/settings/settings.go | 8 ++++++++ 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/internal/gui/app.go b/internal/gui/app.go index 9171cc7a3..b070eb537 100644 --- a/internal/gui/app.go +++ b/internal/gui/app.go @@ -230,6 +230,15 @@ func Run(version string, showMain bool, link string) error { } h.tray.SetMenu(menu) h.tray.AttachWindow(h.panel).WindowOffset(6) + // the quick panel by the icon, or the main window if the user would + // rather (Settings → Tray icon) + h.tray.OnClick(func() { + if settings.Load().Tray == "window" { + h.ShowMain("") + return + } + h.tray.ToggleWindow() + }) // Wails shows a Windows webview 3s after Show whether or not WebView2 // has made its controller yet, and a slow first start then crashes on diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 600e30d82..a9094dfdb 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -1759,11 +1759,13 @@ function renderUsage() { // ---------- settings ---------- // -// Two choices (palette, language) and the facts people come looking for: +// Three choices (palette, language, what the tray icon opens) and the facts +// people come looking for: // the version, where magpie keeps its files, the gateway's address. const THEMES = [["system", "System"], ["light", "Light"], ["dark", "Dark"]]; const LOCALES = [["system", "System"], ["en", "English"], ["zh", "中文"]]; +const TRAYS = [["panel", "Quick panel"], ["window", "Main window"]]; // applyPrefs paints and speaks as the saved settings say. A ?theme= or // ?locale= in the URL wins, so a forced look stays forced. @@ -1795,8 +1797,10 @@ async function loadSettings() { function renderSettings() { const s = prefs; - $("#themeSegs").replaceChildren(segs(THEMES.map(([id, name]) => [id, t(name)]), s.theme, (theme) => savePrefs({ theme, lang: s.lang }))); - $("#langSegs").replaceChildren(segs(LOCALES.map(([id, name]) => [id, t(name)]), s.lang, (lang) => savePrefs({ theme: s.theme, lang }))); + const keep = { theme: s.theme, lang: s.lang, tray: s.tray }; + $("#themeSegs").replaceChildren(segs(THEMES.map(([id, name]) => [id, t(name)]), s.theme, (theme) => savePrefs({ ...keep, theme }))); + $("#langSegs").replaceChildren(segs(LOCALES.map(([id, name]) => [id, t(name)]), s.lang, (lang) => savePrefs({ ...keep, lang }))); + $("#traySegs").replaceChildren(segs(TRAYS.map(([id, name]) => [id, t(name)]), s.tray || "panel", (tray) => savePrefs({ ...keep, tray }))); const about = $("#about"); about.replaceChildren(); diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 766b94be6..a15de4faf 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -31,6 +31,10 @@ const I18N = { "{agent} stays signed in; magpie just stops offering it": "{agent} 仍保持登录,只是 magpie 不再提供它", "You removed it from magpie.": "你已把它从 magpie 中移除。", "Add it back": "加回来", + "Tray icon": "托盘图标", + "What clicking magpie’s icon in the menu bar or tray opens": "点击菜单栏或托盘里的 magpie 图标时打开什么", + "Quick panel": "快捷面板", + "Main window": "主窗口", "{name} added back": "已加回 {name}", "auth": "认证", "agent default": "Agent 默认值", diff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.html index b31a9d2e9..327032169 100644 --- a/internal/gui/assets/index.html +++ b/internal/gui/assets/index.html @@ -88,6 +88,10 @@
Language
Applies at once, no restart
+
+
Tray icon
What clicking magpie’s icon in the menu bar or tray opens
+
+
About
diff --git a/internal/settings/settings.go b/internal/settings/settings.go index c4f6fcc7b..76406e830 100644 --- a/internal/settings/settings.go +++ b/internal/settings/settings.go @@ -18,12 +18,14 @@ import ( type Settings struct { Theme string `json:"theme,omitempty"` // system | light | dark Lang string `json:"lang,omitempty"` // system | en | zh + Tray string `json:"tray,omitempty"` // what clicking the tray icon opens: panel | window } // Themes and Langs are the accepted values, in the order the UI offers them. var ( Themes = []string{"system", "light", "dark"} Langs = []string{"system", "en", "zh"} + Trays = []string{"panel", "window"} ) // Path is the settings file. @@ -56,6 +58,9 @@ func Save(s Settings) error { if !slices.Contains(Langs, s.Lang) { return fmt.Errorf("language must be one of %v, not %q", Langs, s.Lang) } + if !slices.Contains(Trays, s.Tray) { + return fmt.Errorf("tray must be one of %v, not %q", Trays, s.Tray) + } if err := os.MkdirAll(Dir(), 0o755); err != nil { return err } @@ -73,5 +78,8 @@ func (s Settings) normal() Settings { if s.Lang == "" { s.Lang = "system" } + if s.Tray == "" { + s.Tray = "panel" + } return s }