Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 8d35e03

Browse files
authored
auto-updater overwrites updates it has already downloaded (#557)
1 parent d339dfb commit 8d35e03

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

modules/desktop/electron/libs/auto-updater.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { type AppUpdater, autoUpdater } from "electron-updater";
22
import log from "./logger";
3-
import { BrowserWindow } from "electron";
43
import { MainWindowNotifier } from "./types";
54

65
type AutoUpdateStatus = {
@@ -12,6 +11,7 @@ autoUpdater.logger = log;
1211

1312
let mainWindowNotifier: MainWindowNotifier | null = null;
1413
let initalized = false;
14+
let isUpdating = false;
1515

1616
// keep the last status to resend to the window when it's opened becuase the store is destroyed when the window is closed
1717
let lastStatus: AutoUpdateStatus = { status: "up-to-date" };
@@ -21,13 +21,13 @@ export const getUpdater = () => autoUpdater;
2121
export function checkUpdater(notifier: MainWindowNotifier): AppUpdater {
2222
try {
2323
mainWindowNotifier = notifier;
24-
autoUpdater.checkForUpdatesAndNotify();
24+
checkForUpdates();
2525

2626
if (!initalized) {
2727
initalized = true;
2828

2929
setInterval(() => {
30-
autoUpdater.checkForUpdatesAndNotify();
30+
checkForUpdates();
3131
}, 1000 * 60 * 30); // check for updates every 30 minutes
3232
}
3333
} catch (error) {
@@ -37,6 +37,30 @@ export function checkUpdater(notifier: MainWindowNotifier): AppUpdater {
3737
return autoUpdater;
3838
}
3939

40+
const checkForUpdates = async () => {
41+
if (isUpdating) {
42+
log.info("Update is already in progress");
43+
return;
44+
}
45+
46+
isUpdating = true;
47+
48+
try {
49+
const result = await autoUpdater.checkForUpdatesAndNotify();
50+
if (!result?.downloadPromise) {
51+
isUpdating = false;
52+
} else {
53+
const files = await result.downloadPromise;
54+
log.info("Successfully downloaded update files:", files);
55+
// DO NOT RESET isUpdating here because the user still needs to click to install it
56+
// and we don't want to accidentally start another update and overwrite the file
57+
}
58+
} catch (err) {
59+
log.error("Error checking for updates:", err);
60+
isUpdating = false;
61+
}
62+
};
63+
4064
// The auto update runs in the background so the window might not be open when the status changes
4165
// When the update store gets created as part of the window it will request the latest status.
4266
export function getAutoUpdateStatus() {

modules/desktop/src/components/settings-menu/settings-menu.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
class="group flex h-[28px] w-[28px] items-center justify-center rounded-sm border border-gray hover:bg-[#e1e1e1]"
2525
class:circle-badge={$updateStatus.status === "available" || $updateStatus.status === "ready"}
2626
on:click={() => (isOpen = !isOpen)}
27-
class:animate-bounce={$updateStatus.status === "ready"}
2827
title="settings"
2928
>
3029
<div class="icon-gear text-l flex text-gray group-hover:text-black" />

0 commit comments

Comments
 (0)