Co-authored-by: scott@signal.org
Co-authored-by: ken@signal.org
This commit is contained in:
Ken Powers 2019-05-16 15:32:11 -07:00 committed by Scott Nonnenberg
parent 8c8856785b
commit 29de50c12a
100 changed files with 7572 additions and 693 deletions

39
main.js
View file

@ -5,6 +5,7 @@ const url = require('url');
const os = require('os');
const fs = require('fs');
const crypto = require('crypto');
const qs = require('qs');
const _ = require('lodash');
const pify = require('pify');
@ -398,13 +399,16 @@ ipc.on('show-window', () => {
showWindow();
});
let updatesStarted = false;
ipc.on('ready-for-updates', async () => {
if (updatesStarted) {
return;
ipc.once('ready-for-updates', async () => {
// First, install requested sticker pack
if (process.argv.length > 1) {
const [incomingUrl] = process.argv;
if (incomingUrl.startsWith('sgnl://')) {
handleSgnlLink(incomingUrl);
}
}
updatesStarted = true;
// Second, start checking for app updates
try {
await updater.start(getMainWindow, locale.messages, logger);
} catch (error) {
@ -714,6 +718,13 @@ app.on('ready', async () => {
userDataPath,
attachments: orphanedAttachments,
});
const allStickers = await attachments.getAllStickers(userDataPath);
const orphanedStickers = await sql.removeKnownStickers(allStickers);
await attachments.deleteAllStickers({
userDataPath,
stickers: orphanedStickers,
});
}
await attachmentChannel.initialize({
@ -840,6 +851,12 @@ app.on('web-contents-created', (createEvent, contents) => {
});
});
app.setAsDefaultProtocolClient('sgnl');
app.on('open-url', (event, incomingUrl) => {
event.preventDefault();
handleSgnlLink(incomingUrl);
});
ipc.on('set-badge-count', (event, count) => {
app.setBadgeCount(count);
});
@ -1011,3 +1028,15 @@ function installSettingsSetter(name) {
}
});
}
function handleSgnlLink(incomingUrl) {
const { host: command, query } = url.parse(incomingUrl);
const args = qs.parse(query);
if (command === 'addstickers' && mainWindow && mainWindow.webContents) {
const { pack_id: packId, pack_key: packKeyHex } = args;
const packKey = Buffer.from(packKeyHex, 'hex').toString('base64');
mainWindow.webContents.send('add-sticker-pack', { packId, packKey });
} else {
console.error('Unhandled sgnl link');
}
}