Skip to content

Commit 8c85de8

Browse files
authored
chore: better update ux (#1254)
1 parent 37419f0 commit 8c85de8

4 files changed

Lines changed: 28 additions & 10 deletions

File tree

apps/code/src/main/services/updates/schemas.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ export const UpdatesEvent = {
3030

3131
export type UpdatesStatusPayload = {
3232
checking: boolean;
33+
downloading?: boolean;
3334
upToDate?: boolean;
35+
updateReady?: boolean;
3436
version?: string;
3537
error?: string;
3638
};

apps/code/src/main/services/updates/service.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
type InstallUpdateOutput,
1111
UpdatesEvent,
1212
type UpdatesEvents,
13+
type UpdatesStatusPayload,
1314
} from "./schemas";
1415

1516
type CheckSource = "user" | "periodic";
@@ -101,6 +102,11 @@ export class UpdatesService extends TypedEventEmitter<UpdatesEvents> {
101102
});
102103
this.pendingNotification = true;
103104
this.flushPendingNotification();
105+
this.emitStatus({
106+
checking: false,
107+
updateReady: true,
108+
version: this.downloadedVersion ?? undefined,
109+
});
104110
return { success: true };
105111
}
106112

@@ -203,7 +209,7 @@ export class UpdatesService extends TypedEventEmitter<UpdatesEvents> {
203209
this.clearCheckTimeout();
204210
log.info("Update available, downloading...");
205211
// Keep checkingForUpdates true while downloading
206-
// The download is now in progress
212+
this.emitStatus({ checking: true, downloading: true });
207213
}
208214

209215
private handleNoUpdate(): void {
@@ -265,12 +271,7 @@ export class UpdatesService extends TypedEventEmitter<UpdatesEvents> {
265271
}
266272
}
267273

268-
private emitStatus(status: {
269-
checking: boolean;
270-
upToDate?: boolean;
271-
version?: string;
272-
error?: string;
273-
}): void {
274+
private emitStatus(status: UpdatesStatusPayload): void {
274275
this.emit(UpdatesEvent.Status, status);
275276
}
276277

apps/code/src/renderer/components/UpdatePrompt.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,16 @@ export function UpdatePrompt() {
188188
{ id: CHECK_TOAST_ID, duration: 3000 },
189189
);
190190
} else if (status.checking === true) {
191-
// Show checking toast
191+
// Show checking/downloading toast
192192
sonnerToast.custom(
193193
() => (
194194
<Card size="2">
195195
<Flex gap="2" align="center">
196196
<Spinner size="1" />
197197
<Text size="2" weight="medium">
198-
Checking for updates...
198+
{status.downloading
199+
? "Downloading update..."
200+
: "Checking for updates..."}
199201
</Text>
200202
</Flex>
201203
</Card>

apps/code/src/renderer/features/settings/components/sections/UpdatesSettings.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export function UpdatesSettings() {
3838
message: "Checking for updates...",
3939
type: "info",
4040
});
41+
} else if (result.errorCode === "already_checking") {
42+
// A check is already in progress (e.g. boot check) — show spinner and wait
43+
setUpdateStatus({ message: "Checking for updates...", type: "info" });
4144
} else {
4245
if (result.errorCode === "disabled") {
4346
setUpdatesDisabled(true);
@@ -68,12 +71,22 @@ export function UpdatesSettings() {
6871
useSubscription(
6972
trpcReact.updates.onStatus.subscriptionOptions(undefined, {
7073
onData: (status) => {
71-
if (status.checking === false && status.upToDate) {
74+
if (status.checking && status.downloading) {
75+
setUpdateStatus({ message: "Downloading update...", type: "info" });
76+
} else if (status.checking === false && status.upToDate) {
7277
setUpdateStatus({
7378
message: "You're on the latest version",
7479
type: "success",
7580
});
7681
setCheckingForUpdates(false);
82+
} else if (status.checking === false && status.updateReady) {
83+
setUpdateStatus({
84+
message: status.version
85+
? `Update ${status.version} ready to install`
86+
: "Update ready to install",
87+
type: "success",
88+
});
89+
setCheckingForUpdates(false);
7790
} else if (status.checking === false) {
7891
setCheckingForUpdates(false);
7992
}

0 commit comments

Comments
 (0)