Skip to content

Commit e2cf2e3

Browse files
committed
feat(desktop): add open-at-login setting
1 parent bed8bc9 commit e2cf2e3

7 files changed

Lines changed: 36 additions & 11 deletions

File tree

‎desktop/README.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ macOS 12+ and Windows 10/11 (x64 / arm64).
2929
1. Starts the existing server (reusing the boot order of `cmd/server`: config → settings
3030
→ logger → i18n → db → signing → secrets → tasks → device manager) on
3131
`127.0.0.1:5533` by default;
32-
2. Keeps an icon in the menu bar / notification area, with a menu holding "Open in
33-
Browser", "Open Log File", a MyGo-native "Change Server Port" window and "Quit" (localized in the UI language);
32+
2. Keeps an icon in the menu bar / notification area, with localized "Open in Browser",
33+
"Open Log File", "Change Server Port", "Open at Login" and "Quit" actions; the port
34+
editor is a MyGo-native window;
3435
3. Opens `http://127.0.0.1:<port>/` in the default browser once started, and shuts
3536
down gracefully on quit. The port is stored in `server.port` in the app data
3637
directory's `config.yaml`; restart the app for changes to take effect.
@@ -71,8 +72,9 @@ desktop/
7172
| 1 | **Shell + embedded server, not a Bind IPC rewrite** | `internal/*` (install manager, device manager, WS login/pair/progress) is reused whole, the frontend needs no changes, and the risk stays low |
7273
| 2 | **A separate `desktop/app/go.mod`** | The root module is go 1.25 and mygo needs Go 1.27+; isolating it keeps the main service build and CI untouched, while server code is reused by importing the root packages (see "How the server is reused") |
7374
| 3 | **Port 5533 + 127.0.0.1 loopback** | Predictable local URL; users can set `server.port` through the MyGo-native tray window; the desktop build serves nothing to the network |
74-
| 4 | **plumesign packed into resources** | mygo's platform resources mechanism packages it per platform, and `mygo build` signs the executables along with the app, which is what lets macOS Gatekeeper / Windows SmartScreen through |
75-
| 5 | **Config and data in the user directory** | A desktop app has no container `/data`; defaults to `~/Library/Application Support/atvloadly` (macOS) / `%APPDATA%\atvloadly` (Windows), with `server.work_dir` injected at startup |
75+
| 4 | **Open at Login** | The tray checkbox uses MyGo's native per-platform login-item integration; login-launched instances stay in the tray without opening a browser, and macOS 13+ may require approval in System Settings |
76+
| 5 | **plumesign packed into resources** | mygo's platform resources mechanism packages it per platform, and `mygo build` signs the executables along with the app, which is what lets macOS Gatekeeper / Windows SmartScreen through |
77+
| 6 | **Config and data in the user directory** | A desktop app has no container `/data`; defaults to `~/Library/Application Support/atvloadly` (macOS) / `%APPDATA%\atvloadly` (Windows), with `server.work_dir` injected at startup |
7678

7779
> The upstream plumesign release currently ships Linux packages only; its release
7880
> workflow already has the macOS/Windows targets (`plumesign-macos-universal`,

‎desktop/app/main.go‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/bitxeno/atvloadly/internal/app"
1717
"github.com/bitxeno/atvloadly/internal/bootstrap"
1818
"github.com/bitxeno/atvloadly/internal/i18n"
19+
logx "github.com/bitxeno/atvloadly/internal/log"
1920
"github.com/egoist/mygo"
2021
)
2122

@@ -111,15 +112,15 @@ func run() error {
111112
Icon: trayIcon(),
112113
IconIsTemplate: runtime.GOOS == "darwin",
113114
ToolTip: appName,
114-
Menu: trayMenu(url, logPath, configPath),
115115
})
116116
if err != nil {
117117
fatal(fmt.Errorf("no menu bar icon: %w", err))
118118
}
119+
setTrayMenu(tray, url, logPath, configPath)
119120
// The web UI saves the language it shows; relabel the menu as it
120121
// changes.
121122
i18n.OnLanguageChanged(func(string) {
122-
tray.SetMenu(trayMenu(url, logPath, configPath))
123+
setTrayMenu(tray, url, logPath, configPath)
123124
})
124125
if runtime.GOOS == "windows" {
125126
// The notification area opens TrayOptions.Menu on right-click;
@@ -132,21 +133,38 @@ func run() error {
132133
tray.Destroy()
133134
})
134135

135-
// The service is up: the launch lands in the browser.
136-
openBrowser(url)
136+
// Launching at login starts the service quietly in the tray. A
137+
// manual launch opens the browser after the service is ready.
138+
if !mygo.App.WasOpenedAtLogin() {
139+
openBrowser(url)
140+
}
137141
})
138142
return mygo.App.Run()
139143
}
140144

141-
// trayMenu builds the menu bar menu in the language the app shows.
142-
func trayMenu(url, logPath, configPath string) *mygo.Menu {
143-
return mygo.NewMenu([]*mygo.MenuItem{
145+
// setTrayMenu builds the tray menu and reflects the system autostart state.
146+
func setTrayMenu(tray *mygo.Tray, url, logPath, configPath string) {
147+
menu := mygo.NewMenu([]*mygo.MenuItem{
144148
{Label: i18n.Localize("tray.open_browser"), Click: func(*mygo.MenuItem, *mygo.Window) { openBrowser(url) }},
145149
{Label: i18n.Localize("tray.open_log"), Click: func(*mygo.MenuItem, *mygo.Window) { openLogFile(logPath) }},
146150
{Label: i18n.Localize("tray.server_port"), Click: func(*mygo.MenuItem, *mygo.Window) { openPortDialog(configPath) }},
147151
mygo.Separator(),
152+
{
153+
ID: "open-at-login",
154+
Label: i18n.Localize("tray.open_at_login"),
155+
Type: mygo.MenuItemCheckbox,
156+
Checked: mygo.App.OpenAtLogin(),
157+
Click: func(item *mygo.MenuItem, _ *mygo.Window) {
158+
if err := mygo.App.SetOpenAtLogin(item.IsChecked()); err != nil {
159+
logx.Err(err).Msg("Failed to update open-at-login setting")
160+
item.SetChecked(!item.IsChecked())
161+
}
162+
},
163+
},
164+
mygo.Separator(),
148165
{Role: mygo.RoleQuit, Label: i18n.Localize("tray.quit")},
149166
})
167+
tray.SetMenu(menu)
150168
}
151169

152170
// openBrowser opens url with the default browser.

‎locales/en.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"open_browser": "Open in Browser",
55
"open_log": "Open Log File",
66
"server_port": "Change Server Port",
7+
"open_at_login": "Open at Login",
78
"server_port_dialog_title": "Change Server Port",
89
"server_port_dialog_message": "Enter a TCP port (1–65535). Current port: {{.port}}. Restart the app for the change to take effect.",
910
"server_port_dialog_field": "Port",

‎locales/sr-Latn.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"open_browser": "Otvori u pregledaču",
55
"open_log": "Otvori datoteku evidencije",
66
"server_port": "Promeni port servera",
7+
"open_at_login": "Pokreni pri prijavljivanju",
78
"server_port_dialog_title": "Promena porta servera",
89
"server_port_dialog_message": "Unesite TCP port (1–65535). Trenutni port: {{.port}}. Ponovo pokrenite aplikaciju da bi promena stupila na snagu.",
910
"server_port_dialog_field": "Port",

‎locales/sr.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"open_browser": "Отвори у прегледачу",
55
"open_log": "Отвори датотеку евиденције",
66
"server_port": "Промени порт сервера",
7+
"open_at_login": "Покрени при пријављивању",
78
"server_port_dialog_title": "Промена порта сервера",
89
"server_port_dialog_message": "Унесите TCP порт (1–65535). Тренутни порт: {{.port}}. Поново покрените апликацију да би промена ступила на снагу.",
910
"server_port_dialog_field": "Порт",

‎locales/sv.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"open_browser": "Öppna i webbläsare",
55
"open_log": "Öppna loggfil",
66
"server_port": "Ändra serverport",
7+
"open_at_login": "Öppna vid inloggning",
78
"server_port_dialog_title": "Ändra serverport",
89
"server_port_dialog_message": "Ange en TCP-port (1–65535). Nuvarande port: {{.port}}. Starta om appen för att ändringen ska börja gälla.",
910
"server_port_dialog_field": "Port",

‎locales/zh_cn.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"open_browser": "打开浏览器",
55
"open_log": "打开日志文件",
66
"server_port": "修改服务端口",
7+
"open_at_login": "开机时启动",
78
"server_port_dialog_title": "修改服务端口",
89
"server_port_dialog_message": "请输入 TCP 端口(1–65535)。当前端口:{{.port}}。修改后需要重启程序生效。",
910
"server_port_dialog_field": "端口",

0 commit comments

Comments
 (0)
⌂ 换网址