From d8d520622765d21436bab98c3f7f3c9714bb92fb Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Wed, 17 Jan 2024 10:01:05 +0000 Subject: [PATCH] fix: don't try to create window for mac before app is ready --- .../lib/electron/processes/main.process.ts | 20 +++++-------------- .../lib/electron/utils/deep-link.utils.ts | 13 +++++++----- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/packages/desktop/lib/electron/processes/main.process.ts b/packages/desktop/lib/electron/processes/main.process.ts index aadb41bee8..3e5e3dc152 100644 --- a/packages/desktop/lib/electron/processes/main.process.ts +++ b/packages/desktop/lib/electron/processes/main.process.ts @@ -13,38 +13,29 @@ 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' import { contextMenu } from '../menus/context.menu' import { initMenu } from '../menus/menu' import { initialiseAnalytics } from '../utils/analytics.utils' -import { - checkWindowArgsForDeepLinkRequest, - initialiseDeepLinks, - setAppAsDefaultProtocolClient, -} from '../utils/deep-link.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' initialiseAnalytics() - -try { - setAppAsDefaultProtocolClient() -} catch (error) { - console.error('Failed to set app as default protocol client', error) -} +initialiseDeepLinks() /* * NOTE: Ignored because defined by Webpack. @@ -300,7 +291,6 @@ void app.whenReady().then(() => { // Doesn't open & close a new window when the app is already open if (isFirstInstance) { createMainWindow() - initialiseDeepLinks() } }) diff --git a/packages/desktop/lib/electron/utils/deep-link.utils.ts b/packages/desktop/lib/electron/utils/deep-link.utils.ts index d67c0d9e39..ad706b11cb 100644 --- a/packages/desktop/lib/electron/utils/deep-link.utils.ts +++ b/packages/desktop/lib/electron/utils/deep-link.utils.ts @@ -1,7 +1,6 @@ import { app, ipcMain, protocol } from 'electron' import path from 'path' import { windows } from '../constants/windows.constant' -import { createMainWindow } from '../processes/main.process' /** * Define deep link state @@ -9,6 +8,12 @@ import { createMainWindow } from '../processes/main.process' let deepLinkRequest: string | undefined = undefined export function initialiseDeepLinks(): void { + try { + setAppAsDefaultProtocolClient() + } catch (error) { + console.error('Failed to set app as default protocol client', error) + } + /** * Handle deep linking on Mac * https://www.electronjs.org/docs/latest/api/app#event-open-url-macos @@ -27,7 +32,7 @@ export function initialiseDeepLinks(): void { ipcMain.on('clear-deep-link-request', clearDeepLinkRequest) } -export function setAppAsDefaultProtocolClient(): void { +function setAppAsDefaultProtocolClient(): void { /** * Register bloom:// protocol for deep links * https://www.electronjs.org/docs/latest/api/protocol#protocolregisterschemesasprivilegedcustomschemes @@ -60,14 +65,12 @@ function handleDeepLinkEventOnMac(event: Electron.Event, url: string): void { windows.main.restore() windows.main.focus() sendDeepLinkRequestToRenderer(deepLinkRequest) - } else { - createMainWindow() } } export function checkWindowArgsForDeepLinkRequest(_e: Electron.Event, args: string[]): void { if (args.length > 1) { - const url = args.find((arg) => arg.startsWith(`${process.env.APP_PROTOCOL}://`)) + const url = args.find((arg) => arg.startsWith(`${process.env.APP_RPOTOCOL}://`)) if (url) { deepLinkRequest = url