From 16c7b658c9c42d75dcd531b4b44ec8f4a1b062c3 Mon Sep 17 00:00:00 2001 From: gijoe0295 Date: Tue, 16 Apr 2024 03:58:31 +0700 Subject: [PATCH 1/6] feature: silently update on desktop --- desktop/ELECTRON_EVENTS.ts | 1 + desktop/contextBridge.ts | 1 + desktop/main.ts | 21 ++++++++++++++----- .../AppUpdate/updateApp/index.desktop.ts | 5 ++--- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/desktop/ELECTRON_EVENTS.ts b/desktop/ELECTRON_EVENTS.ts index de0bd655e12c..607ad7b21580 100644 --- a/desktop/ELECTRON_EVENTS.ts +++ b/desktop/ELECTRON_EVENTS.ts @@ -9,6 +9,7 @@ const ELECTRON_EVENTS = { KEYBOARD_SHORTCUTS_PAGE: 'keyboard-shortcuts-page', START_UPDATE: 'start-update', UPDATE_DOWNLOADED: 'update-downloaded', + SILENT_UPDATE: 'silent-update', } as const; export default ELECTRON_EVENTS; diff --git a/desktop/contextBridge.ts b/desktop/contextBridge.ts index 689c69de0cc8..487e528a7485 100644 --- a/desktop/contextBridge.ts +++ b/desktop/contextBridge.ts @@ -16,6 +16,7 @@ const WHITELIST_CHANNELS_RENDERER_TO_MAIN = [ ELECTRON_EVENTS.REQUEST_VISIBILITY, ELECTRON_EVENTS.START_UPDATE, ELECTRON_EVENTS.LOCALE_UPDATED, + ELECTRON_EVENTS.SILENT_UPDATE, ] as const; const WHITELIST_CHANNELS_MAIN_TO_RENDERER = [ELECTRON_EVENTS.KEYBOARD_SHORTCUTS_PAGE, ELECTRON_EVENTS.UPDATE_DOWNLOADED, ELECTRON_EVENTS.FOCUS, ELECTRON_EVENTS.BLUR] as const; diff --git a/desktop/main.ts b/desktop/main.ts index 6e14d661b345..640b6a417a73 100644 --- a/desktop/main.ts +++ b/desktop/main.ts @@ -111,6 +111,7 @@ process.argv.forEach((arg) => { // happens correctly. let hasUpdate = false; let downloadedVersion: string; +let isSilentUpdate = 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 @@ -128,11 +129,12 @@ const quitAndInstallWithUpdate = () => { }; /** Menu Item callback to triggers an update check */ -const manuallyCheckForUpdates = (menuItem: MenuItem, browserWindow?: BrowserWindow) => { +const manuallyCheckForUpdates = (menuItem?: MenuItem, browserWindow?: BrowserWindow) => { // Disable item until the check (and download) is complete - // eslint: menu item flags like enabled or visible can be dynamically toggled by mutating the object - // eslint-disable-next-line no-param-reassign - menuItem.enabled = false; + if (menuItem) { + // eslint-disable-next-line no-param-reassign -- menu item flags like enabled or visible can be dynamically toggled by mutating the object + menuItem.enabled = false; + } autoUpdater .checkForUpdates() @@ -172,6 +174,9 @@ const manuallyCheckForUpdates = (menuItem: MenuItem, browserWindow?: BrowserWind return downloadPromise; }) .finally(() => { + if (!menuItem) { + return; + } // eslint-disable-next-line no-param-reassign menuItem.enabled = true; }); @@ -201,7 +206,7 @@ const electronUpdater = (browserWindow: BrowserWindow): PlatformSpecificUpdater if (checkForUpdatesMenuItem) { checkForUpdatesMenuItem.visible = false; } - if (browserWindow.isVisible()) { + if (browserWindow.isVisible() && !isSilentUpdate) { browserWindow.webContents.send(ELECTRON_EVENTS.UPDATE_DOWNLOADED, info.version); } else { quitAndInstallWithUpdate(); @@ -604,6 +609,12 @@ const mainWindow = (): Promise => { } }); + // Automatically check for and install the latest version in the background + ipcMain.on(ELECTRON_EVENTS.SILENT_UPDATE, () => { + isSilentUpdate = true; + manuallyCheckForUpdates(); + }); + return browserWindow; }) diff --git a/src/libs/actions/AppUpdate/updateApp/index.desktop.ts b/src/libs/actions/AppUpdate/updateApp/index.desktop.ts index fb3a7d649baa..5c1ecbe05742 100644 --- a/src/libs/actions/AppUpdate/updateApp/index.desktop.ts +++ b/src/libs/actions/AppUpdate/updateApp/index.desktop.ts @@ -1,6 +1,5 @@ -import {Linking} from 'react-native'; -import CONST from '@src/CONST'; +import ELECTRON_EVENTS from '@desktop/ELECTRON_EVENTS'; export default function updateApp() { - Linking.openURL(CONST.APP_DOWNLOAD_LINKS.DESKTOP); + window.electron.send(ELECTRON_EVENTS.SILENT_UPDATE); } From 316552a18579fbd5706b8306a1db30c986545eae Mon Sep 17 00:00:00 2001 From: gijoe0295 Date: Wed, 17 Apr 2024 08:03:05 +0700 Subject: [PATCH 2/6] temporary change version to test --- desktop/main.ts | 2 +- package-lock.json | 4 ++-- package.json | 2 +- src/languages/en.ts | 2 +- src/languages/es.ts | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/desktop/main.ts b/desktop/main.ts index 640b6a417a73..662278d540fa 100644 --- a/desktop/main.ts +++ b/desktop/main.ts @@ -150,7 +150,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'), + detail: Localize.translate(preferredLocale, 'checkForUpdatesModal.available.message', {isSilentUpdate}), buttons: [Localize.translate(preferredLocale, 'checkForUpdatesModal.available.soundsGood')], }); } else if (result && 'error' in result && result.error) { diff --git a/package-lock.json b/package-lock.json index ae50c5d543b2..32adc60abe02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "new.expensify", - "version": "1.4.62-10", + "version": "1.4.61-8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "new.expensify", - "version": "1.4.62-10", + "version": "1.4.61-8", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 9a7d7ba0a333..0efbab6c503e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "new.expensify", - "version": "1.4.62-10", + "version": "1.4.57-5", "author": "Expensify, Inc.", "homepage": "https://new.expensify.com", "description": "New Expensify is the next generation of Expensify: a reimagination of payments based atop a foundation of chat.", diff --git a/src/languages/en.ts b/src/languages/en.ts index 9451407c822f..4f226ae96b59 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -2456,7 +2456,7 @@ export default { checkForUpdatesModal: { available: { title: 'Update Available', - message: "The new version will be available shortly. We'll notify you when we're ready to update.", + message: ({isSilentUpdate}: {isSilentUpdate: boolean}) => `The new version will be available shortly.${isSilentUpdate ? " We'll notify you when we're ready to update." : ''}`, soundsGood: 'Sounds good', }, notAvailable: { diff --git a/src/languages/es.ts b/src/languages/es.ts index a56c8ac2739d..2ebfa6085286 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -2488,7 +2488,7 @@ export default { checkForUpdatesModal: { available: { title: 'Actualización disponible', - message: 'La nueva versión estará disponible dentro de poco. Te notificaremos cuando esté lista.', + message: ({isSilentUpdate}: {isSilentUpdate: boolean}) => `La nueva versión estará disponible dentro de poco.${isSilentUpdate ? ' Te notificaremos cuando esté lista.' : ''}`, soundsGood: 'Suena bien', }, notAvailable: { From 55a56b4db3fef75e09c127bbf46bca649d04e0b8 Mon Sep 17 00:00:00 2001 From: Joe Ph <153004152+gijoe0295@users.noreply.github.com> Date: Mon, 22 Apr 2024 22:34:10 +0700 Subject: [PATCH 3/6] Fix typo Co-authored-by: Alex Beaman --- desktop/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desktop/main.ts b/desktop/main.ts index 662278d540fa..0b5c59a8a78d 100644 --- a/desktop/main.ts +++ b/desktop/main.ts @@ -128,7 +128,7 @@ const quitAndInstallWithUpdate = () => { autoUpdater.quitAndInstall(); }; -/** Menu Item callback to triggers an update check */ +/** Menu Item callback to trigger an update check */ const manuallyCheckForUpdates = (menuItem?: MenuItem, browserWindow?: BrowserWindow) => { // Disable item until the check (and download) is complete if (menuItem) { From 232838ffb2cf61ea3d8e9a4a493a6afac8a69f72 Mon Sep 17 00:00:00 2001 From: gijoe0295 Date: Fri, 26 Apr 2024 11:29:22 +0700 Subject: [PATCH 4/6] show dialog --- desktop/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desktop/main.ts b/desktop/main.ts index 0b5c59a8a78d..636b7c67fc89 100644 --- a/desktop/main.ts +++ b/desktop/main.ts @@ -612,7 +612,7 @@ const mainWindow = (): Promise => { // Automatically check for and install the latest version in the background ipcMain.on(ELECTRON_EVENTS.SILENT_UPDATE, () => { isSilentUpdate = true; - manuallyCheckForUpdates(); + manuallyCheckForUpdates(undefined, browserWindow); }); return browserWindow; From 3baac627a1a3b8137e8db0cd3e3a5c1ed5e043e5 Mon Sep 17 00:00:00 2001 From: gijoe0295 Date: Fri, 26 Apr 2024 20:02:57 +0700 Subject: [PATCH 5/6] run update once --- desktop/main.ts | 17 ++++++++++++----- src/languages/en.ts | 3 ++- src/languages/es.ts | 3 ++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/desktop/main.ts b/desktop/main.ts index 636b7c67fc89..be3d8722fa56 100644 --- a/desktop/main.ts +++ b/desktop/main.ts @@ -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) { browserWindow.webContents.send(ELECTRON_EVENTS.UPDATE_DOWNLOADED, info.version); } else { quitAndInstallWithUpdate(); @@ -611,7 +615,10 @@ const mainWindow = (): Promise => { // 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); }); diff --git a/src/languages/en.ts b/src/languages/en.ts index a545e67fbd63..8aaa352d4ebf 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -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: { diff --git a/src/languages/es.ts b/src/languages/es.ts index ca130a5df588..2e2d1f19ebd3 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -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: { From 202987e4097640a291d903d98664221993a3333c Mon Sep 17 00:00:00 2001 From: gijoe0295 Date: Tue, 30 Apr 2024 23:17:54 +0700 Subject: [PATCH 6/6] modify comment --- desktop/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desktop/main.ts b/desktop/main.ts index be3d8722fa56..b40557464ec1 100644 --- a/desktop/main.ts +++ b/desktop/main.ts @@ -130,8 +130,8 @@ const quitAndInstallWithUpdate = () => { /** Menu Item callback to trigger an update check */ const manuallyCheckForUpdates = (menuItem?: MenuItem, browserWindow?: BrowserWindow) => { - // Disable item until the check (and download) is complete if (menuItem) { + // Disable item until the check (and download) is complete // eslint-disable-next-line no-param-reassign -- menu item flags like enabled or visible can be dynamically toggled by mutating the object menuItem.enabled = false; }