-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run the Desktop app in a sandbox #7907
Merged
Merged
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
Copyright 2016 Aviral Dasgupta | ||
Copyright 2016 OpenMarket Ltd | ||
Copyright 2017 Michael Telatynski <[email protected]> | ||
Copyright 2018 New Vector Ltd | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
|
@@ -23,8 +24,9 @@ const checkSquirrelHooks = require('./squirrelhooks'); | |
if (checkSquirrelHooks()) return; | ||
|
||
const argv = require('minimist')(process.argv); | ||
const {app, ipcMain, powerSaveBlocker, BrowserWindow, Menu} = require('electron'); | ||
const {app, ipcMain, powerSaveBlocker, BrowserWindow, Menu, autoUpdater} = require('electron'); | ||
const AutoLaunch = require('auto-launch'); | ||
const path = require('path'); | ||
|
||
const tray = require('./tray'); | ||
const vectorMenu = require('./vectormenu'); | ||
|
@@ -97,6 +99,61 @@ ipcMain.on('app_onAction', function(ev, payload) { | |
} | ||
}); | ||
|
||
autoUpdater.on('update-downloaded', (ev, releaseNotes, releaseName, releaseDate, updateURL) => { | ||
if (!mainWindow) return; | ||
// forward to renderer | ||
mainWindow.webContents.send('update-downloaded', { | ||
releaseNotes, | ||
releaseName, | ||
releaseDate, | ||
updateURL, | ||
}); | ||
}); | ||
|
||
ipcMain.on('ipcCall', function(ev, payload) { | ||
if (!mainWindow) return; | ||
|
||
const args = payload.args || []; | ||
let ret; | ||
|
||
switch (payload.name) { | ||
case 'getUpdateFeedUrl': | ||
ret = autoUpdater.getFeedURL(); | ||
break; | ||
case 'getAutoLaunchEnabled': | ||
ret = launcher.isEnabled; | ||
break; | ||
case 'setAutoLaunchEnabled': | ||
if (args[0]) { | ||
launcher.enable(); | ||
} else { | ||
launcher.disable(); | ||
} | ||
break; | ||
case 'getAppVersion': | ||
ret = app.getVersion(); | ||
break; | ||
case 'focusWindow': | ||
if (mainWindow.isMinimized()) { | ||
mainWindow.restore(); | ||
} else if (!mainWindow.isVisible()) { | ||
mainWindow.show(); | ||
} else { | ||
mainWindow.focus(); | ||
} | ||
default: | ||
mainWindow.webContents.send('ipcReply', { | ||
id: payload.id, | ||
error: new Error("Unknown IPC Call: "+payload.name), | ||
}); | ||
return; | ||
} | ||
|
||
mainWindow.webContents.send('ipcReply', { | ||
id: payload.id, | ||
reply: ret, | ||
}); | ||
}); | ||
|
||
app.commandLine.appendSwitch('--enable-usermedia-screen-capturing'); | ||
|
||
|
@@ -126,40 +183,6 @@ const launcher = new AutoLaunch({ | |
}, | ||
}); | ||
|
||
const settings = { | ||
'auto-launch': { | ||
get: launcher.isEnabled, | ||
set: function(bool) { | ||
if (bool) { | ||
return launcher.enable(); | ||
} else { | ||
return launcher.disable(); | ||
} | ||
}, | ||
}, | ||
}; | ||
|
||
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); | ||
} | ||
}); | ||
|
||
ipcMain.on('settings_set', function(ev, key, value) { | ||
console.log(key, value); | ||
if (settings[key] && settings[key].set) { | ||
settings[key].set(value); | ||
} | ||
}); | ||
|
||
app.on('ready', () => { | ||
if (argv['devtools']) { | ||
try { | ||
|
@@ -191,6 +214,7 @@ app.on('ready', () => { | |
defaultHeight: 768, | ||
}); | ||
|
||
const preloadScript = path.normalize(`${__dirname}/preload.js`); | ||
mainWindow = global.mainWindow = new BrowserWindow({ | ||
icon: iconPath, | ||
show: false, | ||
|
@@ -200,6 +224,18 @@ app.on('ready', () => { | |
y: mainWindowState.y, | ||
width: mainWindowState.width, | ||
height: mainWindowState.height, | ||
webPreferences: { | ||
preload: preloadScript, | ||
nodeIntegration: false, | ||
sandbox: true, | ||
enableRemoteModule: false, | ||
// We don't use this: it's useful for the preload script to | ||
// share a context with the main page so we can give select | ||
// objects to the main page. The sandbox option isolates the | ||
// main page from the background script. | ||
contextIsolation: false, | ||
webgl: false, | ||
}, | ||
}); | ||
mainWindow.loadURL(`file://${__dirname}/../../webapp/index.html`); | ||
Menu.setApplicationMenu(vectorMenu); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe remove this commented code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, good spot.