Skip to content

Commit

Permalink
run update once
Browse files Browse the repository at this point in the history
  • Loading branch information
gijoe0295 committed Apr 26, 2024
1 parent 232838f commit 3baac62
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
17 changes: 12 additions & 5 deletions desktop/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ process.argv.forEach((arg) => {
// happens correctly.
let hasUpdate = false;
let downloadedVersion: string;
let isSilentUpdate = false;
let isSilentUpdating = false;

// Note that we have to subscribe to this separately and cannot use Localize.translateLocal,
// because the only way code can be shared between the main and renderer processes at runtime is via the context bridge
Expand All @@ -138,7 +138,10 @@ const manuallyCheckForUpdates = (menuItem?: MenuItem, browserWindow?: BrowserWin

autoUpdater
.checkForUpdates()
.catch((error) => ({error}))
.catch((error) => {
isSilentUpdating = false;
return {error};
})
.then((result) => {
const downloadPromise = result && 'downloadPromise' in result ? result.downloadPromise : undefined;

Expand All @@ -150,7 +153,7 @@ const manuallyCheckForUpdates = (menuItem?: MenuItem, browserWindow?: BrowserWin
dialog.showMessageBox(browserWindow, {
type: 'info',
message: Localize.translate(preferredLocale, 'checkForUpdatesModal.available.title'),
detail: Localize.translate(preferredLocale, 'checkForUpdatesModal.available.message', {isSilentUpdate}),
detail: Localize.translate(preferredLocale, 'checkForUpdatesModal.available.message', {isSilentUpdating}),
buttons: [Localize.translate(preferredLocale, 'checkForUpdatesModal.available.soundsGood')],
});
} else if (result && 'error' in result && result.error) {
Expand All @@ -174,6 +177,7 @@ const manuallyCheckForUpdates = (menuItem?: MenuItem, browserWindow?: BrowserWin
return downloadPromise;
})
.finally(() => {
isSilentUpdating = false;
if (!menuItem) {
return;
}
Expand Down Expand Up @@ -206,7 +210,7 @@ const electronUpdater = (browserWindow: BrowserWindow): PlatformSpecificUpdater
if (checkForUpdatesMenuItem) {
checkForUpdatesMenuItem.visible = false;
}
if (browserWindow.isVisible() && !isSilentUpdate) {
if (browserWindow.isVisible() && !isSilentUpdating) {
browserWindow.webContents.send(ELECTRON_EVENTS.UPDATE_DOWNLOADED, info.version);
} else {
quitAndInstallWithUpdate();
Expand Down Expand Up @@ -611,7 +615,10 @@ const mainWindow = (): Promise<void> => {

// Automatically check for and install the latest version in the background
ipcMain.on(ELECTRON_EVENTS.SILENT_UPDATE, () => {
isSilentUpdate = true;
if (isSilentUpdating) {
return;
}
isSilentUpdating = true;
manuallyCheckForUpdates(undefined, browserWindow);
});

Expand Down
3 changes: 2 additions & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2532,7 +2532,8 @@ export default {
checkForUpdatesModal: {
available: {
title: 'Update Available',
message: ({isSilentUpdate}: {isSilentUpdate: boolean}) => `The new version will be available shortly.${isSilentUpdate ? " We'll notify you when we're ready to update." : ''}`,
message: ({isSilentUpdating}: {isSilentUpdating: boolean}) =>
`The new version will be available shortly.${!isSilentUpdating ? " We'll notify you when we're ready to update." : ''}`,
soundsGood: 'Sounds good',
},
notAvailable: {
Expand Down
3 changes: 2 additions & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2564,7 +2564,8 @@ export default {
checkForUpdatesModal: {
available: {
title: 'Actualización disponible',
message: ({isSilentUpdate}: {isSilentUpdate: boolean}) => `La nueva versión estará disponible dentro de poco.${isSilentUpdate ? ' Te notificaremos cuando esté lista.' : ''}`,
message: ({isSilentUpdating}: {isSilentUpdating: boolean}) =>
`La nueva versión estará disponible dentro de poco.${isSilentUpdating ? ' Te notificaremos cuando esté lista.' : ''}`,
soundsGood: 'Suena bien',
},
notAvailable: {
Expand Down

0 comments on commit 3baac62

Please sign in to comment.