Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main-process/atom-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 16 additions & 14 deletions src/protocol-handler-installer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { remote } = require('electron');
const { ipcRenderer } = require('electron');

const SETTING = 'core.uriHandlerRegistration';
const PROMPT = 'prompt';
Expand All @@ -10,39 +10,41 @@ 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;
}

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;
Expand Down