Browse Source

refactor: use ipcRenderer.invoke / ipcMain.handle in default-app (#18581)

Milan Burda 5 years ago
parent
commit
69e32ad9ce
2 changed files with 4 additions and 8 deletions
  1. 2 6
      default_app/default_app.ts
  2. 2 2
      default_app/preload.ts

+ 2 - 6
default_app/default_app.ts

@@ -37,12 +37,8 @@ function isTrustedSender (webContents: Electron.WebContents) {
   return parsedUrl.protocol === 'file:' && urlPath === indexPath
 }
 
-ipcMain.on('bootstrap', (event) => {
-  try {
-    event.returnValue = isTrustedSender(event.sender) ? electronPath : null
-  } catch {
-    event.returnValue = null
-  }
+ipcMain.handle('bootstrap', (event) => {
+  return isTrustedSender(event.sender) ? electronPath : null
 })
 
 async function createWindow () {

+ 2 - 2
default_app/preload.ts

@@ -1,7 +1,7 @@
 import { ipcRenderer } from 'electron'
 
-function initialize () {
-  const electronPath = ipcRenderer.sendSync('bootstrap')
+async function initialize () {
+  const electronPath = await ipcRenderer.invoke('bootstrap')
 
   function replaceText (selector: string, text: string) {
     const element = document.querySelector<HTMLElement>(selector)