diff --git a/src/main-process/atom-application.js b/src/main-process/atom-application.js index 0346aaa498e..f05d4924496 100644 --- a/src/main-process/atom-application.js +++ b/src/main-process/atom-application.js @@ -133,6 +133,13 @@ const decryptOptions = (optionsMessage, secret) => { return JSON.parse(message); }; +ipcMain.handle('isDefaultProtocolClient', (_, { protocol, path, args }) => { + return app.isDefaultProtocolClient(protocol, path, args); +}); + +ipcMain.handle('setAsDefaultProtocolClient', (_, { protocol, path, args }) => { + return app.setAsDefaultProtocolClient(protocol, path, args); +}); // The application's singleton class. // // It's the entry point into the Atom application and maintains the global state diff --git a/src/protocol-handler-installer.js b/src/protocol-handler-installer.js index 2f3c0740df1..6b904fc7a49 100644 --- a/src/protocol-handler-installer.js +++ b/src/protocol-handler-installer.js @@ -1,4 +1,4 @@ -const { remote } = require('electron'); +const { ipcRenderer } = require('electron'); const SETTING = 'core.uriHandlerRegistration'; const PROMPT = 'prompt'; @@ -10,26 +10,28 @@ module.exports = class ProtocolHandlerInstaller { return ['win32', 'darwin'].includes(process.platform); } - isDefaultProtocolClient() { - return remote.app.isDefaultProtocolClient('atom', process.execPath, [ - '--uri-handler', - '--' - ]); + async isDefaultProtocolClient() { + return ipcRenderer.invoke('isDefaultProtocolClient', { + protocol: 'atom', + path: process.execPath, + args: ['--uri-handler', '--'] + }); } - setAsDefaultProtocolClient() { + async setAsDefaultProtocolClient() { // This Electron API is only available on Windows and macOS. There might be some // hacks to make it work on Linux; see https://github.com/electron/electron/issues/6440 return ( this.isSupported() && - remote.app.setAsDefaultProtocolClient('atom', process.execPath, [ - '--uri-handler', - '--' - ]) + ipcRenderer.invoke('setAsDefaultProtocolClient', { + protocol: 'atom', + path: process.execPath, + args: ['--uri-handler', '--'] + }) ); } - initialize(config, notifications) { + async initialize(config, notifications) { if (!this.isSupported()) { return; } @@ -37,12 +39,12 @@ module.exports = class ProtocolHandlerInstaller { const behaviorWhenNotProtocolClient = config.get(SETTING); switch (behaviorWhenNotProtocolClient) { case PROMPT: - if (!this.isDefaultProtocolClient()) { + if (await !this.isDefaultProtocolClient()) { this.promptToBecomeProtocolClient(config, notifications); } break; case ALWAYS: - if (!this.isDefaultProtocolClient()) { + if (await !this.isDefaultProtocolClient()) { this.setAsDefaultProtocolClient(); } break;