Fix xdg-open and protocol handler for windows/linux
This commit is contained in:
parent
1c5ea63410
commit
7aad25b3e0
2 changed files with 28 additions and 9 deletions
25
main.js
25
main.js
|
@ -113,7 +113,7 @@ if (!process.mas) {
|
||||||
console.log('quitting; we are the second instance');
|
console.log('quitting; we are the second instance');
|
||||||
app.exit();
|
app.exit();
|
||||||
} else {
|
} else {
|
||||||
app.on('second-instance', () => {
|
app.on('second-instance', (e, argv) => {
|
||||||
// Someone tried to run a second instance, we should focus our window
|
// Someone tried to run a second instance, we should focus our window
|
||||||
if (mainWindow) {
|
if (mainWindow) {
|
||||||
if (mainWindow.isMinimized()) {
|
if (mainWindow.isMinimized()) {
|
||||||
|
@ -122,6 +122,12 @@ if (!process.mas) {
|
||||||
|
|
||||||
showWindow();
|
showWindow();
|
||||||
}
|
}
|
||||||
|
// Are they trying to open a sgnl link?
|
||||||
|
const incomingUrl = getIncomingUrl(argv);
|
||||||
|
if (incomingUrl) {
|
||||||
|
handleSgnlLink(incomingUrl);
|
||||||
|
}
|
||||||
|
// Handled
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -405,12 +411,10 @@ async function readyForUpdates() {
|
||||||
isReadyForUpdates = true;
|
isReadyForUpdates = true;
|
||||||
|
|
||||||
// First, install requested sticker pack
|
// First, install requested sticker pack
|
||||||
if (process.argv.length > 1) {
|
const incomingUrl = getIncomingUrl(process.argv);
|
||||||
const [incomingUrl] = process.argv;
|
if (incomingUrl) {
|
||||||
if (incomingUrl.startsWith('sgnl://')) {
|
|
||||||
handleSgnlLink(incomingUrl);
|
handleSgnlLink(incomingUrl);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Second, start checking for app updates
|
// Second, start checking for app updates
|
||||||
try {
|
try {
|
||||||
|
@ -969,9 +973,13 @@ app.on('web-contents-created', (createEvent, contents) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
app.setAsDefaultProtocolClient('sgnl');
|
app.setAsDefaultProtocolClient('sgnl');
|
||||||
app.on('open-url', (event, incomingUrl) => {
|
app.on('will-finish-launching', () => {
|
||||||
|
// open-url must be set from within will-finish-launching for macOS
|
||||||
|
// https://stackoverflow.com/a/43949291
|
||||||
|
app.on('open-url', (event, incomingUrl) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
handleSgnlLink(incomingUrl);
|
handleSgnlLink(incomingUrl);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
ipc.on('set-badge-count', (event, count) => {
|
ipc.on('set-badge-count', (event, count) => {
|
||||||
|
@ -1162,10 +1170,15 @@ function installSettingsSetter(name) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getIncomingUrl(argv) {
|
||||||
|
return argv.find(arg => arg.startsWith('sgnl://'));
|
||||||
|
}
|
||||||
|
|
||||||
function handleSgnlLink(incomingUrl) {
|
function handleSgnlLink(incomingUrl) {
|
||||||
const { host: command, query } = url.parse(incomingUrl);
|
const { host: command, query } = url.parse(incomingUrl);
|
||||||
const args = qs.parse(query);
|
const args = qs.parse(query);
|
||||||
if (command === 'addstickers' && mainWindow && mainWindow.webContents) {
|
if (command === 'addstickers' && mainWindow && mainWindow.webContents) {
|
||||||
|
console.log('Opening sticker pack from sgnl protocol link');
|
||||||
const { pack_id: packId, pack_key: packKeyHex } = args;
|
const { pack_id: packId, pack_key: packKeyHex } = args;
|
||||||
const packKey = Buffer.from(packKeyHex, 'hex').toString('base64');
|
const packKey = Buffer.from(packKeyHex, 'hex').toString('base64');
|
||||||
mainWindow.webContents.send('show-sticker-pack', { packId, packKey });
|
mainWindow.webContents.send('show-sticker-pack', { packId, packKey });
|
||||||
|
|
|
@ -314,6 +314,12 @@
|
||||||
"libxss1"
|
"libxss1"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"protocols": {
|
||||||
|
"name": "sgnl-url-scheme",
|
||||||
|
"schemes": [
|
||||||
|
"sgnl"
|
||||||
|
]
|
||||||
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"package.json",
|
"package.json",
|
||||||
"config/default.json",
|
"config/default.json",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue