From e18ff5e003e0bc35d1a42065c5990f38e89ba005 Mon Sep 17 00:00:00 2001 From: mhatvan Date: Sat, 21 Nov 2020 16:30:21 +0100 Subject: [PATCH 1/2] 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 --- app/ux/WebView.js | 116 +++++++++++++++++++------------- app/view/main/MainController.js | 53 ++++++++++----- electron/main.js | 40 ++++++----- package.json | 20 +++--- 4 files changed, 138 insertions(+), 91 deletions(-) diff --git a/app/ux/WebView.js b/app/ux/WebView.js index 3fbd5475..1ca336e9 100644 --- a/app/ux/WebView.js +++ b/app/ux/WebView.js @@ -288,10 +288,16 @@ Ext.define('Rambox.ux.WebView',{ webview.addEventListener("did-start-loading", function() { console.info('Start loading...', me.src); - webview.getWebContents().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 }); - }); + require("electron") + .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 }); + }); if ( !me.down('statusbar').closed || !me.down('statusbar').keep ) me.down('statusbar').show(); me.down('statusbar').showBusy(); @@ -504,7 +510,6 @@ Ext.define('Rambox.ux.WebView',{ require('electron').shell.openExternal(e.url); } return; - break; default: break; } @@ -551,52 +556,71 @@ Ext.define('Rambox.ux.WebView',{ js_inject += 'document.body.scrollTop=0;'; // Handles Certificate Errors - webview.getWebContents().on('certificate-error', function(event, url, error, certificate, callback) { - if ( me.record.get('trust') ) { - event.preventDefault(); - callback(true); - } else { - callback(false); - } + require("electron") + .remote.webContents.fromId(webview.getWebContentsId()) + .on("certificate-error", function ( + event, + url, + error, + certificate, + callback + ) { + if (me.record.get("trust")) { + event.preventDefault(); + callback(true); + } else { + callback(false); + } - me.down('statusbar').keep = true; - me.down('statusbar').show(); - me.down('statusbar').setStatus({ - text: ' Certification Warning' + me.down("statusbar").keep = true; + me.down("statusbar").show(); + me.down("statusbar").setStatus({ + text: + ' Certification Warning', + }); + me.down("statusbar").down("button").show(); }); - me.down('statusbar').down('button').show(); - }); if (!eventsOnDom) { - webview.getWebContents().on('before-input-event', (event, input) => { - if (input.type !== 'keyDown') return; - - var modifiers = []; - if ( input.shift ) modifiers.push('shift'); - if ( input.control ) modifiers.push('control'); - if ( input.alt ) modifiers.push('alt'); - if ( input.meta ) modifiers.push('meta'); - if ( input.isAutoRepeat ) modifiers.push('isAutoRepeat'); - - if ( input.key === 'Tab' && !(modifiers && modifiers.length) ) return; - - // Maps special keys to fire the correct event in Mac OS - if ( require('electron').remote.process.platform === 'darwin' ) { - var keys = []; - keys['ƒ'] = 'f'; // Search - keys[' '] = 'l'; // Lock - keys['∂'] = 'd'; // DND - - 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; + require("electron") + .remote.webContents.fromId(webview.getWebContentsId()) + .on("before-input-event", (event, input) => { + if (input.type !== "keyDown") return; + + var modifiers = []; + if (input.shift) modifiers.push("shift"); + if (input.control) modifiers.push("control"); + if (input.alt) modifiers.push("alt"); + if (input.meta) modifiers.push("meta"); + if (input.isAutoRepeat) modifiers.push("isAutoRepeat"); + + if (input.key === "Tab" && !(modifiers && modifiers.length)) return; + + // Maps special keys to fire the correct event in Mac OS + if (require("electron").remote.process.platform === "darwin") { + var keys = []; + keys["ƒ"] = "f"; // Search + keys[" "] = "l"; // Lock + keys["∂"] = "d"; // DND + + input.key = keys[input.key] ? keys[input.key] : input.key; + } - require('electron').remote.getCurrentWebContents().sendInputEvent({ - type: input.type, - keyCode: input.key, - modifiers: modifiers + 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({ + type: input.type, + keyCode: input.key, + modifiers: modifiers, + }); }); - }) eventsOnDom = true; Rambox.app.config.googleURLs.forEach((loginURL) => { if ( webview.getURL().indexOf(loginURL) > -1 ) webview.reload() }) diff --git a/app/view/main/MainController.js b/app/view/main/MainController.js index d3bd3d57..ecfd88bb 100644 --- a/app/view/main/MainController.js +++ b/app/view/main/MainController.js @@ -162,23 +162,42 @@ Ext.define('Rambox.view.main.MainController', { if ( config.default_service === rec.get('id') ) ipc.send('setConfig', Ext.apply(config, { default_service: 'ramboxTab' })); function clearData(webview, tab) { - webview.getWebContents().clearHistory(); - webview.getWebContents().session.flushStorageData(); - webview.getWebContents().session.clearCache().then(() => { - webview.getWebContents().session.clearStorageData().then(() => { - webview.getWebContents().session.cookies.flushStore().then(() => { - // Remove record from localStorage - Ext.getStore('Services').remove(rec); - // Close tab - tab.close(); - // Close waiting message - if ( total === actual ) { - Ext.Msg.hide(); - if ( Ext.isFunction(callback) ) callback(); - } - }).catch(err => { console.log(err) }) - }).catch(err => { console.log(err) }) - }).catch(err => { console.log(err) }) + const currentWebView = require("electron").remote.webContents.fromId( + webview.getWebContentsId() + ); + + currentWebView.clearHistory(); + currentWebView.session.flushStorageData(); + currentWebView.session + .clearCache() + .then(() => { + currentWebView.session + .clearStorageData() + .then(() => { + currentWebView.session.cookies + .flushStore() + .then(() => { + // Remove record from localStorage + Ext.getStore("Services").remove(rec); + // Close tab + tab.close(); + // Close waiting message + if (total === actual) { + Ext.Msg.hide(); + if (Ext.isFunction(callback)) callback(); + } + }) + .catch((err) => { + console.log(err); + }); + }) + .catch((err) => { + console.log(err); + }); + }) + .catch((err) => { + console.log(err); + }); } } diff --git a/electron/main.js b/electron/main.js index 74ad0c5d..3ec87862 100644 --- a/electron/main.js +++ b/electron/main.js @@ -85,24 +85,28 @@ let isQuitting = false; function createWindow () { // Create the browser window using the state information mainWindow = new BrowserWindow({ - title: 'Rambox' - ,icon: __dirname + '/../resources/Icon.' + (process.platform === 'linux' ? 'png' : 'ico') - ,backgroundColor: '#FFF' - ,x: config.get('x') - ,y: config.get('y') - ,width: config.get('width') - ,height: config.get('height') - ,alwaysOnTop: config.get('always_on_top') - ,autoHideMenuBar: config.get('hide_menu_bar') - ,skipTaskbar: config.get('window_display_behavior') === 'show_trayIcon' - ,show: !config.get('start_minimized') - ,acceptFirstMouse: true - ,webPreferences: { - plugins: true - ,partition: 'persist:rambox' - ,nodeIntegration: true - ,webviewTag: true - } + title: "Rambox", + icon: + __dirname + + "/../resources/Icon." + + (process.platform === "linux" ? "png" : "ico"), + backgroundColor: "#FFF", + x: config.get("x"), + y: config.get("y"), + width: config.get("width"), + height: config.get("height"), + alwaysOnTop: config.get("always_on_top"), + autoHideMenuBar: config.get("hide_menu_bar"), + skipTaskbar: config.get("window_display_behavior") === "show_trayIcon", + show: !config.get("start_minimized"), + acceptFirstMouse: true, + webPreferences: { + enableRemoteModule: true, + plugins: true, + partition: "persist:rambox", + nodeIntegration: true, + webviewTag: true, + }, }); // Check if user has defined a custom User-Agent diff --git a/package.json b/package.json index 5b9dd25b..79028a34 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "afterSign": "resources/installer/notarize.js", "asar": true, "electronDownload": { - "version": "7.2.4" + "version": "11.0.2" }, "mac": { "category": "public.app-category.productivity", @@ -200,10 +200,10 @@ "chai": "3.5.0", "crowdin": "1.0.0", "csvjson": "4.3.3", - "electron": "7.2.4", - "electron-builder": "21.2.0", - "electron-notarize": "0.2.1", - "electron-packager": "12.1.0", + "electron": "11.0.2", + "electron-builder": "22.9.1", + "electron-notarize": "1.0.0", + "electron-packager": "15.1.0", "mocha": "5.2.0", "spectron": "3.8.0" }, @@ -212,11 +212,11 @@ "auth0-js": "9.13.2", "auto-launch-patched": "5.0.2", "crypto": "1.0.1", - "electron-contextmenu-wrapper": "2.0.0", - "electron-is-dev": "0.3.0", - "electron-log": "2.2.17", - "electron-store": "6.0.0", - "electron-updater": "4.1.2", + "electron-contextmenu-wrapper": "4.0.1", + "electron-is-dev": "1.2.0", + "electron-log": "4.3.0", + "electron-store": "6.0.1", + "electron-updater": "4.3.5", "is-online": "8.2.0", "mime": "2.3.1", "mousetrap": "1.6.3", From 008efd5f086373d7e161ecca9c2835e786cffc1e Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Fri, 16 Jul 2021 12:36:05 -0300 Subject: [PATCH 2/2] Reviewed code and tested --- app/ux/WebView.js | 123 ++++++++++++++------------------ app/view/main/MainController.js | 45 ++++-------- electron/main.js | 41 +++++------ package.json | 2 +- 4 files changed, 88 insertions(+), 123 deletions(-) diff --git a/app/ux/WebView.js b/app/ux/WebView.js index 1ca336e9..db1b9449 100644 --- a/app/ux/WebView.js +++ b/app/ux/WebView.js @@ -288,16 +288,10 @@ Ext.define('Rambox.ux.WebView',{ webview.addEventListener("did-start-loading", function() { console.info('Start loading...', me.src); - require("electron") - .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 }); - }); + require('electron').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 }); + }); if ( !me.down('statusbar').closed || !me.down('statusbar').keep ) me.down('statusbar').show(); me.down('statusbar').showBusy(); @@ -556,71 +550,60 @@ Ext.define('Rambox.ux.WebView',{ js_inject += 'document.body.scrollTop=0;'; // Handles Certificate Errors - require("electron") - .remote.webContents.fromId(webview.getWebContentsId()) - .on("certificate-error", function ( - event, - url, - error, - certificate, - callback - ) { - if (me.record.get("trust")) { - event.preventDefault(); - callback(true); - } else { - callback(false); - } + require('electron').remote.webContents.fromId(webview.getWebContentsId()).on('certificate-error', function(event, url, error, certificate, callback) { + if (me.record.get('trust')) { + event.preventDefault(); + callback(true); + } else { + callback(false); + } - me.down("statusbar").keep = true; - me.down("statusbar").show(); - me.down("statusbar").setStatus({ - text: - ' Certification Warning', - }); - me.down("statusbar").down("button").show(); + me.down('statusbar').keep = true; + me.down('statusbar').show(); + me.down('statusbar').setStatus({ + text: ' Certification Warning', }); + me.down('statusbar').down('button').show(); + }); if (!eventsOnDom) { - require("electron") - .remote.webContents.fromId(webview.getWebContentsId()) - .on("before-input-event", (event, input) => { - if (input.type !== "keyDown") return; - - var modifiers = []; - if (input.shift) modifiers.push("shift"); - if (input.control) modifiers.push("control"); - if (input.alt) modifiers.push("alt"); - if (input.meta) modifiers.push("meta"); - if (input.isAutoRepeat) modifiers.push("isAutoRepeat"); - - if (input.key === "Tab" && !(modifiers && modifiers.length)) return; - - // Maps special keys to fire the correct event in Mac OS - if (require("electron").remote.process.platform === "darwin") { - var keys = []; - keys["ƒ"] = "f"; // Search - keys[" "] = "l"; // Lock - keys["∂"] = "d"; // DND - - input.key = keys[input.key] ? keys[input.key] : input.key; - } + require('electron').remote.webContents.fromId(webview.getWebContentsId()).on('before-input-event', (event, input) => { + if (input.type !== 'keyDown') return; + + var modifiers = []; + if (input.shift) modifiers.push('shift'); + if (input.control) modifiers.push('control'); + if (input.alt) modifiers.push('alt'); + if (input.meta) modifiers.push('meta'); + if (input.isAutoRepeat) modifiers.push('isAutoRepeat'); + + if (input.key === 'Tab' && !(modifiers && modifiers.length)) return; + + // Maps special keys to fire the correct event in Mac OS + if (require('electron').remote.process.platform === 'darwin') { + var keys = []; + keys['ƒ'] = 'f'; // Search + keys[' '] = 'l'; // Lock + keys['∂'] = 'd'; // DND + + 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; - - require("electron").remote.getCurrentWebContents().sendInputEvent({ - type: input.type, - keyCode: input.key, - modifiers: modifiers, - }); + 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({ + type: input.type, + keyCode: input.key, + modifiers: modifiers, }); + }); eventsOnDom = true; Rambox.app.config.googleURLs.forEach((loginURL) => { if ( webview.getURL().indexOf(loginURL) > -1 ) webview.reload() }) diff --git a/app/view/main/MainController.js b/app/view/main/MainController.js index ecfd88bb..c7a41106 100644 --- a/app/view/main/MainController.js +++ b/app/view/main/MainController.js @@ -168,36 +168,21 @@ Ext.define('Rambox.view.main.MainController', { currentWebView.clearHistory(); currentWebView.session.flushStorageData(); - currentWebView.session - .clearCache() - .then(() => { - currentWebView.session - .clearStorageData() - .then(() => { - currentWebView.session.cookies - .flushStore() - .then(() => { - // Remove record from localStorage - Ext.getStore("Services").remove(rec); - // Close tab - tab.close(); - // Close waiting message - if (total === actual) { - Ext.Msg.hide(); - if (Ext.isFunction(callback)) callback(); - } - }) - .catch((err) => { - console.log(err); - }); - }) - .catch((err) => { - console.log(err); - }); - }) - .catch((err) => { - console.log(err); - }); + currentWebView.session.clearCache().then(() => { + currentWebView.session.clearStorageData().then(() => { + currentWebView.session.cookies.flushStore().then(() => { + // Remove record from localStorage + Ext.getStore('Services').remove(rec); + // Close tab + tab.close(); + // Close waiting message + if ( total === actual ) { + Ext.Msg.hide(); + if ( Ext.isFunction(callback) ) callback(); + } + }).catch(err => { console.log(err) }) + }).catch(err => { console.log(err) }) + }).catch(err => { console.log(err) }) } } diff --git a/electron/main.js b/electron/main.js index 3ec87862..7a13dd20 100644 --- a/electron/main.js +++ b/electron/main.js @@ -85,28 +85,25 @@ let isQuitting = false; function createWindow () { // Create the browser window using the state information mainWindow = new BrowserWindow({ - title: "Rambox", - icon: - __dirname + - "/../resources/Icon." + - (process.platform === "linux" ? "png" : "ico"), - backgroundColor: "#FFF", - x: config.get("x"), - y: config.get("y"), - width: config.get("width"), - height: config.get("height"), - alwaysOnTop: config.get("always_on_top"), - autoHideMenuBar: config.get("hide_menu_bar"), - skipTaskbar: config.get("window_display_behavior") === "show_trayIcon", - show: !config.get("start_minimized"), - acceptFirstMouse: true, - webPreferences: { - enableRemoteModule: true, - plugins: true, - partition: "persist:rambox", - nodeIntegration: true, - webviewTag: true, - }, + title: 'Rambox' + ,icon: __dirname + '/../resources/Icon.' + (process.platform === 'linux' ? 'png' : 'ico') + ,backgroundColor: '#FFF' + ,x: config.get('x') + ,y: config.get('y') + ,width: config.get('width') + ,height: config.get('height') + ,alwaysOnTop: config.get('always_on_top') + ,autoHideMenuBar: config.get('hide_menu_bar') + ,skipTaskbar: config.get('window_display_behavior') === 'show_trayIcon' + ,show: !config.get('start_minimized') + ,acceptFirstMouse: true + ,webPreferences: { + enableRemoteModule: true + ,plugins: true + ,partition: 'persist:rambox' + ,nodeIntegration: true + ,webviewTag: true + } }); // Check if user has defined a custom User-Agent diff --git a/package.json b/package.json index 79028a34..4028642b 100644 --- a/package.json +++ b/package.json @@ -226,6 +226,6 @@ "tmp": "0.0.28" }, "volta": { - "node": "8.9.1" + "node": "14.16.1" } }