mirror of https://github.com/keeweb/keeweb.git
Refactor settiing stores to work with promises, wait untill all loaded before showing the app
This commit is contained in:
parent
b04cd843dc
commit
542db7fd0d
|
@ -2,6 +2,10 @@
|
|||
|
||||
const AppModel = require('./models/app-model');
|
||||
const AppView = require('./views/app-view');
|
||||
const AppSettingsModel = require('./models/app-settings-model');
|
||||
const UpdateModel = require('./models/update-model');
|
||||
const RuntimeDataModel = require('./models/runtime-data-model');
|
||||
const FileInfoCollection = require('./collections/file-info-collection');
|
||||
const KeyHandler = require('./comp/key-handler');
|
||||
const IdleTracker = require('./comp/idle-tracker');
|
||||
const PopupNotifier = require('./comp/popup-notifier');
|
||||
|
@ -25,20 +29,15 @@ ready(() => {
|
|||
initModules();
|
||||
|
||||
const appModel = new AppModel();
|
||||
SettingsManager.setBySettings(appModel.settings);
|
||||
const configParam = getConfigParam();
|
||||
if (configParam) {
|
||||
appModel.loadConfig(configParam, err => {
|
||||
SettingsManager.setBySettings(appModel.settings);
|
||||
if (err) {
|
||||
showSettingsLoadError();
|
||||
} else {
|
||||
showApp();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
showApp();
|
||||
}
|
||||
|
||||
Promise.all([
|
||||
AppSettingsModel.instance.load(),
|
||||
UpdateModel.instance.load(),
|
||||
RuntimeDataModel.instance.load(),
|
||||
FileInfoCollection.instance.load()
|
||||
])
|
||||
.then(loadRemoteConfig())
|
||||
.then(showApp);
|
||||
|
||||
function isPopup() {
|
||||
return (window.parent !== window.top) || window.opener;
|
||||
|
@ -66,6 +65,26 @@ ready(() => {
|
|||
});
|
||||
}
|
||||
|
||||
function loadRemoteConfig() {
|
||||
return new Promise((resolve, reject) => {
|
||||
SettingsManager.setBySettings(appModel.settings);
|
||||
const configParam = getConfigParam();
|
||||
if (configParam) {
|
||||
appModel.loadConfig(configParam, err => {
|
||||
SettingsManager.setBySettings(appModel.settings);
|
||||
if (err) {
|
||||
showSettingsLoadError();
|
||||
reject(err);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showApp() {
|
||||
const skipHttpsWarning = localStorage.skipHttpsWarning || appModel.settings.get('skipHttpsWarning');
|
||||
const protocolIsInsecure = ['https:', 'file:', 'app:'].indexOf(location.protocol) < 0;
|
||||
|
|
|
@ -11,7 +11,16 @@ const FileInfoCollection = Backbone.Collection.extend({
|
|||
},
|
||||
|
||||
load: function () {
|
||||
SettingsStore.load('file-info', this.onLoaded.bind(this));
|
||||
return new Promise((resolve, reject) => {
|
||||
SettingsStore.load('file-info', (data, err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
this.onLoaded(data);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
onLoaded: function(data) {
|
||||
|
|
|
@ -5,7 +5,7 @@ let Launcher;
|
|||
if (window.process && window.process.versions && window.process.versions.electron) {
|
||||
Launcher = require('./launcher-electron');
|
||||
} else if (window.cordova) {
|
||||
// Launcher = require('./launcher-android');
|
||||
// Launcher = require('./launcher-cordova');
|
||||
}
|
||||
|
||||
module.exports = Launcher;
|
||||
|
|
|
@ -27,7 +27,7 @@ const AppModel = Backbone.Model.extend({
|
|||
initialize: function() {
|
||||
this.tags = [];
|
||||
this.files = new FileCollection();
|
||||
this.fileInfos = FileInfoCollection.load();
|
||||
this.fileInfos = FileInfoCollection.instance;
|
||||
this.menu = new MenuModel();
|
||||
this.filter = {};
|
||||
this.sort = 'title';
|
||||
|
|
|
@ -46,15 +46,21 @@ const AppSettingsModel = Backbone.Model.extend({
|
|||
},
|
||||
|
||||
load: function() {
|
||||
SettingsStore.load('app-settings', this.onLoaded.bind(this));
|
||||
return new Promise((resolve, reject) => {
|
||||
SettingsStore.load('app-settings', (data, err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
this.onLoaded(data);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
onLoaded: function(data) {
|
||||
if (data) {
|
||||
this.upgrade(data);
|
||||
}
|
||||
|
||||
if (data) {
|
||||
this.set(data, {silent: true});
|
||||
}
|
||||
},
|
||||
|
|
|
@ -11,7 +11,16 @@ const RuntimeDataModel = Backbone.Model.extend({
|
|||
},
|
||||
|
||||
load: function() {
|
||||
SettingsStore.load('runtime-data', this.onLoaded.bind(this));
|
||||
return new Promise((resolve, reject) => {
|
||||
SettingsStore.load('runtime-data', (data, err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
this.onLoaded(data);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
onLoaded: function(data) {
|
||||
|
|
|
@ -21,7 +21,16 @@ const UpdateModel = Backbone.Model.extend({
|
|||
},
|
||||
|
||||
load: function() {
|
||||
SettingsStore.load('update-info', this.onLoaded.bind(this));
|
||||
return new Promise((resolve, reject) => {
|
||||
SettingsStore.load('update-info', (data, err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
this.onLoaded(data);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
onLoaded: function(data) {
|
||||
|
|
Loading…
Reference in New Issue