Skip to content

Commit

Permalink
fix: don't try to create window for mac before app is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
nicole-obrien committed Jan 17, 2024
1 parent ab5c1cc commit d8d5206
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
20 changes: 5 additions & 15 deletions packages/desktop/lib/electron/processes/main.process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
}
})

Expand Down
13 changes: 8 additions & 5 deletions packages/desktop/lib/electron/utils/deep-link.utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
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
*/
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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d8d5206

Please sign in to comment.