From a98792b05e134c07a365c7a7bed145ec8eed07b4 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 24 May 2017 15:52:08 +0100 Subject: [PATCH 1/5] auto-launch support, ux =checkbox in UserSettings[Electron] settings are sorta generic, probably reusable for proxy settings Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- electron_app/package.json | 1 + electron_app/src/electron-main.js | 39 +++++++++++++++++++++++++ src/vector/platform/ElectronPlatform.js | 2 ++ 3 files changed, 42 insertions(+) diff --git a/electron_app/package.json b/electron_app/package.json index df9c3bd261..8da35d8438 100644 --- a/electron_app/package.json +++ b/electron_app/package.json @@ -6,6 +6,7 @@ "description": "A feature-rich client for Matrix.org", "author": "Vector Creations Ltd.", "dependencies": { + "auto-launch": "^5.0.1", "electron-window-state": "^4.1.0" } } diff --git a/electron_app/src/electron-main.js b/electron_app/src/electron-main.js index ab844bd371..6b63d741b9 100644 --- a/electron_app/src/electron-main.js +++ b/electron_app/src/electron-main.js @@ -24,6 +24,7 @@ const check_squirrel_hooks = require('./squirrelhooks'); if (check_squirrel_hooks()) return; const electron = require('electron'); +const AutoLaunch = require('auto-launch'); const url = require('url'); const tray = require('./tray'); @@ -202,6 +203,44 @@ if (shouldQuit) { electron.app.quit() } + +const launcher = new AutoLaunch({ + name: vectorConfig.brand || 'Riot', + isHidden: 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); diff --git a/src/vector/platform/ElectronPlatform.js b/src/vector/platform/ElectronPlatform.js index 5710e66e4a..f52a5ddc93 100644 --- a/src/vector/platform/ElectronPlatform.js +++ b/src/vector/platform/ElectronPlatform.js @@ -138,6 +138,8 @@ export default class ElectronPlatform extends VectorBasePlatform { return null; } + isElectron(): boolean { return true; } + requestNotificationPermission(): Promise { return q('granted'); } From 9c25aab5095f8ec9272fa0a14fe4138ff26c2585 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 29 May 2017 22:12:36 +0100 Subject: [PATCH 2/5] Fix bad merge (3993 before 4021 broke things) Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- electron_app/src/electron-main.js | 41 ------------------------------- 1 file changed, 41 deletions(-) diff --git a/electron_app/src/electron-main.js b/electron_app/src/electron-main.js index 03c3d07dd1..d739a8d0c2 100644 --- a/electron_app/src/electron-main.js +++ b/electron_app/src/electron-main.js @@ -46,47 +46,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. From b27600adbe0f186a22a94e6c49e72a1f07ffbf10 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 30 May 2017 10:53:01 +0100 Subject: [PATCH 3/5] Improve for Mac - Tested on 10.10.5 --- electron_app/src/electron-main.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/electron_app/src/electron-main.js b/electron_app/src/electron-main.js index d739a8d0c2..92b59304ff 100644 --- a/electron_app/src/electron-main.js +++ b/electron_app/src/electron-main.js @@ -173,6 +173,9 @@ if (shouldQuit) { const launcher = new AutoLaunch({ name: vectorConfig.brand || 'Riot', isHidden: true, + mac: { + useLaunchAgent: true, + }, }); const settings = { From c54e2a30b6a9493a83ce3ce98d46f2aab745bab1 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 30 May 2017 12:33:32 +0100 Subject: [PATCH 4/5] explicitly hide because setApplicationMenu on Linux otherwise shows... https://github.com/electron/electron/issues/9621 Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- electron_app/src/electron-main.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/electron_app/src/electron-main.js b/electron_app/src/electron-main.js index d739a8d0c2..cef16f21bc 100644 --- a/electron_app/src/electron-main.js +++ b/electron_app/src/electron-main.js @@ -236,6 +236,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, From 0e96968c4eaed192bf197ee62a8597747c939797 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 30 May 2017 12:35:57 +0100 Subject: [PATCH 5/5] explicitly call install:electron in case electron-builder is silly (which has hit me once) Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 29b5beee07..951a9fc5fd 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "build:compile": "npm run reskindex && babel --source-maps -d lib src", "build:bundle": "cross-env NODE_ENV=production webpack -p --progress", "build:bundle:dev": "webpack --optimize-occurence-order --progress", - "build:electron": "npm run clean && npm run build && build -wml --ia32 --x64", + "build:electron": "npm run clean && npm run build && npm run install:electron && build -wml --ia32 --x64", "build": "npm run reskindex && npm run build:res && npm run build:bundle", "build:dev": "npm run reskindex && npm run build:res && npm run build:bundle:dev", "dist": "scripts/package.sh",