gui: Settings → Tray icon chooses whether a click opens the quick panel or the main window (#7)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 默认值",
|
||||
|
||||
@@ -88,6 +88,10 @@
|
||||
<div class="who"><div class="name" data-t>Language</div><div class="sub" data-t>Applies at once, no restart</div></div>
|
||||
<div id="langSegs"></div>
|
||||
</div>
|
||||
<div class="row pref">
|
||||
<div class="who"><div class="name" data-t>Tray icon</div><div class="sub" data-t>What clicking magpie’s icon in the menu bar or tray opens</div></div>
|
||||
<div id="traySegs"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row-head"><span class="label" data-t>About</span></div>
|
||||
<div class="list prefs" id="about"></div>
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user