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 {