Browse Source

Reviewed code and tested

pull/2897/head
Ramiro Saenz 4 years ago
parent
commit
008efd5f08
  1. 73
      app/ux/WebView.js
  2. 29
      app/view/main/MainController.js
  3. 41
      electron/main.js
  4. 2
      package.json

73
app/ux/WebView.js

@ -288,14 +288,8 @@ 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);
require("electron") require('electron').remote.webContents.fromId(webview.getWebContentsId()).session.webRequest.onBeforeSendHeaders((details, callback) => {
.remote.webContents.fromId(webview.getWebContentsId()) 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'});
.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 });
}); });
@ -556,66 +550,55 @@ Ext.define('Rambox.ux.WebView',{
js_inject += 'document.body.scrollTop=0;'; js_inject += 'document.body.scrollTop=0;';
// Handles Certificate Errors // Handles Certificate Errors
require("electron") require('electron').remote.webContents.fromId(webview.getWebContentsId()).on('certificate-error', function(event, url, error, certificate, callback) {
.remote.webContents.fromId(webview.getWebContentsId()) if (me.record.get('trust')) {
.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: text: '<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Certification Warning',
'<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) {
require("electron") require('electron').remote.webContents.fromId(webview.getWebContentsId()).on('before-input-event', (event, input) => {
.remote.webContents.fromId(webview.getWebContentsId()) if (input.type !== 'keyDown') return;
.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 ( if (
input.key === "F11" || input.key === 'F11' ||
input.key === "a" || input.key === 'a' ||
input.key === "A" || input.key === 'A' ||
input.key === "F12" || input.key === 'F12' ||
input.key === "q" || input.key === 'q' ||
(input.key === "F1" && modifiers.includes("control")) (input.key === 'F1' && modifiers.includes('control'))
) )
return; 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,

29
app/view/main/MainController.js

@ -168,17 +168,11 @@ Ext.define('Rambox.view.main.MainController', {
currentWebView.clearHistory(); currentWebView.clearHistory();
currentWebView.session.flushStorageData(); currentWebView.session.flushStorageData();
currentWebView.session currentWebView.session.clearCache().then(() => {
.clearCache() currentWebView.session.clearStorageData().then(() => {
.then(() => { currentWebView.session.cookies.flushStore().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
@ -186,18 +180,9 @@ 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) => { }).catch(err => { console.log(err) })
console.log(err); }).catch(err => { console.log(err) })
});
})
.catch((err) => {
console.log(err);
});
})
.catch((err) => {
console.log(err);
});
} }
} }

41
electron/main.js

@ -85,28 +85,25 @@ 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: ,icon: __dirname + '/../resources/Icon.' + (process.platform === 'linux' ? 'png' : 'ico')
__dirname + ,backgroundColor: '#FFF'
"/../resources/Icon." + ,x: config.get('x')
(process.platform === "linux" ? "png" : "ico"), ,y: config.get('y')
backgroundColor: "#FFF", ,width: config.get('width')
x: config.get("x"), ,height: config.get('height')
y: config.get("y"), ,alwaysOnTop: config.get('always_on_top')
width: config.get("width"), ,autoHideMenuBar: config.get('hide_menu_bar')
height: config.get("height"), ,skipTaskbar: config.get('window_display_behavior') === 'show_trayIcon'
alwaysOnTop: config.get("always_on_top"), ,show: !config.get('start_minimized')
autoHideMenuBar: config.get("hide_menu_bar"), ,acceptFirstMouse: true
skipTaskbar: config.get("window_display_behavior") === "show_trayIcon", ,webPreferences: {
show: !config.get("start_minimized"), enableRemoteModule: true
acceptFirstMouse: true, ,plugins: true
webPreferences: { ,partition: 'persist:rambox'
enableRemoteModule: true, ,nodeIntegration: true
plugins: true, ,webviewTag: 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

2
package.json

@ -226,6 +226,6 @@
"tmp": "0.0.28" "tmp": "0.0.28"
}, },
"volta": { "volta": {
"node": "8.9.1" "node": "14.16.1"
} }
} }

Loading…
Cancel
Save