From d4038a3e8deed2a8f6d8614c30ed9c884e375003 Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Wed, 24 May 2017 21:04:26 -0300 Subject: [PATCH] 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); } });