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() {
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";
});
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 });
});
@ -556,66 +550,55 @@ 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")) {
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:
'<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Certification Warning',
me.down('statusbar').keep = true;
me.down('statusbar').show();
me.down('statusbar').setStatus({
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) {
require("electron")
.remote.webContents.fromId(webview.getWebContentsId())
.on("before-input-event", (event, input) => {
if (input.type !== "keyDown") 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.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;
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") {
if (require('electron').remote.process.platform === 'darwin') {
var keys = [];
keys["ƒ"] = "f"; // Search
keys[" "] = "l"; // Lock
keys["∂"] = "d"; // DND
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"))
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,
keyCode: input.key,
modifiers: modifiers,

29
app/view/main/MainController.js

@ -168,17 +168,11 @@ Ext.define('Rambox.view.main.MainController', {
currentWebView.clearHistory();
currentWebView.session.flushStorageData();
currentWebView.session
.clearCache()
.then(() => {
currentWebView.session
.clearStorageData()
.then(() => {
currentWebView.session.cookies
.flushStore()
.then(() => {
currentWebView.session.clearCache().then(() => {
currentWebView.session.clearStorageData().then(() => {
currentWebView.session.cookies.flushStore().then(() => {
// Remove record from localStorage
Ext.getStore("Services").remove(rec);
Ext.getStore('Services').remove(rec);
// Close tab
tab.close();
// Close waiting message
@ -186,18 +180,9 @@ Ext.define('Rambox.view.main.MainController', {
Ext.Msg.hide();
if ( Ext.isFunction(callback) ) callback();
}
})
.catch((err) => {
console.log(err);
});
})
.catch((err) => {
console.log(err);
});
})
.catch((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 () {
// 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

2
package.json

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

Loading…
Cancel
Save