Merge branch 'develop' into t3chguy/electron_profiles

This commit is contained in:
Michael Telatynski 2017-06-01 00:01:53 +01:00 committed by GitHub
commit 5762323bd1
30 changed files with 391 additions and 130 deletions

View file

@ -23,6 +23,7 @@ if (checkSquirrelHooks()) return;
const argv = require('minimist')(process.argv);
const electron = require('electron');
const AutoLaunch = require('auto-launch');
const tray = require('./tray');
const vectorMenu = require('./vectormenu');
@ -50,47 +51,6 @@ const INITIAL_UPDATE_DELAY_MS = 30 * 1000;
let mainWindow = null;
let appQuitting = false;
function safeOpenURL(target) {
// openExternal passes the target to open/start/xdg-open,
// so put fairly stringent limits on what can be opened
// (for instance, open /bin/sh does indeed open a terminal
// with a shell, albeit with no arguments)
const parsedUrl = url.parse(target);
if (PERMITTED_URL_SCHEMES.indexOf(parsedUrl.protocol) > -1) {
// explicitly use the URL re-assembled by the url library,
// so we know the url parser has understood all the parts
// of the input string
const newTarget = url.format(parsedUrl);
electron.shell.openExternal(newTarget);
}
}
function onWindowOrNavigate(ev, target) {
// always prevent the default: if something goes wrong,
// we don't want to end up opening it in the electron
// app, as we could end up opening any sort of random
// url in a window that has node scripting access.
ev.preventDefault();
safeOpenURL(target);
}
function onLinkContextMenu(ev, params) {
const popupMenu = new electron.Menu();
popupMenu.append(new electron.MenuItem({
label: params.linkURL,
click() { safeOpenURL(params.linkURL); },
}));
popupMenu.append(new electron.MenuItem({
label: 'Copy Link Address',
click() { electron.clipboard.writeText(params.linkURL); },
}));
popupMenu.popup();
ev.preventDefault();
}
function installUpdate() {
// for some reason, quitAndInstall does not fire the
// before-quit event, so we need to set the flag here.
@ -214,6 +174,47 @@ if (shouldQuit) {
electron.app.exit();
}
const launcher = new AutoLaunch({
name: vectorConfig.brand || 'Riot',
isHidden: true,
mac: {
useLaunchAgent: true,
},
});
const settings = {
'auto-launch': {
get: launcher.isEnabled,
set: function(bool) {
if (bool) {
return launcher.enable();
} else {
return launcher.disable();
}
},
},
};
electron.ipcMain.on('settings_get', async function(ev) {
const data = {};
try {
await Promise.all(Object.keys(settings).map(async function (setting) {
data[setting] = await settings[setting].get();
}));
ev.sender.send('settings', data);
} catch(e) { console.error(e); }
});
electron.ipcMain.on('settings_set', function(ev, key, value) {
console.log(key, value);
if (settings[key] && settings[key].set) {
settings[key].set(value);
}
});
electron.app.on('ready', () => {
if (vectorConfig.update_base_url) {
console.log(`Starting auto update with base URL: ${vectorConfig.update_base_url}`);
@ -243,6 +244,10 @@ electron.app.on('ready', () => {
mainWindow.loadURL(`file://${__dirname}/../../webapp/index.html`);
electron.Menu.setApplicationMenu(vectorMenu);
// explicitly hide because setApplicationMenu on Linux otherwise shows...
// https://github.com/electron/electron/issues/9621
mainWindow.hide();
// Create trayIcon icon
tray.create(mainWindow, {
icon_path: iconPath,