mirror of
https://github.com/ivabus/gui
synced 2025-04-23 14:07:14 +03:00
auto-updater overwrites updates it has already downloaded (#557)
This commit is contained in:
parent
d339dfb02d
commit
8d35e03314
2 changed files with 27 additions and 4 deletions
|
@ -1,6 +1,5 @@
|
|||
import { type AppUpdater, autoUpdater } from "electron-updater";
|
||||
import log from "./logger";
|
||||
import { BrowserWindow } from "electron";
|
||||
import { MainWindowNotifier } from "./types";
|
||||
|
||||
type AutoUpdateStatus = {
|
||||
|
@ -12,6 +11,7 @@ autoUpdater.logger = log;
|
|||
|
||||
let mainWindowNotifier: MainWindowNotifier | null = null;
|
||||
let initalized = false;
|
||||
let isUpdating = false;
|
||||
|
||||
// keep the last status to resend to the window when it's opened becuase the store is destroyed when the window is closed
|
||||
let lastStatus: AutoUpdateStatus = { status: "up-to-date" };
|
||||
|
@ -21,13 +21,13 @@ export const getUpdater = () => autoUpdater;
|
|||
export function checkUpdater(notifier: MainWindowNotifier): AppUpdater {
|
||||
try {
|
||||
mainWindowNotifier = notifier;
|
||||
autoUpdater.checkForUpdatesAndNotify();
|
||||
checkForUpdates();
|
||||
|
||||
if (!initalized) {
|
||||
initalized = true;
|
||||
|
||||
setInterval(() => {
|
||||
autoUpdater.checkForUpdatesAndNotify();
|
||||
checkForUpdates();
|
||||
}, 1000 * 60 * 30); // check for updates every 30 minutes
|
||||
}
|
||||
} catch (error) {
|
||||
|
@ -37,6 +37,30 @@ export function checkUpdater(notifier: MainWindowNotifier): AppUpdater {
|
|||
return autoUpdater;
|
||||
}
|
||||
|
||||
const checkForUpdates = async () => {
|
||||
if (isUpdating) {
|
||||
log.info("Update is already in progress");
|
||||
return;
|
||||
}
|
||||
|
||||
isUpdating = true;
|
||||
|
||||
try {
|
||||
const result = await autoUpdater.checkForUpdatesAndNotify();
|
||||
if (!result?.downloadPromise) {
|
||||
isUpdating = false;
|
||||
} else {
|
||||
const files = await result.downloadPromise;
|
||||
log.info("Successfully downloaded update files:", files);
|
||||
// DO NOT RESET isUpdating here because the user still needs to click to install it
|
||||
// and we don't want to accidentally start another update and overwrite the file
|
||||
}
|
||||
} catch (err) {
|
||||
log.error("Error checking for updates:", err);
|
||||
isUpdating = false;
|
||||
}
|
||||
};
|
||||
|
||||
// The auto update runs in the background so the window might not be open when the status changes
|
||||
// When the update store gets created as part of the window it will request the latest status.
|
||||
export function getAutoUpdateStatus() {
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
class="group flex h-[28px] w-[28px] items-center justify-center rounded-sm border border-gray hover:bg-[#e1e1e1]"
|
||||
class:circle-badge={$updateStatus.status === "available" || $updateStatus.status === "ready"}
|
||||
on:click={() => (isOpen = !isOpen)}
|
||||
class:animate-bounce={$updateStatus.status === "ready"}
|
||||
title="settings"
|
||||
>
|
||||
<div class="icon-gear text-l flex text-gray group-hover:text-black" />
|
||||
|
|
Loading…
Reference in a new issue