mirror of
https://github.com/keeweb/keeweb.git
synced 2024-06-26 07:39:04 +02:00
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 AppModel = require('./models/app-model');
|
||||||
const AppView = require('./views/app-view');
|
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 KeyHandler = require('./comp/key-handler');
|
||||||
const IdleTracker = require('./comp/idle-tracker');
|
const IdleTracker = require('./comp/idle-tracker');
|
||||||
const PopupNotifier = require('./comp/popup-notifier');
|
const PopupNotifier = require('./comp/popup-notifier');
|
||||||
|
@ -25,20 +29,15 @@ ready(() => {
|
||||||
initModules();
|
initModules();
|
||||||
|
|
||||||
const appModel = new AppModel();
|
const appModel = new AppModel();
|
||||||
SettingsManager.setBySettings(appModel.settings);
|
|
||||||
const configParam = getConfigParam();
|
Promise.all([
|
||||||
if (configParam) {
|
AppSettingsModel.instance.load(),
|
||||||
appModel.loadConfig(configParam, err => {
|
UpdateModel.instance.load(),
|
||||||
SettingsManager.setBySettings(appModel.settings);
|
RuntimeDataModel.instance.load(),
|
||||||
if (err) {
|
FileInfoCollection.instance.load()
|
||||||
showSettingsLoadError();
|
])
|
||||||
} else {
|
.then(loadRemoteConfig())
|
||||||
showApp();
|
.then(showApp);
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
showApp();
|
|
||||||
}
|
|
||||||
|
|
||||||
function isPopup() {
|
function isPopup() {
|
||||||
return (window.parent !== window.top) || window.opener;
|
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() {
|
function showApp() {
|
||||||
const skipHttpsWarning = localStorage.skipHttpsWarning || appModel.settings.get('skipHttpsWarning');
|
const skipHttpsWarning = localStorage.skipHttpsWarning || appModel.settings.get('skipHttpsWarning');
|
||||||
const protocolIsInsecure = ['https:', 'file:', 'app:'].indexOf(location.protocol) < 0;
|
const protocolIsInsecure = ['https:', 'file:', 'app:'].indexOf(location.protocol) < 0;
|
||||||
|
|
|
@ -11,7 +11,16 @@ const FileInfoCollection = Backbone.Collection.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
load: function () {
|
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) {
|
onLoaded: function(data) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ let Launcher;
|
||||||
if (window.process && window.process.versions && window.process.versions.electron) {
|
if (window.process && window.process.versions && window.process.versions.electron) {
|
||||||
Launcher = require('./launcher-electron');
|
Launcher = require('./launcher-electron');
|
||||||
} else if (window.cordova) {
|
} else if (window.cordova) {
|
||||||
// Launcher = require('./launcher-android');
|
// Launcher = require('./launcher-cordova');
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Launcher;
|
module.exports = Launcher;
|
||||||
|
|
|
@ -27,7 +27,7 @@ const AppModel = Backbone.Model.extend({
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
this.tags = [];
|
this.tags = [];
|
||||||
this.files = new FileCollection();
|
this.files = new FileCollection();
|
||||||
this.fileInfos = FileInfoCollection.load();
|
this.fileInfos = FileInfoCollection.instance;
|
||||||
this.menu = new MenuModel();
|
this.menu = new MenuModel();
|
||||||
this.filter = {};
|
this.filter = {};
|
||||||
this.sort = 'title';
|
this.sort = 'title';
|
||||||
|
|
|
@ -46,15 +46,21 @@ const AppSettingsModel = Backbone.Model.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
load: function() {
|
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) {
|
onLoaded: function(data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
this.upgrade(data);
|
this.upgrade(data);
|
||||||
}
|
|
||||||
|
|
||||||
if (data) {
|
|
||||||
this.set(data, {silent: true});
|
this.set(data, {silent: true});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -11,7 +11,16 @@ const RuntimeDataModel = Backbone.Model.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
load: function() {
|
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) {
|
onLoaded: function(data) {
|
||||||
|
|
|
@ -21,7 +21,16 @@ const UpdateModel = Backbone.Model.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
load: function() {
|
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) {
|
onLoaded: function(data) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user