From a7c8fce53581c23430f3e9ebb4b3cb8613c3f1fb Mon Sep 17 00:00:00 2001 From: yujiezhang-ops Date: Thu, 19 Nov 2026 16:21:47 +0800 Subject: [PATCH] fix: load settings when the autostart probe fails GetSettings returned the login-item probe's error as its own, so a build that cannot probe autostart could not read any setting. A server build has no login items and fails that probe on every read, which left the backup and terminal controls disabled behind "could not read the backup setting". The stored value now stands in when the probe fails. SaveSettings is unchanged and still reports the failure when the user changes the switch. Refs #258 Co-Authored-By: Claude Sonnet 5 --- frontend/e2e/wails.spec.ts | 9 +++++++++ internal/binding/services.go | 9 +++++++-- internal/binding/services_test.go | 27 +++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/frontend/e2e/wails.spec.ts b/frontend/e2e/wails.spec.ts index be083037..2f70d499 100644 --- a/frontend/e2e/wails.spec.ts +++ b/frontend/e2e/wails.spec.ts @@ -19,6 +19,15 @@ test("language selection switches to English and persists", async ({ page }) => await expect(page.getByRole("combobox", { name: "Language" })).toHaveText("English"); }); +// This build has no login items, so its autostart probe fails on every read. +// The field stays disabled until the settings have loaded, which makes it the +// check that the probe did not fail the whole read. +test("settings load in a build that cannot probe autostart", async ({ page }) => { + await page.goto("/#/settings"); + await expect(page.getByRole("spinbutton", { name: "备份历史版本数" })).toBeEnabled(); + await expect(page.getByRole("spinbutton", { name: "备份历史版本数" })).toHaveValue("3"); +}); + // The task centre is position: fixed at the viewport's lower-left corner, so it // takes no space in the sidebar's flex column. When the sidebar did not reserve // room for it, the rows margin-top: auto pushes to the bottom ended up diff --git a/internal/binding/services.go b/internal/binding/services.go index ecb3b0fc..b7723a37 100644 --- a/internal/binding/services.go +++ b/internal/binding/services.go @@ -240,8 +240,13 @@ func (s *RuntimeService) GetSettings(ctx context.Context) (app.Settings, error) if err != nil || s.autostart.IsEnabled == nil { return settings, err } - settings.Autostart, err = s.autostart.IsEnabled() - return settings, err + // The login item is a separate system from the settings file, and a server + // build has none, so its probe always fails. The stored value stands in then; + // SaveSettings still reports the failure when the user tries to change it. + if enabled, probeErr := s.autostart.IsEnabled(); probeErr == nil { + settings.Autostart = enabled + } + return settings, nil } // SaveSettings persists the download preferences and returns what was stored. diff --git a/internal/binding/services_test.go b/internal/binding/services_test.go index 7eaed094..2d80a751 100644 --- a/internal/binding/services_test.go +++ b/internal/binding/services_test.go @@ -122,6 +122,33 @@ func TestRuntimeServiceAppliesAutostartCallbacks(t *testing.T) { } } +// A server build has no login items, so its probe always fails. That must not +// take the backup and terminal settings down with it: they come from a file the +// probe has nothing to do with. +func TestGetSettingsSurvivesAFailingAutostartProbe(t *testing.T) { + core := providerCore(t, nil) + retention, stored := 7, true + if _, err := core.UpdateSettings(context.Background(), app.SettingsPatch{BackupRetention: &retention, Autostart: &stored}); err != nil { + t.Fatal(err) + } + service := &RuntimeService{ + core: core, + autostart: AutostartCallbacks{ + IsEnabled: func() (bool, error) { return false, errors.New("autostart is not supported on this platform") }, + }, + } + got, err := service.GetSettings(context.Background()) + if err != nil { + t.Fatalf("GetSettings failed with the probe: %v", err) + } + if got.BackupRetention != retention { + t.Fatalf("BackupRetention = %d, want %d", got.BackupRetention, retention) + } + if !got.Autostart { + t.Fatal("Autostart did not fall back to the stored value") + } +} + func TestOpenRegistrationUsesConfiguredProviderURL(t *testing.T) { var opened string service := NewProviderService(providerCore(t, nil), func(value string) error {