From 9dee2cf4f01b81f3b897d374a6ad5b20284f5f91 Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Tue, 23 May 2017 15:51:09 -0300 Subject: [PATCH 1/8] Enable Cookies --- app.js | 3 +++ app/Application.js | 5 +++++ app/package.json | 3 ++- app/ux/Auth0.js | 6 ++++++ package.json | 3 ++- 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 7cf1c650..0013fec8 100644 --- a/app.js +++ b/app.js @@ -1,4 +1,7 @@ var auth0, lock; // Auth0 vars +// Enable Cookies +var ElectronCookies = require('@exponent/electron-cookies'); +ElectronCookies.enable({ origin: 'http://rambox.pro' }); // Sencha App Ext.setGlyphFontFamily('FontAwesome'); diff --git a/app/Application.js b/app/Application.js index 46a616d3..23253f48 100644 --- a/app/Application.js +++ b/app/Application.js @@ -7,6 +7,7 @@ Ext.define('Rambox.Application', { 'Rambox.ux.Auth0' ,'Rambox.util.MD5' ,'Ext.window.Toast' + ,'Ext.util.Cookies' ] ,stores: [ @@ -33,6 +34,10 @@ Ext.define('Rambox.Application', { // Initialize Auth0 Rambox.ux.Auth0.init(); + // Set cookies to help Tooltip.io messages segmentation + Ext.util.Cookies.set('version', require('electron').remote.app.getVersion()); + if ( Ext.util.Cookies.get('auth0') === null ) Ext.util.Cookies.set('auth0', false); + // Check for updates if ( require('electron').remote.process.argv.indexOf('--without-update') === -1 && process.platform !== 'win32' ) Rambox.app.checkUpdate(true); diff --git a/app/package.json b/app/package.json index 1a7ba831..2b489d15 100644 --- a/app/package.json +++ b/app/package.json @@ -33,6 +33,7 @@ "tmp": "0.0.28", "mime": "^1.3.4", "electron-is-dev": "^0.1.1", - "electron-config": "0.2.1" + "electron-config": "0.2.1", + "@exponent/electron-cookies": "2.0.0" } } diff --git a/app/ux/Auth0.js b/app/ux/Auth0.js index 245bc3c4..f9315246 100644 --- a/app/ux/Auth0.js +++ b/app/ux/Auth0.js @@ -51,6 +51,9 @@ Ext.define('Rambox.ux.Auth0', { // Google Analytics Event ga_storage._trackEvent('Users', 'loggedIn'); + // Set cookies to help Tooltip.io messages segmentation + Ext.util.Cookies.set('auth0', true); + // User is logged in // Save the profile and JWT. localStorage.setItem('profile', JSON.stringify(profile)); @@ -225,5 +228,8 @@ Ext.define('Rambox.ux.Auth0', { localStorage.removeItem('profile'); localStorage.removeItem('id_token'); localStorage.removeItem('refresh_token'); + + // Set cookies to help Tooltip.io messages segmentation + Ext.util.Cookies.set('auth0', false); } }); diff --git a/package.json b/package.json index d6a8fee9..6cce2aaf 100644 --- a/package.json +++ b/package.json @@ -104,6 +104,7 @@ "tmp": "0.0.28", "mime": "^1.3.4", "electron-is-dev": "^0.1.1", - "electron-config": "0.2.1" + "electron-config": "0.2.1", + "@exponent/electron-cookies": "2.0.0" } } From 8d184981a2e361709349e840692ab1c6cdcfb76a Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Tue, 23 May 2017 17:33:22 -0300 Subject: [PATCH 2/8] Changed Gmail unread code --- app/store/ServicesList.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/store/ServicesList.js b/app/store/ServicesList.js index faecb169..4d538721 100644 --- a/app/store/ServicesList.js +++ b/app/store/ServicesList.js @@ -116,8 +116,9 @@ Ext.define('Rambox.store.ServicesList', { ,url: 'https://mail.google.com/mail/' ,type: 'email' ,allow_popups: true - ,js_unread: 'Object.defineProperty(document,"title",{configurable:!0,set:function(a){var b=document.getElementsByClassName("aim")[0];t=0,b.textContent.indexOf("(")!=-1&&(t=parseInt(b.textContent.replace(/[^0-9]/g,""))),document.getElementsByTagName("title")[0].innerHTML="("+t+") Gmail"},get:function(){return document.getElementsByTagName("title")[0].innerHTML}});' + ,js_unread: 'function checkUnread(){var a=document.getElementsByClassName("aim")[0];updateBadge(-1!=a.textContent.indexOf("(")&&(t=parseInt(a.textContent.replace(/[^0-9]/g,""))))}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);' ,note: 'To enable desktop notifications, you have to go to Settings inside Gmail. Read more...' + ,dont_update_unread_from_title: true }, { id: 'inbox' From 2342c2c95dc593397b7dbce5843caf6f97c041cb Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Tue, 23 May 2017 17:34:03 -0300 Subject: [PATCH 3/8] Improved JS code injection Because causes memory leaks in some services. --- app/ux/WebView.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/ux/WebView.js b/app/ux/WebView.js index 9b37e37c..da8c6f8b 100644 --- a/app/ux/WebView.js +++ b/app/ux/WebView.js @@ -347,6 +347,7 @@ Ext.define('Rambox.ux.WebView',{ // Mute Webview if ( me.record.get('muted') || localStorage.getItem('locked') || JSON.parse(localStorage.getItem('dontDisturb')) ) me.setAudioMuted(true, true); + var js_inject = ''; // Injected code to detect new messages if ( me.record ) { var js_unread = Ext.getStore('ServicesList').getById(me.record.get('type')).get('js_unread'); @@ -355,7 +356,7 @@ Ext.define('Rambox.ux.WebView',{ console.groupCollapsed(me.record.get('type').toUpperCase() + ' - JS Injected to Detect New Messages'); console.info(me.type); console.log(js_unread); - webview.executeJavaScript(js_unread); + js_inject += js_unread; } } @@ -363,13 +364,13 @@ Ext.define('Rambox.ux.WebView',{ if ( Ext.getStore('ServicesList').getById(me.record.get('type')).get('titleBlink') ) { var js_preventBlink = 'var originalTitle=document.title;Object.defineProperty(document,"title",{configurable:!0,set:function(a){null===a.match(new RegExp("[(]([0-9•]+)[)][ ](.*)","g"))&&a!==originalTitle||(document.getElementsByTagName("title")[0].innerHTML=a)},get:function(){return document.getElementsByTagName("title")[0].innerHTML}});'; console.log(js_preventBlink); - webview.executeJavaScript(js_preventBlink); + js_inject += js_preventBlink; } console.groupEnd(); // Scroll always to top (bug) - webview.executeJavaScript('document.body.scrollTop=0;'); + js_inject += 'document.body.scrollTop=0;'; // Handles Certificate Errors webview.getWebContents().on('certificate-error', function(event, url, error, certificate, callback) { @@ -387,6 +388,8 @@ Ext.define('Rambox.ux.WebView',{ }); me.down('statusbar').down('button').show(); }); + + webview.executeJavaScript(js_inject); }); webview.addEventListener('ipc-message', function(event) { From ac943c356e58abd573cbc189b6b82103cd20aba3 Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Wed, 24 May 2017 18:47:16 -0300 Subject: [PATCH 4/8] Added Ext JS localization support :flags: --- app.json | 1 + app/Application.js | 3 +++ 2 files changed, 4 insertions(+) diff --git a/app.json b/app.json index abef42a1..8f2fc7b2 100644 --- a/app.json +++ b/app.json @@ -40,6 +40,7 @@ * ] */ "requires": [ + "ext-locale" ], /** diff --git a/app/Application.js b/app/Application.js index 23253f48..2b30c232 100644 --- a/app/Application.js +++ b/app/Application.js @@ -31,6 +31,9 @@ Ext.define('Rambox.Application', { ga_storage._trackPageview('/index.html', 'main'); ga_storage._trackEvent('Versions', require('electron').remote.app.getVersion()); + // Load language for Ext JS library + Ext.Loader.loadScript({url: Ext.util.Format.format("ext/packages/ext-locale/build/ext-locale-{0}.js", localStorage.getItem('locale-auth0') || 'en')}); + // Initialize Auth0 Rambox.ux.Auth0.init(); From d4038a3e8deed2a8f6d8614c30ed9c884e375003 Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Wed, 24 May 2017 21:04:26 -0300 Subject: [PATCH 5/8] Added wizard to fix sync bug --- app/Application.js | 70 ++++++++++++++++++++++++++++++++++++++++++++++ app/ux/Auth0.js | 10 +++++-- 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/app/Application.js b/app/Application.js index 2b30c232..2edde25f 100644 --- a/app/Application.js +++ b/app/Application.js @@ -204,6 +204,76 @@ Ext.define('Rambox.Application', { Ext.cq1('app-main').getController().showLockWindow(); } + // Synchronization problem in version 0.5.3 steps to fix it + if ( localStorage.getItem('id_token') && localStorage.getItem('refresh_token') === null ) { + var win = Ext.create('Ext.window.Window', { + title: 'Backup your services' + ,autoShow: true + ,modal: true + ,closable: false + ,resizable: false + ,bodyPadding: '0 15 15 15' + ,width: 500 + ,layout: 'card' + ,items: [ + { + xtype: 'container' + ,html: '

Synchronization problem fixed!

In previous version, we had a bug that backing up your services throw an error. Now is fixed, but you will need to follow two simple steps to make it work.

If you decide not to do it now, you can cancel but it will ask you again next time you open Rambox until you do it.' + } + ,{ + xtype: 'container' + ,html: '

Login again

Just click the "Sign in" button at the bottom-right of this window to sign in again with the same account you used before.' + } + ,{ + xtype: 'container' + ,html: '

Backup

To finish, click the "Sync!" button to backup your current services and that\'s all!' + } + ] + ,buttons: [ + { + text: locale['button[1]'] + ,ui: 'decline' + ,handler: function() { + win.close(); + } + } + ,'->' + ,{ + text: 'Start' + ,handler: function(btn) { + btn.hide(); + btn.nextSibling('#signin').show(); + win.getLayout().setActiveItem(1); + } + } + ,{ + text: 'Sign in' + ,itemId: 'signin' + ,hidden: true + ,handler: function(btn) { + Rambox.ux.Auth0.backupCurrent = true; + Rambox.ux.Auth0.login(); + Ext.defer(Rambox.ux.Auth0.logout, 1000); + btn.hide(); + btn.nextSibling('#sync').show(); + win.getLayout().setActiveItem(2); + } + } + ,{ + text: 'Sync!' + ,itemId: 'sync' + ,hidden: true + ,handler: function() { + Rambox.ux.Auth0.backupConfiguration(function() { + win.close(); + Rambox.ux.Auth0.backupCurrent = false; + }); + } + } + ] + }); + } + // Remove spinner Ext.get('spinner').destroy(); } diff --git a/app/ux/Auth0.js b/app/ux/Auth0.js index f9315246..12b39bf2 100644 --- a/app/ux/Auth0.js +++ b/app/ux/Auth0.js @@ -4,6 +4,7 @@ Ext.define('Rambox.ux.Auth0', { // private ,lock: null ,auth0: null + ,backupCurrent: false ,init: function() { var me = this; @@ -60,7 +61,7 @@ Ext.define('Rambox.ux.Auth0', { localStorage.setItem('id_token', authResult.idToken); localStorage.setItem('refresh_token', authResult.refreshToken); - if ( !Ext.isEmpty(profile.user_metadata) && !Ext.isEmpty(profile.user_metadata.services) ) { + if ( !Ext.isEmpty(profile.user_metadata) && !Ext.isEmpty(profile.user_metadata.services) && !me.backupCurrent ) { Ext.each(profile.user_metadata.services, function(s) { var service = Ext.create('Rambox.model.Service', s); service.save(); @@ -77,7 +78,7 @@ Ext.define('Rambox.ux.Auth0', { }); } - ,backupConfiguration: function() { + ,backupConfiguration: function(callback) { var me = this; Ext.Msg.wait('Saving backup...', 'Please wait...'); @@ -113,6 +114,8 @@ Ext.define('Rambox.ux.Auth0', { ,align: 't' ,closable: false }); + + if ( Ext.isFunction(callback) ) callback.bind(me)(); } ,failure: function(response) { if ( response.status === 401 ) return me.renewToken(me.backupConfiguration); @@ -125,6 +128,9 @@ Ext.define('Rambox.ux.Auth0', { ,align: 't' ,closable: false }); + + if ( Ext.isFunction(callback) ) callback.bind(me)(); + console.error(response); } }); From fee8cb7544afc40f0d42b05ceb23420f36936e1a Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Wed, 24 May 2017 21:05:31 -0300 Subject: [PATCH 6/8] Fixed problem related with Auth0 windows The problem was related with "start_minimized" option. If the user had in "true", Auth0 windows will not work. --- electron/main.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/electron/main.js b/electron/main.js index 1c6c6ca6..fefcfdc5 100644 --- a/electron/main.js +++ b/electron/main.js @@ -162,11 +162,23 @@ function createWindow () { // Open links in default browser mainWindow.webContents.on('new-window', function(e, url, frameName, disposition, options) { - if ( disposition !== 'foreground-tab' ) return; const protocol = require('url').parse(url).protocol; - if (protocol === 'http:' || protocol === 'https:' || protocol === 'mailto:') { - e.preventDefault(); - shell.openExternal(url); + switch ( disposition ) { + case 'new-window': + e.preventDefault(); + const win = new BrowserWindow(options); + win.once('ready-to-show', () => win.show()); + win.loadURL(url); + e.newGuest = win; + break; + case 'foreground-tab': + if (protocol === 'http:' || protocol === 'https:' || protocol === 'mailto:') { + e.preventDefault(); + shell.openExternal(url); + } + break; + default: + break; } }); From 5621c834dab69543e78e9819bcfb6db86bb30de4 Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Thu, 25 May 2017 00:28:36 -0300 Subject: [PATCH 7/8] Improved focus window --- electron/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/electron/main.js b/electron/main.js index fefcfdc5..e0349bd2 100644 --- a/electron/main.js +++ b/electron/main.js @@ -136,6 +136,7 @@ function createWindow () { ,autoHideMenuBar: config.get('hide_menu_bar') ,skipTaskbar: config.get('window_display_behavior') === 'show_trayIcon' ,show: !config.get('start_minimized') + ,acceptFirstMouse: true ,webPreferences: { webSecurity: false ,nodeIntegration: true From d12304cb075ca57ae69be3418e83c1c3154aa89a Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Mon, 29 May 2017 15:57:22 -0300 Subject: [PATCH 8/8] Versioning 0.5.9 --- app/package.json | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/package.json b/app/package.json index 2b489d15..79752f91 100644 --- a/app/package.json +++ b/app/package.json @@ -1,7 +1,7 @@ { "name": "Rambox", "productName": "Rambox", - "version": "0.5.8", + "version": "0.5.9", "description": "Rambox", "main": "electron/main.js", "private": true, diff --git a/appveyor.yml b/appveyor.yml index e84f5877..10d59970 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 0.5.8 +version: 0.5.9 pull_requests: do_not_increment_build_number: true branches: