diff --git a/electron_app/package.json b/electron_app/package.json index df9c3bd2..8da35d84 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 ab844bd3..6b63d741 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 5710e66e..f52a5ddc 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'); }