@@ -22,6 +22,7 @@ const checkSquirrelHooks = require('./squirrelhooks');
2222if ( checkSquirrelHooks ( ) ) return ;
2323
2424const electron = require ( 'electron' ) ;
25+ const AutoLaunch = require ( 'auto-launch' ) ;
2526
2627const tray = require ( './tray' ) ;
2728const vectorMenu = require ( './vectormenu' ) ;
@@ -45,47 +46,6 @@ const INITIAL_UPDATE_DELAY_MS = 30 * 1000;
4546let mainWindow = null ;
4647let appQuitting = false ;
4748
48- function safeOpenURL ( target ) {
49- // openExternal passes the target to open/start/xdg-open,
50- // so put fairly stringent limits on what can be opened
51- // (for instance, open /bin/sh does indeed open a terminal
52- // with a shell, albeit with no arguments)
53- const parsedUrl = url . parse ( target ) ;
54- if ( PERMITTED_URL_SCHEMES . indexOf ( parsedUrl . protocol ) > - 1 ) {
55- // explicitly use the URL re-assembled by the url library,
56- // so we know the url parser has understood all the parts
57- // of the input string
58- const newTarget = url . format ( parsedUrl ) ;
59- electron . shell . openExternal ( newTarget ) ;
60- }
61- }
62-
63- function onWindowOrNavigate ( ev , target ) {
64- // always prevent the default: if something goes wrong,
65- // we don't want to end up opening it in the electron
66- // app, as we could end up opening any sort of random
67- // url in a window that has node scripting access.
68- ev . preventDefault ( ) ;
69- safeOpenURL ( target ) ;
70- }
71-
72- function onLinkContextMenu ( ev , params ) {
73- const popupMenu = new electron . Menu ( ) ;
74-
75- popupMenu . append ( new electron . MenuItem ( {
76- label : params . linkURL ,
77- click ( ) { safeOpenURL ( params . linkURL ) ; } ,
78- } ) ) ;
79-
80- popupMenu . append ( new electron . MenuItem ( {
81- label : 'Copy Link Address' ,
82- click ( ) { electron . clipboard . writeText ( params . linkURL ) ; } ,
83- } ) ) ;
84-
85- popupMenu . popup ( ) ;
86- ev . preventDefault ( ) ;
87- }
88-
8949function installUpdate ( ) {
9050 // for some reason, quitAndInstall does not fire the
9151 // before-quit event, so we need to set the flag here.
@@ -209,6 +169,47 @@ if (shouldQuit) {
209169 electron . app . quit ( ) ;
210170}
211171
172+
173+ const launcher = new AutoLaunch ( {
174+ name : vectorConfig . brand || 'Riot' ,
175+ isHidden : true ,
176+ mac : {
177+ useLaunchAgent : true ,
178+ } ,
179+ } ) ;
180+
181+ const settings = {
182+ 'auto-launch' : {
183+ get : launcher . isEnabled ,
184+ set : function ( bool ) {
185+ if ( bool ) {
186+ return launcher . enable ( ) ;
187+ } else {
188+ return launcher . disable ( ) ;
189+ }
190+ } ,
191+ } ,
192+ } ;
193+
194+ electron . ipcMain . on ( 'settings_get' , async function ( ev ) {
195+ const data = { } ;
196+
197+ try {
198+ await Promise . all ( Object . keys ( settings ) . map ( async function ( setting ) {
199+ data [ setting ] = await settings [ setting ] . get ( ) ;
200+ } ) ) ;
201+
202+ ev . sender . send ( 'settings' , data ) ;
203+ } catch ( e ) { console . error ( e ) ; }
204+ } ) ;
205+
206+ electron . ipcMain . on ( 'settings_set' , function ( ev , key , value ) {
207+ console . log ( key , value ) ;
208+ if ( settings [ key ] && settings [ key ] . set ) {
209+ settings [ key ] . set ( value ) ;
210+ }
211+ } ) ;
212+
212213electron . app . on ( 'ready' , ( ) => {
213214 if ( vectorConfig . update_base_url ) {
214215 console . log ( `Starting auto update with base URL: ${ vectorConfig . update_base_url } ` ) ;
@@ -238,6 +239,10 @@ electron.app.on('ready', () => {
238239 mainWindow . loadURL ( `file://${ __dirname } /../../webapp/index.html` ) ;
239240 electron . Menu . setApplicationMenu ( vectorMenu ) ;
240241
242+ // explicitly hide because setApplicationMenu on Linux otherwise shows...
243+ // https://github.com/electron/electron/issues/9621
244+ mainWindow . hide ( ) ;
245+
241246 // Create trayIcon icon
242247 tray . create ( mainWindow , {
243248 icon_path : iconPath ,
0 commit comments