Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/desktop/electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ const updater = new AppUpdaterController({
if (!host?.isAvailable()) throw new Error("host unavailable");
await host.call("settings.set", { lastNotifiedUpdateVersion: version });
},
persistDismissedVersion: async (version) => {
const host = getHost();
if (!host?.isAvailable()) throw new Error("host unavailable");
await host.call("settings.set", { updateDismissedVersion: version });
},
});

/**
Expand Down
4 changes: 4 additions & 0 deletions apps/desktop/electron/main/ipc/app-ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,8 @@ export function registerAppIpc({
await updater.openReleases();
return { ok: true };
});
handle(IPC.invoke.updatesDismiss, async () => {
await updater.dismiss();
return { ok: true };
});
}
48 changes: 48 additions & 0 deletions apps/desktop/electron/main/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const MANUAL_CHECK_TIMEOUT_MS = 15_000;
export type UpdaterSettings = {
updatePreference?: unknown;
lastNotifiedUpdateVersion?: unknown;
updateDismissedVersion?: unknown;
};

export type UpdaterOptions = {
Expand All @@ -92,6 +93,8 @@ export type UpdaterOptions = {
currentVersion: string;
readUpdateSettings?: () => Promise<UpdaterSettings>;
persistLastNotifiedVersion?: (version: string) => Promise<void>;
/** Persists the version whose update notice the user dismissed (#1317). */
persistDismissedVersion?: (version: string | null) => Promise<void>;
/**
* Active product UI locale for shipped-locale release notes.
* Called when attaching notes to update state; defaults to English.
Expand Down Expand Up @@ -120,13 +123,18 @@ export class AppUpdaterController {
private readonly automaticSupported: boolean;
private readonly readUpdateSettings?: () => Promise<UpdaterSettings>;
private readonly persistLastNotifiedVersion?: (version: string) => Promise<void>;
private readonly persistDismissedVersion?: (
version: string | null,
) => Promise<void>;
private readonly manualReminderTracker = new ManualUpdateReminderTracker();
private preference: UpdatePreference;
private preferenceRevision = 0;
private settingsReady: Promise<void> | null = null;
private autoCheckStarted = false;
private disposed = false;
private state: UpdateState;
/** Version whose notice the user dismissed; cleared when a new one appears. */
private dismissedVersion?: string;
private manualRequested = false;
private initialTimer: NodeJS.Timeout | null = null;
private intervalTimer: NodeJS.Timeout | null = null;
Expand Down Expand Up @@ -198,6 +206,7 @@ export class AppUpdaterController {
);
this.readUpdateSettings = options.readUpdateSettings;
this.persistLastNotifiedVersion = options.persistLastNotifiedVersion;
this.persistDismissedVersion = options.persistDismissedVersion;
const mode = resolveUpdateModePolicy(
platform,
isPackaged,
Expand Down Expand Up @@ -275,6 +284,17 @@ export class AppUpdaterController {
) {
this.manualReminderTracker.hydrate(lastNotifiedVersion);
}
const dismissedVersion = settings.updateDismissedVersion;
if (
typeof dismissedVersion === "string" &&
dismissedVersion.length > 0 &&
dismissedVersion.length <= 128
) {
this.dismissedVersion = dismissedVersion;
if (this.state.availableVersion === dismissedVersion) {
this.setState({ dismissed: true });
}
}
const preference = resolveStoredUpdatePreference(
settings.updatePreference,
this.defaultPreference,
Expand Down Expand Up @@ -364,6 +384,26 @@ export class AppUpdaterController {
this.applyPreference(preference, true);
}

/**
* Records the user's decision to stop nudging about `availableVersion`
* until a newer version is detected (#1317). The banner hides itself from
* the pushed `dismissed` flag, so the decision survives restarts.
*/
async dismiss(): Promise<void> {
const version = this.state.availableVersion;
if (!version) return;
this.dismissedVersion = version;
this.setState({ dismissed: true });
if (!this.persistDismissedVersion) return;
try {
await this.persistDismissedVersion(version);
} catch (error) {
this.logger.app("updater", "warn", "update dismissal persistence failed", {
data: { detail: String(error), version },
});
}
}

private attachListeners() {
if (this.listenersAttached) return;
this.listenersAttached = true;
Expand Down Expand Up @@ -403,11 +443,19 @@ export class AppUpdaterController {
});
this.autoUpdater.on("update-available", (info: UpdateInfo) => {
const automatic = this.state.mode === "in-app";
// A newly discovered version supersedes any earlier dismissal.
if (this.dismissedVersion && this.dismissedVersion !== info.version) {
this.dismissedVersion = undefined;
if (this.persistDismissedVersion) {
void this.persistDismissedVersion(null).catch(() => undefined);
}
}
this.setState({
status: automatic ? "downloading" : "available",
availableVersion: info.version,
releaseNotes: this.notesFor(info.version),
progressPercent: automatic ? 0 : undefined,
dismissed: this.dismissedVersion === info.version,
manualReminder: automatic
? false
: this.manualReminderFor(info.version),
Expand Down
7 changes: 5 additions & 2 deletions apps/desktop/src/components/UpdateBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function UpdateBanner() {

if (!update?.availableVersion) return null;
const stateKey = `${update.availableVersion}:${update.status}`;
if (stateKey === dismissedState) return null;
if (stateKey === dismissedState || update.dismissed === true) return null;

const visible =
update.status === "downloaded" ||
Expand Down Expand Up @@ -124,7 +124,10 @@ export function UpdateBanner() {
tooltip={t("updates.dismiss")}
ariaLabel={t("updates.dismiss")}
className="update-notice-dismiss"
onClick={() => setDismissedState(stateKey)}
onClick={() => {
setDismissedState(stateKey);
void api.updatesDismiss().catch(() => undefined);
}}
>
<IconClose className="size-3.5" />
</TooltipButton>
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ export const api = {
updatesDownload: () => invoke<UpdateState>(IPC.invoke.updatesDownload),
updatesInstall: () => invoke(IPC.invoke.updatesInstall),
updatesOpenReleases: () => invoke(IPC.invoke.updatesOpenReleases),
updatesDismiss: () => invoke(IPC.invoke.updatesDismiss),
openFeedback: () => invoke(IPC.invoke.appOpenFeedback),
listNotifications: (input?: { unreadOnly?: boolean; limit?: number }) =>
invoke<NotificationListResult>(IPC.invoke.notificationList, input ?? {}),
Expand Down
7 changes: 7 additions & 0 deletions apps/desktop/test/update-preference.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,10 @@ test("Settings → Info saves only valid automatic/manual preferences", async ()
assert.match(updateSettingsSource, /persistUpdatePreference\(value, saveSettings\)/);
assert.match(updateBannerSource, /manualReminder === true/);
});

test("dismissed update banner hides via persisted state, not component memory", () => {
// The banner must consult the durable `dismissed` flag from UpdateState and
// record the dismissal through the updatesDismiss IPC channel (#1317).
assert.match(updateBannerSource, /update\.dismissed === true/);
assert.match(updateBannerSource, /api\.updatesDismiss\(\)/);
});
26 changes: 26 additions & 0 deletions crates/host-core/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,27 @@ fn validate_settings_value(value: &Value) -> Result<(), JsonRpcError> {
));
}
}
if let Some(version) = object.get("updateDismissedVersion") {
match version {
serde_json::Value::Null => {}
serde_json::Value::String(version) => {
if version.trim().is_empty() || version.len() > 128 {
return Err(rpc_err(
1002,
"updateDismissedVersion must contain 1 to 128 characters",
"INVALID_PARAMS",
));
}
}
_ => {
return Err(rpc_err(
1002,
"updateDismissedVersion must be a string or null",
"INVALID_PARAMS",
));
}
}
}
if let Some(infinite_retry) = object.get("infiniteProviderRetry") {
if !infinite_retry.is_boolean() {
return Err(rpc_err(
Expand Down Expand Up @@ -9463,6 +9484,8 @@ mod update_settings_tests {
json!({"updatePreference": "automatic"}),
json!({"updatePreference": "manual"}),
json!({"lastNotifiedUpdateVersion": "0.15.9"}),
json!({"updateDismissedVersion": "0.15.9"}),
json!({"updateDismissedVersion": null}),
] {
assert!(validate_settings_value(&value).is_ok(), "{value}");
}
Expand All @@ -9472,6 +9495,9 @@ mod update_settings_tests {
json!({"lastNotifiedUpdateVersion": " "}),
json!({"lastNotifiedUpdateVersion": 12}),
json!({"lastNotifiedUpdateVersion": "x".repeat(129)}),
json!({"updateDismissedVersion": " "}),
json!({"updateDismissedVersion": 12}),
json!({"updateDismissedVersion": "x".repeat(129)}),
] {
assert!(validate_settings_value(&value).is_err(), "{value}");
}
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export const IPC = {
updatesDownload: "pi-desktop/updates/download",
updatesInstall: "pi-desktop/updates/install",
updatesOpenReleases: "pi-desktop/updates/openReleases",
/** Persist the user's decision to stop nudging about one version (#1317). */
updatesDismiss: "pi-desktop/updates/dismiss",
notificationList: "pi-desktop/notification/list",
notificationMarkRead: "pi-desktop/notification/markRead",
notificationMarkAllRead: "pi-desktop/notification/markAllRead",
Expand Down
5 changes: 5 additions & 0 deletions packages/shared/src/types/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ export type UpdateState = {
error?: string;
/** True when the transition came from a user-initiated check. */
manual?: boolean;
/**
* True when the user dismissed the notice for `availableVersion`. Stays
* dismissed across restarts until a newer version is detected (#1317).
*/
dismissed?: boolean;
releasesUrl: string;
};

Expand Down
Loading