Browse Source
This still has the same issues with actually removing old data as upstream. Electron issues and other requests have gone unanswered, so pushing to master.pull/3202/head
18 changed files with 565 additions and 467 deletions
@ -0,0 +1,284 @@
|
||||
{ |
||||
"name": "Rambox", |
||||
"version": "0.5.18", |
||||
"lockfileVersion": 1, |
||||
"requires": true, |
||||
"dependencies": { |
||||
"applescript": { |
||||
"version": "1.0.0", |
||||
"resolved": "https://registry.npmjs.org/applescript/-/applescript-1.0.0.tgz", |
||||
"integrity": "sha1-u4evVoytA0pOSMS9r2Bno6JwExc=" |
||||
}, |
||||
"auto-launch-patched": { |
||||
"version": "5.0.2", |
||||
"resolved": "https://registry.npmjs.org/auto-launch-patched/-/auto-launch-patched-5.0.2.tgz", |
||||
"integrity": "sha1-8a5oPIwTG93Pr68YHuMsqGbwejM=", |
||||
"requires": { |
||||
"applescript": "^1.0.0", |
||||
"mkdirp": "^0.5.1", |
||||
"path-is-absolute": "^1.0.0", |
||||
"untildify": "^3.0.2", |
||||
"winreg": "1.2.2" |
||||
} |
||||
}, |
||||
"conf": { |
||||
"version": "2.0.0", |
||||
"resolved": "https://registry.npmjs.org/conf/-/conf-2.0.0.tgz", |
||||
"integrity": "sha512-iCLzBsGFi8S73EANsEJZz0JnJ/e5VZef/kSaxydYZLAvw0rFNAUx5R7K5leC/CXXR2mZfXWhUvcZOO/dM2D5xg==", |
||||
"requires": { |
||||
"dot-prop": "^4.1.0", |
||||
"env-paths": "^1.0.0", |
||||
"make-dir": "^1.0.0", |
||||
"pkg-up": "^2.0.0", |
||||
"write-file-atomic": "^2.3.0" |
||||
} |
||||
}, |
||||
"dot-prop": { |
||||
"version": "4.2.0", |
||||
"resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz", |
||||
"integrity": "sha512-tUMXrxlExSW6U2EXiiKGSBVdYgtV8qlHL+C10TsW4PURY/ic+eaysnSkwB4kA/mBlCyy/IKDJ+Lc3wbWeaXtuQ==", |
||||
"requires": { |
||||
"is-obj": "^1.0.0" |
||||
} |
||||
}, |
||||
"electron-context-menu": { |
||||
"version": "0.10.0", |
||||
"resolved": "https://registry.npmjs.org/electron-context-menu/-/electron-context-menu-0.10.0.tgz", |
||||
"integrity": "sha512-8dv+cOIpGuSmxAje3qdydd7kzfUTHBiEq6V80CqW76P5M92sEl0WpHHhNKxKFZ2L+mNr5Lp4R9qGjyfDiYI8yg==", |
||||
"requires": { |
||||
"electron-dl": "^1.2.0", |
||||
"electron-is-dev": "^0.3.0" |
||||
} |
||||
}, |
||||
"electron-dl": { |
||||
"version": "1.12.0", |
||||
"resolved": "https://registry.npmjs.org/electron-dl/-/electron-dl-1.12.0.tgz", |
||||
"integrity": "sha512-UMc2CL45Ybpvu66LDPYzwmDRmYK4Ivz+wdnTM0eXcNMztvQwhixAk2UPme1c7McqG8bAlKEkQpZn3epmQy4EWg==", |
||||
"requires": { |
||||
"ext-name": "^5.0.0", |
||||
"pupa": "^1.0.0", |
||||
"unused-filename": "^1.0.0" |
||||
} |
||||
}, |
||||
"electron-is-dev": { |
||||
"version": "0.3.0", |
||||
"resolved": "https://registry.npmjs.org/electron-is-dev/-/electron-is-dev-0.3.0.tgz", |
||||
"integrity": "sha1-FOb9pcaOnk7L7/nM8DfL18BcWv4=" |
||||
}, |
||||
"electron-store": { |
||||
"version": "2.0.0", |
||||
"resolved": "https://registry.npmjs.org/electron-store/-/electron-store-2.0.0.tgz", |
||||
"integrity": "sha512-1WCFYHsYvZBqDsoaS0Relnz0rd81ZkBAI0Fgx7Nq2UWU77rSNs1qxm4S6uH7TCZ0bV3LQpJFk7id/is/ZgoOPA==", |
||||
"requires": { |
||||
"conf": "^2.0.0" |
||||
} |
||||
}, |
||||
"env-paths": { |
||||
"version": "1.0.0", |
||||
"resolved": "https://registry.npmjs.org/env-paths/-/env-paths-1.0.0.tgz", |
||||
"integrity": "sha1-QWgTO0K7BcOKNbGuQ5fIKYqzaeA=" |
||||
}, |
||||
"ext-list": { |
||||
"version": "2.2.2", |
||||
"resolved": "https://registry.npmjs.org/ext-list/-/ext-list-2.2.2.tgz", |
||||
"integrity": "sha512-u+SQgsubraE6zItfVA0tBuCBhfU9ogSRnsvygI7wht9TS510oLkBRXBsqopeUG/GBOIQyKZO9wjTqIu/sf5zFA==", |
||||
"requires": { |
||||
"mime-db": "^1.28.0" |
||||
} |
||||
}, |
||||
"ext-name": { |
||||
"version": "5.0.0", |
||||
"resolved": "https://registry.npmjs.org/ext-name/-/ext-name-5.0.0.tgz", |
||||
"integrity": "sha512-yblEwXAbGv1VQDmow7s38W77hzAgJAO50ztBLMcUyUBfxv1HC+LGwtiEN+Co6LtlqT/5uwVOxsD4TNIilWhwdQ==", |
||||
"requires": { |
||||
"ext-list": "^2.0.0", |
||||
"sort-keys-length": "^1.0.0" |
||||
} |
||||
}, |
||||
"find-up": { |
||||
"version": "2.1.0", |
||||
"resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", |
||||
"integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", |
||||
"requires": { |
||||
"locate-path": "^2.0.0" |
||||
} |
||||
}, |
||||
"graceful-fs": { |
||||
"version": "4.1.11", |
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", |
||||
"integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" |
||||
}, |
||||
"imurmurhash": { |
||||
"version": "0.1.4", |
||||
"resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", |
||||
"integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=" |
||||
}, |
||||
"is-obj": { |
||||
"version": "1.0.1", |
||||
"resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", |
||||
"integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=" |
||||
}, |
||||
"is-plain-obj": { |
||||
"version": "1.1.0", |
||||
"resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz", |
||||
"integrity": "sha1-caUMhCnfync8kqOQpKA7OfzVHT4=" |
||||
}, |
||||
"locate-path": { |
||||
"version": "2.0.0", |
||||
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", |
||||
"integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=", |
||||
"requires": { |
||||
"p-locate": "^2.0.0", |
||||
"path-exists": "^3.0.0" |
||||
} |
||||
}, |
||||
"make-dir": { |
||||
"version": "1.3.0", |
||||
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz", |
||||
"integrity": "sha512-2w31R7SJtieJJnQtGc7RVL2StM2vGYVfqUOvUDxH6bC6aJTxPxTF0GnIgCyu7tjockiUWAYQRbxa7vKn34s5sQ==", |
||||
"requires": { |
||||
"pify": "^3.0.0" |
||||
} |
||||
}, |
||||
"mime": { |
||||
"version": "2.3.1", |
||||
"resolved": "https://registry.npmjs.org/mime/-/mime-2.3.1.tgz", |
||||
"integrity": "sha512-OEUllcVoydBHGN1z84yfQDimn58pZNNNXgZlHXSboxMlFvgI6MXSWpWKpFRra7H1HxpVhHTkrghfRW49k6yjeg==" |
||||
}, |
||||
"mime-db": { |
||||
"version": "1.35.0", |
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.35.0.tgz", |
||||
"integrity": "sha512-JWT/IcCTsB0Io3AhWUMjRqucrHSPsSf2xKLaRldJVULioggvkJvggZ3VXNNSRkCddE6D+BUI4HEIZIA2OjwIvg==" |
||||
}, |
||||
"minimist": { |
||||
"version": "0.0.8", |
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", |
||||
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" |
||||
}, |
||||
"mkdirp": { |
||||
"version": "0.5.1", |
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", |
||||
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", |
||||
"requires": { |
||||
"minimist": "0.0.8" |
||||
} |
||||
}, |
||||
"modify-filename": { |
||||
"version": "1.1.0", |
||||
"resolved": "https://registry.npmjs.org/modify-filename/-/modify-filename-1.1.0.tgz", |
||||
"integrity": "sha1-mi3sg4Bvuy2XXyK+7IWcoms5OqE=" |
||||
}, |
||||
"os-tmpdir": { |
||||
"version": "1.0.2", |
||||
"resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", |
||||
"integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=" |
||||
}, |
||||
"p-limit": { |
||||
"version": "1.3.0", |
||||
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", |
||||
"integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", |
||||
"requires": { |
||||
"p-try": "^1.0.0" |
||||
} |
||||
}, |
||||
"p-locate": { |
||||
"version": "2.0.0", |
||||
"resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", |
||||
"integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", |
||||
"requires": { |
||||
"p-limit": "^1.1.0" |
||||
} |
||||
}, |
||||
"p-try": { |
||||
"version": "1.0.0", |
||||
"resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", |
||||
"integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=" |
||||
}, |
||||
"path-exists": { |
||||
"version": "3.0.0", |
||||
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", |
||||
"integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=" |
||||
}, |
||||
"path-is-absolute": { |
||||
"version": "1.0.1", |
||||
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", |
||||
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" |
||||
}, |
||||
"pify": { |
||||
"version": "3.0.0", |
||||
"resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", |
||||
"integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=" |
||||
}, |
||||
"pkg-up": { |
||||
"version": "2.0.0", |
||||
"resolved": "https://registry.npmjs.org/pkg-up/-/pkg-up-2.0.0.tgz", |
||||
"integrity": "sha1-yBmscoBZpGHKscOImivjxJoATX8=", |
||||
"requires": { |
||||
"find-up": "^2.1.0" |
||||
} |
||||
}, |
||||
"pupa": { |
||||
"version": "1.0.0", |
||||
"resolved": "https://registry.npmjs.org/pupa/-/pupa-1.0.0.tgz", |
||||
"integrity": "sha1-mpVopa9+ZXuEYqbp1TKHQ1YM7/Y=" |
||||
}, |
||||
"signal-exit": { |
||||
"version": "3.0.2", |
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", |
||||
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" |
||||
}, |
||||
"sort-keys": { |
||||
"version": "1.1.2", |
||||
"resolved": "https://registry.npmjs.org/sort-keys/-/sort-keys-1.1.2.tgz", |
||||
"integrity": "sha1-RBttTTRnmPG05J6JIK37oOVD+a0=", |
||||
"requires": { |
||||
"is-plain-obj": "^1.0.0" |
||||
} |
||||
}, |
||||
"sort-keys-length": { |
||||
"version": "1.0.1", |
||||
"resolved": "https://registry.npmjs.org/sort-keys-length/-/sort-keys-length-1.0.1.tgz", |
||||
"integrity": "sha1-nLb09OnkgVWmqgZx7dM2/xR5oYg=", |
||||
"requires": { |
||||
"sort-keys": "^1.0.0" |
||||
} |
||||
}, |
||||
"tmp": { |
||||
"version": "0.0.33", |
||||
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", |
||||
"integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", |
||||
"requires": { |
||||
"os-tmpdir": "~1.0.2" |
||||
} |
||||
}, |
||||
"untildify": { |
||||
"version": "3.0.3", |
||||
"resolved": "https://registry.npmjs.org/untildify/-/untildify-3.0.3.tgz", |
||||
"integrity": "sha512-iSk/J8efr8uPT/Z4eSUywnqyrQU7DSdMfdqK4iWEaUVVmcP5JcnpRqmVMwcwcnmI1ATFNgC5V90u09tBynNFKA==" |
||||
}, |
||||
"unused-filename": { |
||||
"version": "1.0.0", |
||||
"resolved": "https://registry.npmjs.org/unused-filename/-/unused-filename-1.0.0.tgz", |
||||
"integrity": "sha1-00CID3GuIRXrqhMlvvBcxmhEacY=", |
||||
"requires": { |
||||
"modify-filename": "^1.1.0", |
||||
"path-exists": "^3.0.0" |
||||
} |
||||
}, |
||||
"winreg": { |
||||
"version": "1.2.2", |
||||
"resolved": "https://registry.npmjs.org/winreg/-/winreg-1.2.2.tgz", |
||||
"integrity": "sha1-hQmvo7ccW70RCm18YkfsZ3NsWY8=" |
||||
}, |
||||
"write-file-atomic": { |
||||
"version": "2.3.0", |
||||
"resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.3.0.tgz", |
||||
"integrity": "sha512-xuPeK4OdjWqtfi59ylvVL0Yn35SF3zgcAcv7rBPFHVaEapaDr4GdGgm3j7ckTwH9wHL7fGmgfAnb0+THrHb8tA==", |
||||
"requires": { |
||||
"graceful-fs": "^4.1.11", |
||||
"imurmurhash": "^0.1.4", |
||||
"signal-exit": "^3.0.2" |
||||
} |
||||
} |
||||
} |
||||
} |
@ -29,13 +29,11 @@
|
||||
"author": "TheGoddessInari <[email protected]>", |
||||
"license": "GPL-3.0", |
||||
"dependencies": { |
||||
"auth0-js": "^8.12.3", |
||||
"auth0-lock": "^10.22.0", |
||||
"auto-launch-patched": "5.0.2", |
||||
"electron-store": "2.0.0", |
||||
"electron-context-menu": "0.10.0", |
||||
"electron-store": "^2.0.0", |
||||
"electron-context-menu": "^0.10.0", |
||||
"electron-is-dev": "^0.3.0", |
||||
"mime": "^2.3.1", |
||||
"tmp": "0.0.33" |
||||
"tmp": "^0.0.33" |
||||
} |
||||
} |
||||
|
@ -1,256 +0,0 @@
|
||||
Ext.define('Rambox.ux.Auth0', { |
||||
singleton: true |
||||
|
||||
// private
|
||||
,lock: null |
||||
,auth0: null |
||||
,backupCurrent: false |
||||
|
||||
,init: function() { |
||||
var me = this; |
||||
|
||||
var Auth0Lock = require('auth0-lock')['default']; |
||||
var Auth0 = require('auth0-js'); |
||||
|
||||
// Auth0 Config
|
||||
me.lock = new Auth0Lock(auth0Cfg.clientID, auth0Cfg.domain, { |
||||
autoclose: true |
||||
,autofocus: true |
||||
,auth: { |
||||
redirect: false |
||||
,params: {scope: 'openid offline_access'} |
||||
} |
||||
,theme: { |
||||
logo: 'resources/Icon.png' |
||||
,primaryColor: '#0675A0' |
||||
} |
||||
,languageDictionary: { |
||||
title: 'Rambox-OS Account' |
||||
} |
||||
,popupOptions: { |
||||
nodeIntegration: 'no' |
||||
} |
||||
,language: localStorage.getItem('locale-auth0') === null ? 'en' : localStorage.getItem('locale-auth0') |
||||
}); |
||||
|
||||
me.auth0 = new Auth0.WebAuth({ clientID: auth0Cfg.clientID, domain : auth0Cfg.domain }); |
||||
|
||||
me.defineEvents(); |
||||
} |
||||
|
||||
,defineEvents: function() { |
||||
var me = this; |
||||
|
||||
me.lock.on("authenticated", function(authResult) { |
||||
me.lock.getProfile(authResult.idToken, function(err, profile) { |
||||
if ( err ) { |
||||
if ( err.error === 401 || err.error === 'Unauthorized' ) return me.renewToken(me.checkConfiguration); |
||||
Ext.Msg.hide(); |
||||
return Ext.Msg.show({ |
||||
title: 'Error' |
||||
,message: 'There was an error getting the profile: ' + err.error_description |
||||
,icon: Ext.Msg.ERROR |
||||
,buttons: Ext.Msg.OK |
||||
}); |
||||
} |
||||
|
||||
// Display a spinner while waiting
|
||||
Ext.Msg.wait(locale['app.window[29]'], locale['app.window[28]']); |
||||
|
||||
// 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) && !me.backupCurrent ) { |
||||
Ext.each(profile.user_metadata.services, function(s) { |
||||
var service = Ext.create('Rambox.model.Service', s); |
||||
service.save(); |
||||
Ext.getStore('Services').add(service); |
||||
}); |
||||
|
||||
require('electron').remote.getCurrentWindow().reload(); |
||||
} |
||||
|
||||
Ext.Msg.hide(); |
||||
Ext.cq1('app-main').getViewModel().set('username', profile.name); |
||||
Ext.cq1('app-main').getViewModel().set('avatar', profile.picture); |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
,backupConfiguration: function(callback) { |
||||
var me = this; |
||||
|
||||
Ext.Msg.wait('Saving backup...', 'Please wait...'); |
||||
|
||||
// Getting all services
|
||||
var lastupdate = (new Date()).toJSON(); |
||||
var services = []; |
||||
Ext.getStore('Services').each(function(service) { |
||||
var s = Ext.clone(service); |
||||
delete s.data.id; |
||||
delete s.data.zoomLevel; |
||||
services.push(s.data); |
||||
}); |
||||
|
||||
Ext.Ajax.request({ |
||||
url: 'https://rambox.auth0.com/api/v2/users/'+Ext.decode(localStorage.getItem('profile')).user_id |
||||
,method: 'PATCH' |
||||
,headers: { authorization: "Bearer " + localStorage.getItem('id_token') } |
||||
,jsonData: { user_metadata: { services: services, services_lastupdate: lastupdate } } |
||||
,success: function(response) { |
||||
Ext.Msg.hide(); |
||||
// Save the last update in localStorage
|
||||
var profile = Ext.decode(localStorage.getItem('profile')); |
||||
if ( !profile.user_metadata ) profile.user_metadata = {}; |
||||
profile.user_metadata.services_lastupdate = lastupdate; |
||||
localStorage.setItem('profile', Ext.encode(profile)); |
||||
Ext.cq1('app-main').getViewModel().set('last_sync', new Date(lastupdate).toUTCString()); |
||||
|
||||
Ext.toast({ |
||||
html: '<i class="fa fa-check fa-3x fa-pull-left" aria-hidden="true"></i> Your configuration were successfully backed up.' |
||||
,title: 'Synchronize Configuration' |
||||
,width: 300 |
||||
,align: 't' |
||||
,closable: false |
||||
}); |
||||
|
||||
if ( Ext.isFunction(callback) ) callback.bind(me)(); |
||||
} |
||||
,failure: function(response) { |
||||
if ( response.status === 401 ) return me.renewToken(me.backupConfiguration); |
||||
|
||||
Ext.Msg.hide(); |
||||
Ext.toast({ |
||||
html: '<i class="fa fa-times fa-3x fa-pull-left" aria-hidden="true"></i> Error occurred when trying to backup your configuration.' |
||||
,title: 'Synchronize Configuration' |
||||
,width: 300 |
||||
,align: 't' |
||||
,closable: false |
||||
}); |
||||
|
||||
if ( Ext.isFunction(callback) ) callback.bind(me)(); |
||||
|
||||
console.error(response); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
,restoreConfiguration: function() { |
||||
var me = this; |
||||
|
||||
me.lock.getProfile(localStorage.getItem('id_token'), function (err, profile) { |
||||
if ( err ) { |
||||
if ( err.error === 401 || err.error === 'Unauthorized' ) return me.renewToken(me.checkConfiguration); |
||||
return Ext.Msg.show({ |
||||
title: 'Error' |
||||
,message: 'There was an error getting the profile: ' + err.error_description |
||||
,icon: Ext.Msg.ERROR |
||||
,buttons: Ext.Msg.OK |
||||
}); |
||||
} |
||||
|
||||
// First we remove all current services
|
||||
Ext.cq1('app-main').getController().removeAllServices(false, function() { |
||||
Ext.each(profile.user_metadata.services, function(s) { |
||||
var service = Ext.create('Rambox.model.Service', s); |
||||
service.save(); |
||||
Ext.getStore('Services').add(service); |
||||
}); |
||||
|
||||
require('electron').remote.getCurrentWindow().reload(); |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
,checkConfiguration: function() { |
||||
var me = this; |
||||
|
||||
me.lock.getProfile(localStorage.getItem('id_token'), function (err, profile) { |
||||
if ( err ) { |
||||
if ( err.error === 401 || err.error === 'Unauthorized' ) return me.renewToken(me.checkConfiguration); |
||||
return Ext.Msg.show({ |
||||
title: 'Error' |
||||
,message: 'There was an error getting the profile: ' + err.error_description |
||||
,icon: Ext.Msg.ERROR |
||||
,buttons: Ext.Msg.OK |
||||
}); |
||||
} |
||||
|
||||
if ( !profile.user_metadata ) { |
||||
Ext.toast({ |
||||
html: 'You don\'t have any backup yet.' |
||||
,title: 'Synchronize Configuration' |
||||
,width: 300 |
||||
,align: 't' |
||||
,closable: false |
||||
}); |
||||
return; |
||||
} |
||||
|
||||
if ( Math.floor(new Date(profile.user_metadata.services_lastupdate) / 1000) > Math.floor(new Date(Ext.decode(localStorage.getItem('profile')).user_metadata.services_lastupdate) / 1000) ) { |
||||
Ext.toast({ |
||||
html: 'Your settings are out of date.' |
||||
,title: 'Synchronize Configuration' |
||||
,width: 300 |
||||
,align: 't' |
||||
,closable: false |
||||
}); |
||||
} else { |
||||
Ext.toast({ |
||||
html: 'Latest backup is already applied.' |
||||
,title: 'Synchronize Configuration' |
||||
,width: 300 |
||||
,align: 't' |
||||
,closable: false |
||||
}); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
,renewToken: function(callback) { |
||||
var me = this; |
||||
|
||||
Ext.Ajax.request({ |
||||
url: 'https://rambox.auth0.com/delegation' |
||||
,method: 'POST' |
||||
,jsonData: { |
||||
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer' |
||||
,client_id: auth0Cfg.clientID |
||||
,refresh_token: localStorage.getItem('refresh_token') |
||||
,api_type: 'app' |
||||
} |
||||
,success: function(response) { |
||||
var json = Ext.decode(response.responseText); |
||||
localStorage.setItem('id_token', json.id_token); |
||||
|
||||
if ( Ext.isFunction(callback) ) callback.bind(me)(); |
||||
} |
||||
,failure: function(response) { |
||||
console.error(response); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
,login: function() { |
||||
var me = this; |
||||
|
||||
me.lock.show(); |
||||
} |
||||
|
||||
,logout: function() { |
||||
var me = this; |
||||
|
||||
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); |
||||
} |
||||
}); |
@ -0,0 +1,65 @@
|
||||
const remote = require('electron').remote; |
||||
const dialog = remote.dialog; |
||||
const app = remote.app; |
||||
const fs = require('fs'); |
||||
const path = require('path'); |
||||
const userPath = app.getPath('userData'); |
||||
const defaultFileName = 'rambox-backup.json'; |
||||
const myDefaultPath = userPath + path.sep + defaultFileName; |
||||
|
||||
Ext.define('Rambox.ux.FileBackup', { |
||||
singleton: true, |
||||
BackupConfiguration: function (callback) { |
||||
var me = this; |
||||
let services = []; |
||||
Ext.getStore('Services').each(function(service) { |
||||
const s = Ext.clone(service); |
||||
delete s.data.id; |
||||
delete s.data.zoomLevel; |
||||
services.push(s.data); |
||||
}); |
||||
|
||||
const json_string = JSON.stringify(services, null, 4); |
||||
dialog.showSaveDialog({ |
||||
defaultPath: myDefaultPath |
||||
}, function(filename, bookmark) { |
||||
if (!filename) return; |
||||
fs.writeFile(filename, json_string, function(err) { |
||||
if (err) { |
||||
console.log(err); |
||||
} |
||||
}); |
||||
}); |
||||
if (Ext.isFunction(callback)) callback.bind(me)(); |
||||
}, |
||||
restoreConfiguration: function () { |
||||
var me = this; |
||||
dialog.showOpenDialog({ |
||||
defaultPath: myDefaultPath, |
||||
properties: ['openFile'] |
||||
}, function(filePaths, bookmarks) { |
||||
if (filePaths.length === 1) { |
||||
const filePath = filePaths[0]; |
||||
console.log(filePath); |
||||
fs.readFile(filePath, function (err, data) { |
||||
if (err) { |
||||
console.log(err); |
||||
} |
||||
const services = JSON.parse(data); |
||||
if (services) { |
||||
console.dir(services); |
||||
Ext.cq1('app-main').getController().removeAllServices(true, function() { |
||||
Ext.each(services, function(s) { |
||||
const service = Ext.create('Rambox.model.Service', s); |
||||
service.save(); |
||||
Ext.getStore('Services').add(service); |
||||
}); |
||||
remote.getCurrentWindow().reload(); |
||||
}); |
||||
|
||||
} |
||||
}); |
||||
} |
||||
}); |
||||
} |
||||
}); |
Loading…
Reference in new issue