feat: add LAN access configuration for desktop app, allowing users to enable public API access with corresponding UI updates and translations

This commit is contained in:
wizardchen
2026-04-11 16:34:40 +08:00
committed by lyingbug
parent d99e2cbac3
commit dfaaa62f14
14 changed files with 421 additions and 558 deletions
+25 -3
View File
@@ -7,9 +7,11 @@ import (
// App holds Wails-bound state for the desktop shell.
type App struct {
ctx context.Context
backendURL string
shutdownCh chan struct{}
ctx context.Context
backendURL string
apiLanBaseURL string
listenPublic bool
shutdownCh chan struct{}
}
// NewApp creates a new App application struct.
@@ -46,3 +48,23 @@ func (a *App) GetDesktopHTTPPortSetting() int {
func (a *App) SetDesktopHTTPPortSetting(port int) error {
return SaveDesktopHTTPPortPreference(port)
}
// GetDesktopHTTPBindPublicSetting returns whether API listens on all interfaces (0.0.0.0).
func (a *App) GetDesktopHTTPBindPublicSetting() bool {
return LoadDesktopHTTPBindPublic()
}
// SetDesktopHTTPBindPublicSetting saves LAN/public listen preference. Restart the app for it to take effect.
func (a *App) SetDesktopHTTPBindPublicSetting(v bool) error {
return SaveDesktopHTTPBindPublicPreference(v)
}
// GetAPILanBaseURL returns a suggested base URL for other devices on the LAN (…/api/v1), or empty if not in bind-public mode or IP detection failed.
func (a *App) GetAPILanBaseURL() string {
return a.apiLanBaseURL
}
// GetDesktopListenPublicActive is true when this session’s API server is listening on all interfaces (runtime), not the saved preference.
func (a *App) GetDesktopListenPublicActive() bool {
return a.listenPublic
}