Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: silently update desktop app #40253

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
run update once
gijoe0295 committed Apr 26, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 3baac627a1a3b8137e8db0cd3e3a5c1ed5e043e5
17 changes: 12 additions & 5 deletions desktop/main.ts
Original file line number Diff line number Diff line change
@@ -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
@@ -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;

@@ -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) {
@@ -174,6 +177,7 @@ const manuallyCheckForUpdates = (menuItem?: MenuItem, browserWindow?: BrowserWin
return downloadPromise;
})
.finally(() => {
isSilentUpdating = false;
if (!menuItem) {
return;
}
@@ -206,7 +210,7 @@ const electronUpdater = (browserWindow: BrowserWindow): PlatformSpecificUpdater
if (checkForUpdatesMenuItem) {
checkForUpdatesMenuItem.visible = false;
}
if (browserWindow.isVisible() && !isSilentUpdate) {
if (browserWindow.isVisible() && !isSilentUpdating) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gijoe0295 I still think that we should show a notification to the user after updating version successfully

cc @Beamanator

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm well this is why we're calling it "silent" updating I guess haha. At this point, if the user already clicked "Update" I'm not sure this would require another notification to the user -> Like on Web, we would just refresh & BAM it's updated, no extra notification 🤔

browserWindow.webContents.send(ELECTRON_EVENTS.UPDATE_DOWNLOADED, info.version);
} else {
quitAndInstallWithUpdate();
@@ -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);
});

3 changes: 2 additions & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
@@ -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: {
3 changes: 2 additions & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
@@ -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: {