Browse Source

chore: Update Electron (#2871)

- update electron from 7.2.4 to 11.0.2
- upgrade electron-related dependencies to latest
- replace deprecated occurrences of webview.getWebContents() with require("electron").remote.webContents.fromId(webview.getWebContentsId())
- add enableRemoteModule: true to createWindow() in main.js until https://github.com/electron/electron/issues/21408 is resolved
pull/2897/head
mhatvan 4 years ago
parent
commit
e18ff5e003
No known key found for this signature in database
GPG Key ID: 6DD396B45D5556CE
  1. 76
      app/ux/WebView.js
  2. 37
      app/view/main/MainController.js
  3. 40
      electron/main.js
  4. 20
      package.json

76
app/ux/WebView.js

@ -288,8 +288,14 @@ Ext.define('Rambox.ux.WebView',{
webview.addEventListener("did-start-loading", function() { webview.addEventListener("did-start-loading", function() {
console.info('Start loading...', me.src); console.info('Start loading...', me.src);
webview.getWebContents().session.webRequest.onBeforeSendHeaders((details, callback) => { require("electron")
Rambox.app.config.googleURLs.forEach((loginURL) => { if ( details.url.indexOf(loginURL) > -1 ) details.requestHeaders['User-Agent'] = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0'}) .remote.webContents.fromId(webview.getWebContentsId())
.session.webRequest.onBeforeSendHeaders((details, callback) => {
Rambox.app.config.googleURLs.forEach((loginURL) => {
if (details.url.indexOf(loginURL) > -1)
details.requestHeaders["User-Agent"] =
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0";
});
callback({ cancel: false, requestHeaders: details.requestHeaders }); callback({ cancel: false, requestHeaders: details.requestHeaders });
}); });
@ -504,7 +510,6 @@ Ext.define('Rambox.ux.WebView',{
require('electron').shell.openExternal(e.url); require('electron').shell.openExternal(e.url);
} }
return; return;
break;
default: default:
break; break;
} }
@ -551,52 +556,71 @@ Ext.define('Rambox.ux.WebView',{
js_inject += 'document.body.scrollTop=0;'; js_inject += 'document.body.scrollTop=0;';
// Handles Certificate Errors // Handles Certificate Errors
webview.getWebContents().on('certificate-error', function(event, url, error, certificate, callback) { require("electron")
if ( me.record.get('trust') ) { .remote.webContents.fromId(webview.getWebContentsId())
.on("certificate-error", function (
event,
url,
error,
certificate,
callback
) {
if (me.record.get("trust")) {
event.preventDefault(); event.preventDefault();
callback(true); callback(true);
} else { } else {
callback(false); callback(false);
} }
me.down('statusbar').keep = true; me.down("statusbar").keep = true;
me.down('statusbar').show(); me.down("statusbar").show();
me.down('statusbar').setStatus({ me.down("statusbar").setStatus({
text: '<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Certification Warning' text:
'<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Certification Warning',
}); });
me.down('statusbar').down('button').show(); me.down("statusbar").down("button").show();
}); });
if (!eventsOnDom) { if (!eventsOnDom) {
webview.getWebContents().on('before-input-event', (event, input) => { require("electron")
if (input.type !== 'keyDown') return; .remote.webContents.fromId(webview.getWebContentsId())
.on("before-input-event", (event, input) => {
if (input.type !== "keyDown") return;
var modifiers = []; var modifiers = [];
if ( input.shift ) modifiers.push('shift'); if (input.shift) modifiers.push("shift");
if ( input.control ) modifiers.push('control'); if (input.control) modifiers.push("control");
if ( input.alt ) modifiers.push('alt'); if (input.alt) modifiers.push("alt");
if ( input.meta ) modifiers.push('meta'); if (input.meta) modifiers.push("meta");
if ( input.isAutoRepeat ) modifiers.push('isAutoRepeat'); if (input.isAutoRepeat) modifiers.push("isAutoRepeat");
if ( input.key === 'Tab' && !(modifiers && modifiers.length) ) return; if (input.key === "Tab" && !(modifiers && modifiers.length)) return;
// Maps special keys to fire the correct event in Mac OS // Maps special keys to fire the correct event in Mac OS
if ( require('electron').remote.process.platform === 'darwin' ) { if (require("electron").remote.process.platform === "darwin") {
var keys = []; var keys = [];
keys['ƒ'] = 'f'; // Search keys["ƒ"] = "f"; // Search
keys[' '] = 'l'; // Lock keys[" "] = "l"; // Lock
keys['∂'] = 'd'; // DND keys["∂"] = "d"; // DND
input.key = keys[input.key] ? keys[input.key] : input.key; input.key = keys[input.key] ? keys[input.key] : input.key;
} }
if ( input.key === 'F11' || input.key === 'a' || input.key === 'A' || input.key === 'F12' || input.key === 'q' || (input.key === 'F1' && modifiers.includes('control'))) return; if (
input.key === "F11" ||
input.key === "a" ||
input.key === "A" ||
input.key === "F12" ||
input.key === "q" ||
(input.key === "F1" && modifiers.includes("control"))
)
return;
require('electron').remote.getCurrentWebContents().sendInputEvent({ require("electron").remote.getCurrentWebContents().sendInputEvent({
type: input.type, type: input.type,
keyCode: input.key, keyCode: input.key,
modifiers: modifiers modifiers: modifiers,
});
}); });
})
eventsOnDom = true; eventsOnDom = true;
Rambox.app.config.googleURLs.forEach((loginURL) => { if ( webview.getURL().indexOf(loginURL) > -1 ) webview.reload() }) Rambox.app.config.googleURLs.forEach((loginURL) => { if ( webview.getURL().indexOf(loginURL) > -1 ) webview.reload() })

37
app/view/main/MainController.js

@ -162,13 +162,23 @@ Ext.define('Rambox.view.main.MainController', {
if ( config.default_service === rec.get('id') ) ipc.send('setConfig', Ext.apply(config, { default_service: 'ramboxTab' })); if ( config.default_service === rec.get('id') ) ipc.send('setConfig', Ext.apply(config, { default_service: 'ramboxTab' }));
function clearData(webview, tab) { function clearData(webview, tab) {
webview.getWebContents().clearHistory(); const currentWebView = require("electron").remote.webContents.fromId(
webview.getWebContents().session.flushStorageData(); webview.getWebContentsId()
webview.getWebContents().session.clearCache().then(() => { );
webview.getWebContents().session.clearStorageData().then(() => {
webview.getWebContents().session.cookies.flushStore().then(() => { currentWebView.clearHistory();
currentWebView.session.flushStorageData();
currentWebView.session
.clearCache()
.then(() => {
currentWebView.session
.clearStorageData()
.then(() => {
currentWebView.session.cookies
.flushStore()
.then(() => {
// Remove record from localStorage // Remove record from localStorage
Ext.getStore('Services').remove(rec); Ext.getStore("Services").remove(rec);
// Close tab // Close tab
tab.close(); tab.close();
// Close waiting message // Close waiting message
@ -176,9 +186,18 @@ Ext.define('Rambox.view.main.MainController', {
Ext.Msg.hide(); Ext.Msg.hide();
if (Ext.isFunction(callback)) callback(); if (Ext.isFunction(callback)) callback();
} }
}).catch(err => { console.log(err) }) })
}).catch(err => { console.log(err) }) .catch((err) => {
}).catch(err => { console.log(err) }) console.log(err);
});
})
.catch((err) => {
console.log(err);
});
})
.catch((err) => {
console.log(err);
});
} }
} }

40
electron/main.js

@ -85,24 +85,28 @@ let isQuitting = false;
function createWindow () { function createWindow () {
// Create the browser window using the state information // Create the browser window using the state information
mainWindow = new BrowserWindow({ mainWindow = new BrowserWindow({
title: 'Rambox' title: "Rambox",
,icon: __dirname + '/../resources/Icon.' + (process.platform === 'linux' ? 'png' : 'ico') icon:
,backgroundColor: '#FFF' __dirname +
,x: config.get('x') "/../resources/Icon." +
,y: config.get('y') (process.platform === "linux" ? "png" : "ico"),
,width: config.get('width') backgroundColor: "#FFF",
,height: config.get('height') x: config.get("x"),
,alwaysOnTop: config.get('always_on_top') y: config.get("y"),
,autoHideMenuBar: config.get('hide_menu_bar') width: config.get("width"),
,skipTaskbar: config.get('window_display_behavior') === 'show_trayIcon' height: config.get("height"),
,show: !config.get('start_minimized') alwaysOnTop: config.get("always_on_top"),
,acceptFirstMouse: true autoHideMenuBar: config.get("hide_menu_bar"),
,webPreferences: { skipTaskbar: config.get("window_display_behavior") === "show_trayIcon",
plugins: true show: !config.get("start_minimized"),
,partition: 'persist:rambox' acceptFirstMouse: true,
,nodeIntegration: true webPreferences: {
,webviewTag: true enableRemoteModule: true,
} plugins: true,
partition: "persist:rambox",
nodeIntegration: true,
webviewTag: true,
},
}); });
// Check if user has defined a custom User-Agent // Check if user has defined a custom User-Agent

20
package.json

@ -67,7 +67,7 @@
"afterSign": "resources/installer/notarize.js", "afterSign": "resources/installer/notarize.js",
"asar": true, "asar": true,
"electronDownload": { "electronDownload": {
"version": "7.2.4" "version": "11.0.2"
}, },
"mac": { "mac": {
"category": "public.app-category.productivity", "category": "public.app-category.productivity",
@ -200,10 +200,10 @@
"chai": "3.5.0", "chai": "3.5.0",
"crowdin": "1.0.0", "crowdin": "1.0.0",
"csvjson": "4.3.3", "csvjson": "4.3.3",
"electron": "7.2.4", "electron": "11.0.2",
"electron-builder": "21.2.0", "electron-builder": "22.9.1",
"electron-notarize": "0.2.1", "electron-notarize": "1.0.0",
"electron-packager": "12.1.0", "electron-packager": "15.1.0",
"mocha": "5.2.0", "mocha": "5.2.0",
"spectron": "3.8.0" "spectron": "3.8.0"
}, },
@ -212,11 +212,11 @@
"auth0-js": "9.13.2", "auth0-js": "9.13.2",
"auto-launch-patched": "5.0.2", "auto-launch-patched": "5.0.2",
"crypto": "1.0.1", "crypto": "1.0.1",
"electron-contextmenu-wrapper": "2.0.0", "electron-contextmenu-wrapper": "4.0.1",
"electron-is-dev": "0.3.0", "electron-is-dev": "1.2.0",
"electron-log": "2.2.17", "electron-log": "4.3.0",
"electron-store": "6.0.0", "electron-store": "6.0.1",
"electron-updater": "4.1.2", "electron-updater": "4.3.5",
"is-online": "8.2.0", "is-online": "8.2.0",
"mime": "2.3.1", "mime": "2.3.1",
"mousetrap": "1.6.3", "mousetrap": "1.6.3",

Loading…
Cancel
Save