Skip to content

Commit

Permalink
fix: opening mac deeplink when app is quit (#1715)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicole-obrien authored Jan 17, 2024
1 parent 499ec30 commit a75f913
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
10 changes: 7 additions & 3 deletions packages/desktop/lib/electron/processes/main.process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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
}
})

Expand Down
16 changes: 10 additions & 6 deletions packages/desktop/lib/electron/utils/deep-link.utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
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
*/
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
Expand All @@ -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)
}
})
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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()
}
}
Expand Down

0 comments on commit a75f913

Please sign in to comment.