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

Remove webcatalog: protocol support #1621

Merged
merged 1 commit into from
Jan 27, 2022
Merged
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
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);
}
});
}