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",