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.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 46a616d3..2edde25f 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: [ @@ -30,9 +31,16 @@ 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(); + // 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); @@ -196,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/package.json b/app/package.json index 1a7ba831..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, @@ -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/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' diff --git a/app/ux/Auth0.js b/app/ux/Auth0.js index 245bc3c4..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; @@ -51,13 +52,16 @@ 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)); 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(); @@ -74,7 +78,7 @@ Ext.define('Rambox.ux.Auth0', { }); } - ,backupConfiguration: function() { + ,backupConfiguration: function(callback) { var me = this; Ext.Msg.wait('Saving backup...', 'Please wait...'); @@ -110,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); @@ -122,6 +128,9 @@ Ext.define('Rambox.ux.Auth0', { ,align: 't' ,closable: false }); + + if ( Ext.isFunction(callback) ) callback.bind(me)(); + console.error(response); } }); @@ -225,5 +234,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/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) { 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: diff --git a/electron/main.js b/electron/main.js index 1c6c6ca6..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 @@ -162,11 +163,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; } }); 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" } }