From ed223f03ad352ea55366deb7acc60e8b5b6c7202 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 27 Feb 2025 16:44:23 +0100 Subject: [PATCH 1/4] debug logs --- desktop/main.ts | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/desktop/main.ts b/desktop/main.ts index 4f642d90da51..fa61be3baffb 100644 --- a/desktop/main.ts +++ b/desktop/main.ts @@ -211,6 +211,9 @@ const showKeyboardShortcutsPage = (browserWindow: BrowserWindow) => { const electronUpdater = (browserWindow: BrowserWindow): PlatformSpecificUpdater => ({ init: () => { autoUpdater.on(ELECTRON_EVENTS.UPDATE_DOWNLOADED, (info) => { + // eslint-disable-next-line no-console + console.group('[dev] ELECTRON_EVENTS.UPDATE_DOWNLOADED'); + console.debug('[dev] info:', info); const systemMenu = Menu.getApplicationMenu(); const updateMenuItem = systemMenu?.getMenuItemById(`update`); const checkForUpdatesMenuItem = systemMenu?.getMenuItemById(`checkForUpdates`); @@ -226,15 +229,37 @@ const electronUpdater = (browserWindow: BrowserWindow): PlatformSpecificUpdater if (browserWindow.isVisible() && !isSilentUpdating) { browserWindow.webContents.send(ELECTRON_EVENTS.UPDATE_DOWNLOADED, info.version); } else { - quitAndInstallWithUpdate(); + console.debug('[dev] else'); + + autoUpdater + .checkForUpdates() + .then((result) => { + console.debug('[dev] result', result); + if (result?.updateInfo.version === downloadedVersion) { + quitAndInstallWithUpdate(); + } else { + return autoUpdater.downloadUpdate(); + } + }) + .then(() => { + quitAndInstallWithUpdate(); + }) + .catch((error) => { + console.debug('[dev] error', error); + log.error('Error during update check or download:', error); + }); } + // eslint-disable-next-line no-console + console.groupEnd(); }); ipcMain.on(ELECTRON_EVENTS.START_UPDATE, quitAndInstallWithUpdate); autoUpdater.checkForUpdates(); }, update: () => { - autoUpdater.checkForUpdates(); + autoUpdater.checkForUpdates().then((result) => { + console.debug('[dev] update result', result); + }); }, }); @@ -663,9 +688,9 @@ const mainWindow = (): Promise => { // Start checking for JS updates .then((browserWindowRef) => { - if (__DEV__) { - return; - } + // if (__DEV__) { + // return; + // } checkForUpdates(electronUpdater(browserWindowRef)); }) From c8f70feeac919e689fe1da50c87b71ff960652f3 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 3 Mar 2025 11:55:20 +0100 Subject: [PATCH 2/4] refactor: replace Localize.translate with translate for consistency in main.ts --- desktop/main.ts | 62 ++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/desktop/main.ts b/desktop/main.ts index fa61be3baffb..174185468d19 100644 --- a/desktop/main.ts +++ b/desktop/main.ts @@ -6,7 +6,7 @@ import type {ElectronLog} from 'electron-log'; import {autoUpdater} from 'electron-updater'; import {machineId} from 'node-machine-id'; import checkForUpdates from '@libs/checkForUpdates'; -import * as Localize from '@libs/Localize'; +import {translate} from '@libs/Localize'; import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; @@ -71,9 +71,9 @@ function pasteAsPlainText(browserWindow: BrowserWindow | BrowserView | WebviewTa function createContextMenu(preferredLocale: Locale = LOCALES.DEFAULT): () => void { return contextMenu({ labels: { - cut: Localize.translate(preferredLocale, 'desktopApplicationMenu.cut'), - paste: Localize.translate(preferredLocale, 'desktopApplicationMenu.paste'), - copy: Localize.translate(preferredLocale, 'desktopApplicationMenu.copy'), + cut: translate(preferredLocale, 'desktopApplicationMenu.cut'), + paste: translate(preferredLocale, 'desktopApplicationMenu.paste'), + copy: translate(preferredLocale, 'desktopApplicationMenu.copy'), }, append: (defaultActions, parameters, browserWindow) => [ { @@ -81,10 +81,10 @@ function createContextMenu(preferredLocale: Locale = LOCALES.DEFAULT): () => voi visible: parameters.isEditable && parameters.editFlags.canPaste, role: 'pasteAndMatchStyle', accelerator: DESKTOP_SHORTCUT_ACCELERATOR.PASTE_AND_MATCH_STYLE, - label: Localize.translate(preferredLocale, 'desktopApplicationMenu.pasteAndMatchStyle'), + label: translate(preferredLocale, 'desktopApplicationMenu.pasteAndMatchStyle'), }, { - label: Localize.translate(preferredLocale, 'desktopApplicationMenu.pasteAsPlainText'), + label: translate(preferredLocale, 'desktopApplicationMenu.pasteAsPlainText'), visible: parameters.isEditable && parameters.editFlags.canPaste && clipboard.readText().length > 0, accelerator: DESKTOP_SHORTCUT_ACCELERATOR.PASTE_AS_PLAIN_TEXT, click: () => pasteAsPlainText(browserWindow), @@ -126,7 +126,7 @@ let hasUpdate = false; let downloadedVersion: string; let isSilentUpdating = false; -// Note that we have to subscribe to this separately and cannot use Localize.translateLocal, +// Note that we have to subscribe to this separately and cannot use translateLocal, // because the only way code can be shared between the main and renderer processes at runtime is via the context bridge // So we track preferredLocale separately via ELECTRON_EVENTS.LOCALE_UPDATED const preferredLocale: Locale = CONST.LOCALES.DEFAULT; @@ -165,23 +165,23 @@ const manuallyCheckForUpdates = (menuItem?: MenuItem, browserWindow?: BaseWindow if (downloadPromise) { dialog.showMessageBox(browserWindow, { type: 'info', - message: Localize.translate(preferredLocale, 'checkForUpdatesModal.available.title'), - detail: Localize.translate(preferredLocale, 'checkForUpdatesModal.available.message', {isSilentUpdating}), - buttons: [Localize.translate(preferredLocale, 'checkForUpdatesModal.available.soundsGood')], + message: translate(preferredLocale, 'checkForUpdatesModal.available.title'), + detail: translate(preferredLocale, 'checkForUpdatesModal.available.message', {isSilentUpdating}), + buttons: [translate(preferredLocale, 'checkForUpdatesModal.available.soundsGood')], }); } else if (result && 'error' in result && result.error) { dialog.showMessageBox(browserWindow, { type: 'error', - message: Localize.translate(preferredLocale, 'checkForUpdatesModal.error.title'), - detail: Localize.translate(preferredLocale, 'checkForUpdatesModal.error.message'), - buttons: [Localize.translate(preferredLocale, 'checkForUpdatesModal.notAvailable.okay')], + message: translate(preferredLocale, 'checkForUpdatesModal.error.title'), + detail: translate(preferredLocale, 'checkForUpdatesModal.error.message'), + buttons: [translate(preferredLocale, 'checkForUpdatesModal.notAvailable.okay')], }); } else { dialog.showMessageBox(browserWindow, { type: 'info', - message: Localize.translate(preferredLocale, 'checkForUpdatesModal.notAvailable.title'), - detail: Localize.translate(preferredLocale, 'checkForUpdatesModal.notAvailable.message'), - buttons: [Localize.translate(preferredLocale, 'checkForUpdatesModal.notAvailable.okay')], + message: translate(preferredLocale, 'checkForUpdatesModal.notAvailable.title'), + detail: translate(preferredLocale, 'checkForUpdatesModal.notAvailable.message'), + buttons: [translate(preferredLocale, 'checkForUpdatesModal.notAvailable.okay')], cancelId: 2, }); } @@ -267,7 +267,7 @@ const localizeMenuItems = (submenu: MenuItemConstructorOptions[], updatedLocale: submenu.map((menu) => { const newMenu: MenuItemConstructorOptions = {...menu}; if (menu.id) { - const labelTranslation = Localize.translate(updatedLocale, `desktopApplicationMenu.${menu.id}` as TranslationPaths); + const labelTranslation = translate(updatedLocale, `desktopApplicationMenu.${menu.id}` as TranslationPaths); if (labelTranslation) { newMenu.label = labelTranslation; } @@ -378,14 +378,14 @@ const mainWindow = (): Promise => { const initialMenuTemplate: MenuItemConstructorOptions[] = [ { id: 'mainMenu', - label: Localize.translate(preferredLocale, `desktopApplicationMenu.mainMenu`), + label: translate(preferredLocale, `desktopApplicationMenu.mainMenu`), submenu: [ {id: 'about', role: 'about'}, - {id: 'update', label: Localize.translate(preferredLocale, `desktopApplicationMenu.update`), click: quitAndInstallWithUpdate, visible: false}, - {id: 'checkForUpdates', label: Localize.translate(preferredLocale, `desktopApplicationMenu.checkForUpdates`), click: manuallyCheckForUpdates}, + {id: 'update', label: translate(preferredLocale, `desktopApplicationMenu.update`), click: quitAndInstallWithUpdate, visible: false}, + {id: 'checkForUpdates', label: translate(preferredLocale, `desktopApplicationMenu.checkForUpdates`), click: manuallyCheckForUpdates}, { id: 'viewShortcuts', - label: Localize.translate(preferredLocale, `desktopApplicationMenu.viewShortcuts`), + label: translate(preferredLocale, `desktopApplicationMenu.viewShortcuts`), accelerator: 'CmdOrCtrl+J', click: () => { showKeyboardShortcutsPage(browserWindow); @@ -403,12 +403,12 @@ const mainWindow = (): Promise => { }, { id: 'fileMenu', - label: Localize.translate(preferredLocale, `desktopApplicationMenu.fileMenu`), + label: translate(preferredLocale, `desktopApplicationMenu.fileMenu`), submenu: [{id: 'closeWindow', role: 'close', accelerator: 'Cmd+w'}], }, { id: 'editMenu', - label: Localize.translate(preferredLocale, `desktopApplicationMenu.editMenu`), + label: translate(preferredLocale, `desktopApplicationMenu.editMenu`), submenu: [ {id: 'undo', role: 'undo'}, {id: 'redo', role: 'redo'}, @@ -431,7 +431,7 @@ const mainWindow = (): Promise => { {type: 'separator'}, { id: 'speechSubmenu', - label: Localize.translate(preferredLocale, `desktopApplicationMenu.speechSubmenu`), + label: translate(preferredLocale, `desktopApplicationMenu.speechSubmenu`), submenu: [ {id: 'startSpeaking', role: 'startSpeaking'}, {id: 'stopSpeaking', role: 'stopSpeaking'}, @@ -441,7 +441,7 @@ const mainWindow = (): Promise => { }, { id: 'viewMenu', - label: Localize.translate(preferredLocale, `desktopApplicationMenu.viewMenu`), + label: translate(preferredLocale, `desktopApplicationMenu.viewMenu`), submenu: [ {id: 'reload', role: 'reload'}, {id: 'forceReload', role: 'forceReload'}, @@ -456,7 +456,7 @@ const mainWindow = (): Promise => { }, { id: 'historyMenu', - label: Localize.translate(preferredLocale, `desktopApplicationMenu.historyMenu`), + label: translate(preferredLocale, `desktopApplicationMenu.historyMenu`), submenu: [ { id: 'back', @@ -497,33 +497,33 @@ const mainWindow = (): Promise => { }, { id: 'helpMenu', - label: Localize.translate(preferredLocale, `desktopApplicationMenu.helpMenu`), + label: translate(preferredLocale, `desktopApplicationMenu.helpMenu`), role: 'help', submenu: [ { id: 'learnMore', - label: Localize.translate(preferredLocale, `desktopApplicationMenu.learnMore`), + label: translate(preferredLocale, `desktopApplicationMenu.learnMore`), click: () => { shell.openExternal(CONST.MENU_HELP_URLS.LEARN_MORE); }, }, { id: 'documentation', - label: Localize.translate(preferredLocale, `desktopApplicationMenu.documentation`), + label: translate(preferredLocale, `desktopApplicationMenu.documentation`), click: () => { shell.openExternal(CONST.MENU_HELP_URLS.DOCUMENTATION); }, }, { id: 'communityDiscussions', - label: Localize.translate(preferredLocale, `desktopApplicationMenu.communityDiscussions`), + label: translate(preferredLocale, `desktopApplicationMenu.communityDiscussions`), click: () => { shell.openExternal(CONST.MENU_HELP_URLS.COMMUNITY_DISCUSSIONS); }, }, { id: 'searchIssues', - label: Localize.translate(preferredLocale, `desktopApplicationMenu.searchIssues`), + label: translate(preferredLocale, `desktopApplicationMenu.searchIssues`), click: () => { shell.openExternal(CONST.MENU_HELP_URLS.SEARCH_ISSUES); }, From b5be89884a70afbe30ffd80caa5e0604c1a94467 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 3 Mar 2025 12:56:36 +0100 Subject: [PATCH 3/4] fix: improve electron auto-update process with better logging and flow --- desktop/main.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/desktop/main.ts b/desktop/main.ts index 174185468d19..d6ee0bd49414 100644 --- a/desktop/main.ts +++ b/desktop/main.ts @@ -236,14 +236,16 @@ const electronUpdater = (browserWindow: BrowserWindow): PlatformSpecificUpdater .then((result) => { console.debug('[dev] result', result); if (result?.updateInfo.version === downloadedVersion) { + console.debug('[dev] if - versions match, installing'); quitAndInstallWithUpdate(); } else { - return autoUpdater.downloadUpdate(); + console.debug('[dev] else - downloading new update'); + return autoUpdater.downloadUpdate().then(() => { + console.debug('[dev] download complete, installing'); + quitAndInstallWithUpdate(); + }); } }) - .then(() => { - quitAndInstallWithUpdate(); - }) .catch((error) => { console.debug('[dev] error', error); log.error('Error during update check or download:', error); From c74fd295c3fa2769e391d0d6e0522d47297313e3 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 10 Mar 2025 13:40:05 +0100 Subject: [PATCH 4/4] revert dev condition --- desktop/main.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/desktop/main.ts b/desktop/main.ts index ba266a4402f0..1c5b6cfcb8a0 100644 --- a/desktop/main.ts +++ b/desktop/main.ts @@ -709,9 +709,9 @@ const mainWindow = (): Promise => { // Start checking for JS updates .then((browserWindowRef) => { - // if (__DEV__) { - // return; - // } + if (__DEV__) { + return; + } checkForUpdates(electronUpdater(browserWindowRef)); })