Skip to content
This repository was archived by the owner on Apr 22, 2022. It is now read-only.

Commit

Permalink
v0.5.9
Browse files Browse the repository at this point in the history
0.5.9
  • Loading branch information
saenzramiro authored May 29, 2017
2 parents 3d7ae58 + d12304c commit 3674116
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 14 deletions.
3 changes: 3 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
1 change: 1 addition & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
* ]
*/
"requires": [
"ext-locale"
],

/**
Expand Down
78 changes: 78 additions & 0 deletions app/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Ext.define('Rambox.Application', {
'Rambox.ux.Auth0'
,'Rambox.util.MD5'
,'Ext.window.Toast'
,'Ext.util.Cookies'
]

,stores: [
Expand All @@ -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);

Expand Down Expand Up @@ -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: '<h1>Synchronization problem fixed!</h1>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.<br><br>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: '<h1>Login again</h1>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: '<h1>Backup</h1>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();
}
Expand Down
5 changes: 3 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Rambox",
"productName": "Rambox",
"version": "0.5.8",
"version": "0.5.9",
"description": "Rambox",
"main": "electron/main.js",
"private": true,
Expand Down Expand Up @@ -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"
}
}
3 changes: 2 additions & 1 deletion app/store/ServicesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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. <a href="https://support.google.com/mail/answer/1075549?ref_topic=3394466" target="_blank">Read more...</a>'
,dont_update_unread_from_title: true
},
{
id: 'inbox'
Expand Down
16 changes: 14 additions & 2 deletions app/ux/Auth0.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Ext.define('Rambox.ux.Auth0', {
// private
,lock: null
,auth0: null
,backupCurrent: false

,init: function() {
var me = this;
Expand Down Expand Up @@ -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();
Expand All @@ -74,7 +78,7 @@ Ext.define('Rambox.ux.Auth0', {
});
}

,backupConfiguration: function() {
,backupConfiguration: function(callback) {
var me = this;

Ext.Msg.wait('Saving backup...', 'Please wait...');
Expand Down Expand Up @@ -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);
Expand All @@ -122,6 +128,9 @@ Ext.define('Rambox.ux.Auth0', {
,align: 't'
,closable: false
});

if ( Ext.isFunction(callback) ) callback.bind(me)();

console.error(response);
}
});
Expand Down Expand Up @@ -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);
}
});
9 changes: 6 additions & 3 deletions app/ux/WebView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -355,21 +356,21 @@ 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;
}
}

// Prevent Title blinking (some services have) and only allow when the title have an unread regex match: "(3) Title"
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) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 0.5.8
version: 0.5.9
pull_requests:
do_not_increment_build_number: true
branches:
Expand Down
21 changes: 17 additions & 4 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
});

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 3674116

Please sign in to comment.