Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
Remove webcatalog: protocol support (#1621)
Browse files Browse the repository at this point in the history
  • Loading branch information
quanglam2807 authored Jan 27, 2022
1 parent b60b311 commit e50a15a
Showing 1 changed file with 1 addition and 61 deletions.
62 changes: 1 addition & 61 deletions main-src/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,51 +61,9 @@ if (!gotTheLock) {
}
}

// Register protocol
app.setAsDefaultProtocolClient('webcatalog');

loadListeners();
loadInvokers();

// mock app.whenReady
let trulyReady = false;
ipcMain.once('truly-ready', () => { trulyReady = true; });
const whenTrulyReady = () => {
if (trulyReady) return Promise.resolve();
return new Promise((resolve) => {
ipcMain.once('truly-ready', () => {
trulyReady = true;
resolve();
});
});
};

const handleOpenUrl = (urlStr) => {
whenTrulyReady()
.then(() => {
if (urlStr.startsWith('webcatalog://catalog/')) {
let appId;
try {
appId = urlStr.replace('webcatalog://catalog/', '');
} catch (err) {
// eslint-disable-next-line no-console
console.log(err);
}
if (appId) {
mainWindow.send('open-dialog-catalog-app-details', appId);
}
}
});
};

const handleArgv = (argv) => {
if (argv.length <= 1) return;
const urlStr = argv.find((a) => a.startsWith('webcatalog:'));
if (urlStr) {
handleOpenUrl(urlStr);
}
};

app.on('ready', () => {
// https://github.com/electron/electron/issues/23757
protocol.registerFileProtocol('file', (request, callback) => {
Expand Down Expand Up @@ -136,12 +94,6 @@ if (!gotTheLock) {
// trigger whenFullyReady
ipcMain.emit('truly-ready');

// handle protocols on Windows & Linux
// on macOS, use 'open-url' event
if (process.platform !== 'darwin') {
handleArgv(process.argv);
}

const win = mainWindow.get();
mainWindow.get().on('focus', () => {
win.send('log-focus');
Expand Down Expand Up @@ -193,23 +145,11 @@ if (!gotTheLock) {
.then(() => mainWindow.show());
});

app.on('open-url', (e, urlStr) => {
e.preventDefault();

handleOpenUrl(urlStr);
});

app.on('second-instance', (e, argv) => {
app.on('second-instance', () => {
const win = mainWindow.get();
if (win != null) {
if (win.isMinimized()) win.restore();
win.show();
}

// handle protocols on Windows & Linux
// on macOS, use 'open-url' event
if (process.platform !== 'darwin') {
handleArgv(argv);
}
});
}

0 comments on commit e50a15a

Please sign in to comment.