From 008efd5f086373d7e161ecca9c2835e786cffc1e Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Fri, 16 Jul 2021 12:36:05 -0300 Subject: [PATCH] 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" } }