From c91ef575e3ccdc8391335bb6c473dd4f286f29b5 Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Wed, 28 Jul 2021 18:25:50 -0300 Subject: [PATCH] Updated Electron and fixed some major bugs --- app/ux/Auth0.js | 3 +- app/ux/WebView.js | 147 +++------------------------------------------- electron/main.js | 81 +++++++++++++++++++++++++ package.json | 19 ++++-- 4 files changed, 105 insertions(+), 145 deletions(-) diff --git a/app/ux/Auth0.js b/app/ux/Auth0.js index 6d771b37..5751b61b 100644 --- a/app/ux/Auth0.js +++ b/app/ux/Auth0.js @@ -253,7 +253,8 @@ Ext.define('Rambox.ux.Auth0', { ,height: 600 ,maximizable: false ,minimizable: false - ,resizable: false + ,resizable: true + ,closable: true ,center: true ,autoHideMenuBar: true ,skipTaskbar: true diff --git a/app/ux/WebView.js b/app/ux/WebView.js index db1b9449..db92fbe9 100644 --- a/app/ux/WebView.js +++ b/app/ux/WebView.js @@ -35,9 +35,6 @@ Ext.define('Rambox.ux.WebView',{ } } - // Allow Custom sites with self certificates - //if ( me.record.get('trust') ) ipc.send('allowCertificate', me.src); - const prefConfig = ipc.sendSync('getConfig'); Ext.apply(me, { items: me.webViewConstructor() @@ -216,14 +213,13 @@ Ext.define('Rambox.ux.WebView',{ ,plugins: 'true' ,allowtransparency: 'on' ,autosize: 'on' - ,webpreferences: '' //,nativeWindowOpen=yes - //,disablewebsecurity: 'on' // Disabled because some services (Like Google Drive) dont work with this enabled + ,webpreferences: 'nativeWindowOpen=yes, spellcheck=no, contextIsolation=no' + ,allowpopups: 'on' + // ,disablewebsecurity: 'on' // Disabled because some services (Like Google Drive) dont work with this enabled ,useragent: me.getUserAgent() ,preload: './resources/js/rambox-service-api.js' } }]; - - if ( Ext.getStore('ServicesList').getById(this.record.get('type')) ? Ext.getStore('ServicesList').getById(me.record.get('type')).get('allow_popups') : false ) cfg[0].autoEl.allowpopups = 'on'; } return cfg; @@ -380,139 +376,12 @@ Ext.define('Rambox.ux.WebView',{ // Open links in default browser webview.addEventListener('new-window', function(e) { - switch ( me.type ) { - case 'skype': - // hack to fix multiple browser tabs on Skype link click, re #11 - if ( require('url').parse(me.down('statusbar #url').html).protocol !== null ) { - e.url = me.down('statusbar #url').html; - } else if ( e.url.indexOf('imgpsh_fullsize') >= 0 ) { - ipc.send('image:download', e.url, e.target.partition); - e.preventDefault(); - return; - } - break; - case 'hangouts': - e.preventDefault(); - if ( e.url.indexOf('plus.google.com/u/0/photos/albums') >= 0 ) { - ipc.send('image:popup', e.url, e.target.partition); - return; - } else if ( e.url.indexOf('/el/CONVERSATION/') >= 0 ) { - me.add({ - xtype: 'window' - ,title: 'Video Call' - ,width: '80%' - ,height: '80%' - ,maximizable: true - ,resizable: true - ,draggable: true - ,collapsible: true - ,items: { - xtype: 'component' - ,hideMode: 'offsets' - ,autoRender: true - ,autoShow: true - ,autoEl: { - tag: 'webview' - ,src: e.url - ,style: 'width:100%;height:100%;' - ,partition: me.getWebView().partition - ,useragent: me.getUserAgent() - } - } - }).show(); - return; - } - break; - case 'slack': - if ( e.url.indexOf('slack.com/call/') >= 0 ) { - me.add({ - xtype: 'window' - ,title: e.options.title - ,width: e.options.width - ,height: e.options.height - ,maximizable: true - ,resizable: true - ,draggable: true - ,collapsible: true - ,items: { - xtype: 'component' - ,hideMode: 'offsets' - ,autoRender: true - ,autoShow: true - ,autoEl: { - tag: 'webview' - ,src: e.url - ,style: 'width:100%;height:100%;' - ,partition: me.getWebView().partition - ,useragent: me.getUserAgent() - } - } - }).show(); - e.preventDefault(); - return; - } - break; - case 'icloud': - if ( e.url.indexOf('index.html#compose') >= 0 ) { - me.add({ - xtype: 'window' - ,title: 'iCloud - Compose' - ,width: 700 - ,height: 500 - ,maximizable: true - ,resizable: true - ,draggable: true - ,collapsible: true - ,items: { - xtype: 'component' - ,itemId: 'webview' - ,hideMode: 'offsets' - ,autoRender: true - ,autoShow: true - ,autoEl: { - tag: 'webview' - ,src: e.url - ,style: 'width:100%;height:100%;' - ,partition: me.getWebView().partition - ,useragent: me.getUserAgent() - ,preload: './resources/js/rambox-modal-api.js' - } - } - ,listeners: { - show: function(win) { - const webview = win.down('#webview').el.dom; - webview.addEventListener('ipc-message', function(event) { - var channel = event.channel; - switch (channel) { - case 'close': - win.close(); - break; - default: - break; - } - }); - } - } - }).show(); - e.preventDefault(); - return; - } - break; - case 'flowdock': - if ( e.disposition === 'new-window' ) { - e.preventDefault(); - require('electron').shell.openExternal(e.url); - } - return; - default: - break; - } - + e.preventDefault(); const protocol = require('url').parse(e.url).protocol; - if (protocol === 'http:' || protocol === 'https:' || protocol === 'mailto:') { - e.preventDefault(); - require('electron').shell.openExternal(e.url); - } + // Block some Deep links to prevent that open its app (Ex: Slack) + if ( ['slack:'].includes(protocol) ) return; + // Allow Deep links + if ( !['http:', 'https:', 'about:'].includes(protocol) ) return require('electron').shell.openExternal(e.url); }); webview.addEventListener('will-navigate', function(e, url) { diff --git a/electron/main.js b/electron/main.js index de77e69c..ce22e31c 100644 --- a/electron/main.js +++ b/electron/main.js @@ -107,6 +107,8 @@ function createWindow () { ,partition: 'persist:rambox' ,nodeIntegration: true ,webviewTag: true + ,contextIsolation: false + ,spellcheck: false } }); @@ -386,6 +388,85 @@ app.on('second-instance', (event, commandLine, workingDirectory) => { } }); +// ALLOWED URLS POPUPS +let allowPopUp = [ + 'feedly.com/v3/auth/', + 'identity.linuxfoundation.org/cas/login', + 'auth.missiveapp.com', + 'accounts.google.com/AccountChooser', + 'facebook.com/v3.1/dialog/oauth?', + 'accounts.google.com/o/oauth2', + 'app.slack.com/files/import/gdrive', + 'spikenow.com/s/account', + 'app.mixmax.com/_oauth/google', + 'officeapps.live.com', + 'dropbox.com/profile_services/start_auth_flow', + 'facebook.com/v3.2/dialog/oauth?', + 'notion.so/googlepopupredirect', + 'zoom.us/office365', + 'figma.com/start_google_sso', + 'mail.google.com/mail', + 'app.slack.com/free-willy/', + 'messenger.com/videocall', + 'api.moo.do', + 'manychat.com/fb?popup', + '=?print=true' // esta ultima checkea como anda imprimir un pedf desde gmail, si no va bie sacala +]; + +app.on('web-contents-created', (webContentsCreatedEvent, contents) => { + if (contents.getType() !== 'webview') return; + // Block some Deep links to prevent that open its app (Ex: Slack) + contents.on('will-navigate', (event, url) => url.substring(0, 8) === 'slack://' && event.preventDefault()); + // New Window handler + contents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures, referrer, postBody) => { + // If the url is about:blank we allow the window and handle it in 'did-create-window' + if (['about:blank', 'about:blank#blocked'].includes(url)) { + event.preventDefault(); + Object.assign(options, { show: false }); + const win = new BrowserWindow(options); + win.center(); + let once = false; + win.webContents.on('will-navigate', (e, nextURL) => { + if (once) return; + if (['about:blank', 'about:blank#blocked'].includes(nextURL)) return; + once = true; + let allow = false; + allowPopUp.forEach(url => nextURL.indexOf(url) > -1 && (allow = true)); + // If the url is in aboutBlankOnlyWindow we handle this as a popup window + if (allow) return win.show(); + shell.openExternal(nextURL); + win.close() + }) + event.newGuest = win; + return; + } + // We check if url is in the allowPopUpLoginURLs or allowForegroundTabURLs in Firebase to open a as a popup, + // if it is not we send this to the app + let allow = false; + allowPopUp.forEach(allowed => url.indexOf(allowed) > -1 && (allow = true)); + if (allow) return; + shell.openExternal(url); + event.preventDefault(); + }); + contents.on('did-create-window', (win, details) => { + // Here we center the new window. + win.center(); + // The following code is for handling the about:blank cases only. + if (!['about:blank', 'about:blank#blocked'].includes(details.url)) return; + let once = false; + win.webContents.on('will-navigate', (e, nextURL) => { + if (once) return; + if (['about:blank', 'about:blank#blocked'].includes(nextURL)) return; + once = true; + let allow = false; + allowPopUp.forEach(url => nextURL.indexOf(url) > -1 && (allow = true)); + // If the url is in aboutBlankOnlyWindow we handle this as a popup window + if (allow) return win.show(); + shell.openExternal(url); + win.close(); + }); + }); +}); // Code for downloading images as temporal files // Credit: Ghetto Skype (https://github.com/stanfieldr/ghetto-skype) diff --git a/package.json b/package.json index 4028642b..41cd29a8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "Rambox", "productName": "Rambox", - "version": "0.7.7", + "version": "0.7.8", "description": "Free and Open Source messaging and emailing app that combines common web applications into one.", "main": "electron/main.js", "repository": { @@ -66,8 +66,9 @@ "appId": "com.grupovrs.ramboxce", "afterSign": "resources/installer/notarize.js", "asar": true, + "electronVersion": "11.4.10", "electronDownload": { - "version": "11.0.2" + "version": "11.4.10" }, "mac": { "category": "public.app-category.productivity", @@ -127,10 +128,14 @@ "camera", "audio-record", "audio-playback", - "removable-media" + "removable-media", + "raw-usb", + "u2f-devices", + "cups-control" ] }, "linux": { + "icon": "resources/installer/icons", "category": "Network", "desktop": { "Terminal": "false", @@ -138,6 +143,9 @@ "Categories": "GTK;GNOME;Network;Email;Chat;InstantMessaging;" }, "artifactName": "Rambox-${version}-linux-${arch}.${ext}", + "executableArgs": [ + "--no-sandbox" + ], "target": [ { "target": "snap", @@ -200,7 +208,7 @@ "chai": "3.5.0", "crowdin": "1.0.0", "csvjson": "4.3.3", - "electron": "11.0.2", + "electron": "11.4.10", "electron-builder": "22.9.1", "electron-notarize": "1.0.0", "electron-packager": "15.1.0", @@ -212,7 +220,8 @@ "auth0-js": "9.13.2", "auto-launch-patched": "5.0.2", "crypto": "1.0.1", - "electron-contextmenu-wrapper": "4.0.1", + "diskusage": "1.1.3", + "electron-contextmenu-wrapper": "git+https://github.com/ramboxapp/electron-contextmenu-wrapper.git", "electron-is-dev": "1.2.0", "electron-log": "4.3.0", "electron-store": "6.0.1",