diff --git a/packages/desktop/lib/electron/processes/main.process.ts b/packages/desktop/lib/electron/processes/main.process.ts index 71583cdfea..f5917f75e1 100644 --- a/packages/desktop/lib/electron/processes/main.process.ts +++ b/packages/desktop/lib/electron/processes/main.process.ts @@ -13,14 +13,15 @@ import { UtilityProcess, } from 'electron' import { WebPreferences } from 'electron/main' -import path from 'path' import fs from 'fs' +import path from 'path' import features from '@features/features' import { LedgerApiMethod } from '@core/ledger/enums' import { windows } from '../constants/windows.constant' +import type { ILedgerProcessMessage } from '../interfaces/ledger-process-message.interface' import AutoUpdateManager from '../managers/auto-update.manager' import KeychainManager from '../managers/keychain.manager' import NftDownloadManager from '../managers/nft-download.manager' @@ -31,12 +32,14 @@ import { initialiseAnalytics } from '../utils/analytics.utils' import { checkWindowArgsForDeepLinkRequest, initialiseDeepLinks } from '../utils/deep-link.utils' import { getDiagnostics } from '../utils/diagnostics.utils' import { shouldReportError } from '../utils/error.utils' -import { getMachineId } from '../utils/os.utils' -import type { ILedgerProcessMessage } from '../interfaces/ledger-process-message.interface' import { ensureDirectoryExistence } from '../utils/file-system.utils' +import { getMachineId } from '../utils/os.utils' + +export let appIsReady = false initialiseAnalytics() initialiseDeepLinks() + /* * NOTE: Ignored because defined by Webpack. */ @@ -281,6 +284,7 @@ void app.whenReady().then(() => { // Doesn't open & close a new window when the app is already open if (isFirstInstance) { createMainWindow() + appIsReady = true } }) diff --git a/packages/desktop/lib/electron/utils/deep-link.utils.ts b/packages/desktop/lib/electron/utils/deep-link.utils.ts index 9ccf0941aa..b3acc1905b 100644 --- a/packages/desktop/lib/electron/utils/deep-link.utils.ts +++ b/packages/desktop/lib/electron/utils/deep-link.utils.ts @@ -1,7 +1,7 @@ import { app, ipcMain, protocol } from 'electron' import path from 'path' import { windows } from '../constants/windows.constant' -import { createMainWindow } from '../processes/main.process' +import { appIsReady, createMainWindow } from '../processes/main.process' /** * Define deep link state @@ -9,7 +9,11 @@ import { createMainWindow } from '../processes/main.process' let deepLinkRequest: string | undefined = undefined export function initialiseDeepLinks(): void { - setAppAsDefaultProtocolClient() + try { + setAppAsDefaultProtocolClient() + } catch (error) { + console.error('Failed to set app as default protocol client', error) + } /** * Handle deep linking on Mac @@ -20,7 +24,7 @@ export function initialiseDeepLinks(): void { // Check if deep link was passed when the app was not running ipcMain.on('dom-content-loaded', (event) => { - if (windows.main) { + if (windows?.main) { checkWindowArgsForDeepLinkRequest(event, process.argv) } }) @@ -49,7 +53,7 @@ function setAppAsDefaultProtocolClient(): void { } function sendDeepLinkRequestToRenderer(url: string): void { - if (windows.main) { + if (windows?.main) { windows.main.webContents.send('deep-link-request', url) } } @@ -58,11 +62,11 @@ function handleDeepLinkEventOnMac(event: Electron.Event, url: string): void { deepLinkRequest = url event.preventDefault() - if (windows.main) { + if (windows?.main) { windows.main.restore() windows.main.focus() sendDeepLinkRequestToRenderer(deepLinkRequest) - } else { + } else if (appIsReady) { createMainWindow() } }