Skip to content

Commit d330fda

Browse files
committed
feat(desktop): replace port dialog with service settings page
The tray action now opens a settings page with the server port and LAN access. LAN access is stored in the existing server.listen_addr field (127.0.0.1 or 0.0.0.0); no new configuration keys are added.
1 parent 77d3d6d commit d330fda

13 files changed

Lines changed: 621 additions & 492 deletions

File tree

‎desktop/README.md‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ macOS 12+ and Windows 10/11 (x64 / arm64).
3030
→ logger → i18n → db → signing → secrets → tasks → device manager) on
3131
`127.0.0.1:5533` by default;
3232
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;
33+
"Open Log File", "Settings", "Open at Login" and "Quit" actions; Settings is a
34+
MyGo-native page for the server port and LAN access;
3535
3. Opens `http://127.0.0.1:<port>/` in the default browser once started, and shuts
36-
down gracefully on quit. The port is stored in `server.port` in the app data
37-
directory's `config.yaml`; restart the app for changes to take effect.
36+
down gracefully on quit. The port is stored in `server.port` and LAN access in
37+
`server.listen_addr` (`127.0.0.1` or `0.0.0.0`) in the app data directory's
38+
`config.yaml`; restart the app for changes to take effect.
3839

3940
There is no main window: the app stays out of the Dock on macOS (`LSUIElement`) and
4041
shows no taskbar button on Windows. It does not use `mygo.Bind` typed IPC — the
@@ -50,7 +51,7 @@ desktop/
5051
└── app/
5152
├── go.mod # separate module (mygo needs Go 1.27+, see decision #2)
5253
├── main.go # shell entry: starts the server, tray icon, single instance, opens the browser
53-
├── port.go # initializes and validates config.yaml server.port (default 5533)
54+
├── settings.go # reads/writes config.yaml server.port and server.listen_addr
5455
├── locales.go # embeds the server catalogs (copied from the root locales/ at build time)
5556
├── plumesign.go # resolves the plumesign resource path (PathResources first, PATH fallback)
5657
├── mygo.config.ts # mygo CLI config (LSUIElement, macOS signing, resources)
@@ -71,7 +72,7 @@ desktop/
7172
|---|----------|-----------|
7273
| 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 |
7374
| 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") |
74-
| 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 |
75+
| 3 | **Port 5533 + configurable listen address** | Predictable local URL; the Settings page writes `server.port` and `server.listen_addr` (`127.0.0.1` local-only, `0.0.0.0` for LAN access) |
7576
| 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 |
7677
| 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 |
7778
| 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 |

‎desktop/app/main.go‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"os"
1313
"path/filepath"
1414
"runtime"
15+
"strconv"
1516

1617
"github.com/bitxeno/atvloadly/internal/app"
1718
"github.com/bitxeno/atvloadly/internal/bootstrap"
@@ -58,11 +59,12 @@ func run() error {
5859

5960
// The service shares the desktop app's identity: data lives in the app's
6061
// user data directory instead of ~/.config/<binary name>. Its existing
61-
// config.yaml stores server.port alongside the other server settings.
62+
// config.yaml stores server.port and server.listen_addr.
6263
appDataDir := dataDir()
6364
app.SetAppDataDir(appDataDir)
6465
configPath := desktopConfigPath(appDataDir)
65-
if err := ensureDesktopConfig(configPath); err != nil {
66+
desktop, err := loadDesktopSettings(configPath)
67+
if err != nil {
6668
return err
6769
}
6870

@@ -74,10 +76,11 @@ func run() error {
7476
_ = os.Setenv("PATH", dir+string(os.PathListSeparator)+os.Getenv("PATH"))
7577
}
7678

77-
url, stop, err := startService(configPath)
79+
_, stop, err := startService(configPath)
7880
if err != nil {
7981
return err
8082
}
83+
url := "http://" + loopbackListenAddr + ":" + strconv.Itoa(desktop.Port) + "/"
8184

8285
// Quit stops the service; a crash exit leaves it to the process exit.
8386
defer func() { stop() }()
@@ -129,7 +132,7 @@ func run() error {
129132
tray.OnClick(func() { tray.PopUpMenu() })
130133
}
131134
mygo.App.OnWillQuit(func(*mygo.QuitEvent) {
132-
closePortDialog()
135+
closeSettingsDialog()
133136
tray.Destroy()
134137
})
135138

@@ -147,7 +150,7 @@ func setTrayMenu(tray *mygo.Tray, url, logPath, configPath string) {
147150
menu := mygo.NewMenu([]*mygo.MenuItem{
148151
{Label: i18n.Localize("tray.open_browser"), Click: func(*mygo.MenuItem, *mygo.Window) { openBrowser(url) }},
149152
{Label: i18n.Localize("tray.open_log"), Click: func(*mygo.MenuItem, *mygo.Window) { openLogFile(logPath) }},
150-
{Label: i18n.Localize("tray.server_port"), Click: func(*mygo.MenuItem, *mygo.Window) { openPortDialog(configPath) }},
153+
{Label: i18n.Localize("tray.settings"), Click: func(*mygo.MenuItem, *mygo.Window) { openSettingsDialog(configPath) }},
151154
mygo.Separator(),
152155
{
153156
ID: "open-at-login",
@@ -184,10 +187,10 @@ func openLogFile(path string) {
184187
}
185188
}
186189

187-
// startService starts the atvloadly service on the given loopback port and
188-
// returns its URL. stop releases the port and stops the background jobs.
190+
// startService starts the atvloadly service on the configured address and
191+
// returns its URL. stop releases the listener and stops the background jobs.
189192
func startService(configPath string) (url string, stop func(), err error) {
190-
addr, stop, err := bootstrap.Run(bootstrap.Options{ConfigFile: configPath, ListenAddr: "127.0.0.1"})
193+
addr, stop, err := bootstrap.Run(bootstrap.Options{ConfigFile: configPath})
191194
if err != nil {
192195
return "", nil, err
193196
}

‎desktop/app/port.go‎

Lines changed: 0 additions & 161 deletions
This file was deleted.

0 commit comments

Comments
 (0)
⌂ 换网址