settings: the Dock can follow the window — Hide, With window, Show. With window, magpie is in the Dock (and Cmd-Tab) while its window is open and leaves it when the window is closed, so it can be switched to without an icon kept there the rest of the time. Tested on a sandboxed bundle: shown at start, gone on close, back on reopen; Show and Hide behave as before. Issue #101
This commit is contained in:
@@ -49,7 +49,7 @@ type Bundle struct {
|
||||
App string `json:"app,omitempty"` // the magpie that made it
|
||||
Keys bool `json:"keys"` // whether the providers carry their keys
|
||||
Providers []provider.Provider `json:"providers"`
|
||||
Icons map[string][]byte `json:"icons,omitempty"` // pictures picked for providers, by file name
|
||||
Icons map[string][]byte `json:"icons,omitempty"` // pictures picked for providers, by file name
|
||||
Groups []provider.Group `json:"groups,omitempty"` // the user's model groups
|
||||
Settings *settings.Settings `json:"settings,omitempty"`
|
||||
Profiles map[string]profile.Profile `json:"profiles,omitempty"`
|
||||
@@ -237,7 +237,7 @@ func Restore(b Bundle, parts Parts) (Result, error) {
|
||||
if parts.Settings && b.Settings != nil {
|
||||
// the window's size and the proxy are this machine's own
|
||||
s, cur := *b.Settings, settings.Load()
|
||||
s.Window, s.Proxy, s.Dock = cur.Window, cur.Proxy, cur.Dock
|
||||
s.Window, s.Proxy, s.Dock, s.DockWindow = cur.Window, cur.Proxy, cur.Dock, cur.DockWindow
|
||||
if err := settings.Save(s); err != nil {
|
||||
return r, err
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ func hashes(b backup.Bundle) map[string]string {
|
||||
if b.Settings != nil {
|
||||
s = *b.Settings
|
||||
}
|
||||
s.Window, s.Proxy, s.Dock = nil, "", false // this computer's own: never synced
|
||||
s.Window, s.Proxy, s.Dock, s.DockWindow = nil, "", false, false // this computer's own: never synced
|
||||
return map[string]string{
|
||||
"providers": h([]any{b.Providers, b.Icons, b.Groups}),
|
||||
"settings": h(s),
|
||||
|
||||
+5
-5
@@ -126,9 +126,9 @@ func settingsState() settingsJSON {
|
||||
return s
|
||||
}
|
||||
|
||||
// onDock puts the app in the Mac's Dock or takes it out, when the Settings
|
||||
// page changes that; set by the process that has the app.
|
||||
var onDock func(bool)
|
||||
// onDock puts the app in the Mac's Dock or takes it out as the settings say,
|
||||
// when the Settings page changes them; set by the process that has the app.
|
||||
var onDock func(settings.Settings)
|
||||
|
||||
// assetTypes are the page's own files' types. The file server takes them
|
||||
// from Windows' registry, which another program may have changed — an SVG
|
||||
@@ -312,8 +312,8 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
|
||||
fail(rw, err)
|
||||
return
|
||||
}
|
||||
if in.Dock != cur.Dock && onDock != nil {
|
||||
onDock(in.Dock)
|
||||
if (in.Dock != cur.Dock || in.DockWindow != cur.DockWindow) && onDock != nil {
|
||||
onDock(in)
|
||||
}
|
||||
writeJSON(rw, settingsState())
|
||||
})
|
||||
|
||||
+11
-1
@@ -66,6 +66,7 @@ func (h *host) ShowMain(view string) {
|
||||
if view != "" {
|
||||
h.main.SetURL("/?view=" + view + h.query)
|
||||
}
|
||||
h.dock(settings.Load(), true)
|
||||
h.main.Show()
|
||||
h.main.Focus()
|
||||
}
|
||||
@@ -76,10 +77,18 @@ func (h *host) Import(link string) {
|
||||
h.whenReady(func() {
|
||||
h.panel.Hide()
|
||||
h.main.SetURL("/?view=providers&import=" + id + h.query)
|
||||
h.dock(settings.Load(), true)
|
||||
h.main.Show()
|
||||
h.main.Focus()
|
||||
})
|
||||
}
|
||||
|
||||
// dock puts magpie in the Dock or takes it out as s says, with the window
|
||||
// shown or not: always, never, or while the window is.
|
||||
func (h *host) dock(s settings.Settings, shown bool) {
|
||||
setDock(s.Dock || s.DockWindow && shown, shown)
|
||||
}
|
||||
|
||||
func (h *host) Quit() { h.app.Quit() }
|
||||
func (h *host) OpenURL(url string) { _ = h.app.Browser.OpenURL(url) }
|
||||
func (h *host) OpenFolder(path string) error { return openFolder(h.app, path) }
|
||||
@@ -152,7 +161,7 @@ func Run(version string, showMain bool, link string) error {
|
||||
ErrorHandler: func(err error) { log.Println("magpie:", err) },
|
||||
})
|
||||
|
||||
onDock = setDock
|
||||
onDock = func(s settings.Settings) { h.dock(s, h.main.IsVisible()) }
|
||||
// The Dock icon opens the window. Wails would show every hidden window
|
||||
// on it, the panel too, so the hook answers first and stops it.
|
||||
h.app.Event.RegisterApplicationEventHook(events.Mac.ApplicationShouldHandleReopen, func(e *application.ApplicationEvent) {
|
||||
@@ -229,6 +238,7 @@ func Run(version string, showMain bool, link string) error {
|
||||
// Closing the window keeps the tray alive; quitting is a menu action.
|
||||
h.main.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
|
||||
h.main.Hide()
|
||||
h.dock(settings.Load(), false)
|
||||
e.Cancel()
|
||||
})
|
||||
|
||||
|
||||
@@ -3963,14 +3963,15 @@ const DISCORD_SVG = '<svg viewBox="0 0 24 24" width="13" height="13" fill="curre
|
||||
|
||||
function renderSettings() {
|
||||
const s = prefs;
|
||||
const keep = { theme: s.theme, lang: s.lang, tray: s.tray, dock: !!s.dock, proxy: s.proxy || "",
|
||||
const keep = { theme: s.theme, lang: s.lang, tray: s.tray, dock: !!s.dock, dockWindow: !!s.dockWindow, proxy: s.proxy || "",
|
||||
redact: !!s.redact, redactPersonal: !!s.redactPersonal, redactWords: s.redactWords || [] };
|
||||
$("#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 })));
|
||||
// the Dock is the Mac's
|
||||
$("#dockRow").hidden = !document.body.classList.contains("mac");
|
||||
$("#dockSegs").replaceChildren(segs([["off", t("Hide")], ["on", t("Show")]], s.dock ? "on" : "off", (v) => savePrefs({ ...keep, dock: v === "on" })));
|
||||
$("#dockSegs").replaceChildren(segs([["off", t("Hide")], ["window", t("With window")], ["on", t("Show")]],
|
||||
s.dock ? "on" : s.dockWindow ? "window" : "off", (v) => savePrefs({ ...keep, dock: v === "on", dockWindow: v === "window" })));
|
||||
// the system's record, set on its own, not with the other choices
|
||||
$("#loginSegs").replaceChildren(segs([["off", t("Off")], ["on", t("On")]], s.login ? "on" : "off", (v) =>
|
||||
api("settings/login", { on: v === "on" }).then((ns) => { prefs = ns; renderSettings(); }).catch((e) => { status(t(e.message), "err"); renderSettings(); })));
|
||||
|
||||
@@ -62,7 +62,8 @@ const I18N = {
|
||||
"Open at login": "开机自启",
|
||||
"Start magpie in the tray when you log in, so agents find the gateway from the start": "登录系统时在托盘里启动 magpie,各个 Agent 一开始就能连上网关",
|
||||
"move magpie to Applications first, then turn this on": "请先把 magpie 移到「应用程序」文件夹,再打开这个选项",
|
||||
"Keep magpie in the Dock too, for a menu bar too full to show its icon": "让 magpie 同时常驻程序坞,菜单栏图标被挤掉时也能打开",
|
||||
"Keep magpie in the Dock too, always or while its window is open, for Cmd-Tab and a menu bar too full to show its icon": "让 magpie 也出现在程序坞:常驻,或只在窗口打开时显示,方便 Cmd-Tab 切换,菜单栏图标被挤掉时也能打开",
|
||||
"With window": "跟随窗口",
|
||||
"What clicking magpie’s icon in the menu bar or tray opens": "点击菜单栏或托盘里的 magpie 图标时打开什么",
|
||||
"Quick panel": "快捷面板",
|
||||
"Main window": "主窗口",
|
||||
|
||||
@@ -125,7 +125,7 @@
|
||||
<div id="loginSegs"></div>
|
||||
</div>
|
||||
<div class="row pref" id="dockRow" hidden>
|
||||
<div class="who"><div class="name" data-t>Dock</div><div class="sub" data-t>Keep magpie in the Dock too, for a menu bar too full to show its icon</div></div>
|
||||
<div class="who"><div class="name" data-t>Dock</div><div class="sub" data-t>Keep magpie in the Dock too, always or while its window is open, for Cmd-Tab and a menu bar too full to show its icon</div></div>
|
||||
<div id="dockSegs"></div>
|
||||
</div>
|
||||
<div class="row pref">
|
||||
|
||||
@@ -78,12 +78,15 @@ static int tintPanel(void *w, int r, int g, int b, int a, int ms) {
|
||||
}
|
||||
|
||||
// A Dock icon is the Regular activation policy, none is Accessory. Leaving
|
||||
// the Dock deactivates the app, so it is brought back to the front after,
|
||||
// with the window the Settings page is in.
|
||||
static void setDock(int on) {
|
||||
// the Dock deactivates the app, so with front set it is brought back to the
|
||||
// front after, with the window the Settings page is in; a window just closed
|
||||
// leaves it where it is.
|
||||
static void setDock(int on, int front) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[NSApp setActivationPolicy:on ? NSApplicationActivationPolicyRegular : NSApplicationActivationPolicyAccessory];
|
||||
if (!on) [NSApp activateIgnoringOtherApps:YES];
|
||||
NSApplicationActivationPolicy p = on ? NSApplicationActivationPolicyRegular : NSApplicationActivationPolicyAccessory;
|
||||
if ([NSApp activationPolicy] == p) return;
|
||||
[NSApp setActivationPolicy:p];
|
||||
if (front) [NSApp activateIgnoringOtherApps:YES];
|
||||
});
|
||||
}
|
||||
*/
|
||||
@@ -119,8 +122,9 @@ func dockPolicy(on bool) application.ActivationPolicy {
|
||||
return application.ActivationPolicyAccessory
|
||||
}
|
||||
|
||||
// setDock shows magpie in the Dock or takes it out, at once.
|
||||
func setDock(on bool) { C.setDock(C.int(boolInt(on))) }
|
||||
// setDock shows magpie in the Dock or takes it out, at once, bringing it to
|
||||
// the front after when front.
|
||||
func setDock(on, front bool) { C.setDock(C.int(boolInt(on)), C.int(boolInt(front))) }
|
||||
|
||||
func boolInt(b bool) int {
|
||||
if b {
|
||||
|
||||
@@ -6,7 +6,7 @@ import "github.com/wailsapp/wails/v3/pkg/application"
|
||||
|
||||
// The Dock is the Mac's; elsewhere magpie stays in the tray.
|
||||
func dockPolicy(bool) application.ActivationPolicy { return application.ActivationPolicyAccessory }
|
||||
func setDock(bool) {}
|
||||
func setDock(bool, bool) {}
|
||||
|
||||
// glidePanel steps the shown panel to height a frame at a time, keeping it
|
||||
// by the tray icon as it goes.
|
||||
|
||||
@@ -25,6 +25,10 @@ type Settings struct {
|
||||
// Dock keeps magpie in the Mac's Dock as well as the menu bar, for a
|
||||
// menu bar too full to show its icon.
|
||||
Dock bool `json:"dock,omitempty"`
|
||||
// DockWindow shows it in the Dock only while its window is open, so
|
||||
// Cmd-Tab reaches the window without an icon kept there the rest of
|
||||
// the time. Dock wins over it.
|
||||
DockWindow bool `json:"dockWindow,omitempty"`
|
||||
// Proxy for magpie's own requests to vendors: "" follows the
|
||||
// environment and then the system, "direct" uses none, anything else
|
||||
// is the proxy (http://, https:// or socks5://; host:port means http).
|
||||
|
||||
Reference in New Issue
Block a user