mirror of
https://github.com/keeweb/keeweb.git
synced 2024-06-20 06:56:40 +02:00
Merge branch 'alex-shpak-develop' into develop
This commit is contained in:
parent
1438ae5642
commit
adcf3c5377
|
@ -19,7 +19,6 @@ const PluginManager = require('./plugins/plugin-manager');
|
|||
const Launcher = require('./comp/launcher');
|
||||
const KdbxwebInit = require('./util/kdbxweb-init');
|
||||
const Locale = require('./util/locale');
|
||||
const Logger = require('./util/logger');
|
||||
|
||||
const ready = Launcher && Launcher.ready || $;
|
||||
|
||||
|
@ -28,52 +27,14 @@ ready(() => {
|
|||
return AuthReceiver.receive();
|
||||
}
|
||||
loadMixins();
|
||||
let appModel;
|
||||
const logger = new Logger('app');
|
||||
initModules().then(() => {
|
||||
appModel = new AppModel();
|
||||
SettingsManager.setBySettings(appModel.settings);
|
||||
const configParam = getConfigParam();
|
||||
if (configParam) {
|
||||
appModel.loadConfig(configParam, err => {
|
||||
SettingsManager.setBySettings(appModel.settings);
|
||||
if (err && !appModel.settings.get('cacheConfigSettings')) {
|
||||
showSettingsLoadError();
|
||||
} else {
|
||||
showApp();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
showApp();
|
||||
}
|
||||
});
|
||||
|
||||
const appModel = new AppModel();
|
||||
SettingsManager.setBySettings(appModel.settings);
|
||||
const configParam = getConfigParam();
|
||||
if (configParam) {
|
||||
appModel.loadConfig(configParam, err => {
|
||||
SettingsManager.setBySettings(appModel.settings);
|
||||
if (err && !appModel.settings.get('cacheConfigSettings')) {
|
||||
showSettingsLoadError();
|
||||
} else {
|
||||
showApp();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
showApp();
|
||||
}
|
||||
|
||||
/* const appModel = new AppModel();
|
||||
|
||||
Promise.all([
|
||||
AppSettingsModel.instance.load(),
|
||||
UpdateModel.instance.load(),
|
||||
RuntimeDataModel.instance.load(),
|
||||
FileInfoCollection.instance.load()
|
||||
])
|
||||
.then(loadRemoteConfig())
|
||||
.then(showApp); */
|
||||
Promise.resolve()
|
||||
.then(loadConfigs)
|
||||
.then(initModules)
|
||||
.then(loadRemoteConfig)
|
||||
.then(showApp);
|
||||
|
||||
function isPopup() {
|
||||
return (window.parent !== window.top) || window.opener;
|
||||
|
@ -84,15 +45,22 @@ ready(() => {
|
|||
require('./helpers');
|
||||
}
|
||||
|
||||
function loadConfigs() {
|
||||
return Promise.all([
|
||||
AppSettingsModel.instance.load(),
|
||||
UpdateModel.instance.load(),
|
||||
RuntimeDataModel.instance.load(),
|
||||
FileInfoCollection.instance.load()
|
||||
]);
|
||||
}
|
||||
|
||||
function initModules() {
|
||||
const promises = [];
|
||||
KeyHandler.init();
|
||||
IdleTracker.init();
|
||||
PopupNotifier.init();
|
||||
KdbxwebInit.init();
|
||||
promises.push(PluginManager.init());
|
||||
window.kw = ExportApi;
|
||||
return Promise.all(promises);
|
||||
return PluginManager.init();
|
||||
}
|
||||
|
||||
function showSettingsLoadError() {
|
||||
|
@ -147,7 +115,7 @@ ready(() => {
|
|||
Updater.init();
|
||||
SingleInstanceChecker.init();
|
||||
const time = Math.round(performance.now());
|
||||
logger.info(`Started in ${time}ms ¯\\_(ツ)_/¯`);
|
||||
appModel.appLogger.info(`Started in ${time}ms ¯\\_(ツ)_/¯`);
|
||||
}
|
||||
|
||||
function getConfigParam() {
|
||||
|
|
|
@ -11,24 +11,13 @@ const FileInfoCollection = Backbone.Collection.extend({
|
|||
},
|
||||
|
||||
load: function () {
|
||||
return new Promise((resolve, reject) => {
|
||||
SettingsStore.load('file-info', (data, err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
this.onLoaded(data);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
return SettingsStore.load('file-info').then(data => {
|
||||
if (data) {
|
||||
this.reset(data, {silent: true});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onLoaded: function(data) {
|
||||
if (data) {
|
||||
this.reset(data, { silent: true });
|
||||
}
|
||||
},
|
||||
|
||||
save: function () {
|
||||
SettingsStore.save('file-info', this.toJSON());
|
||||
},
|
||||
|
|
|
@ -11,9 +11,6 @@ const Launcher = {
|
|||
version: window.process.versions.electron,
|
||||
autoTypeSupported: true,
|
||||
req: window.require,
|
||||
ready: function(callback) {
|
||||
$(callback);
|
||||
},
|
||||
platform: function() {
|
||||
return process.platform;
|
||||
},
|
||||
|
|
|
@ -7,57 +7,58 @@ const Logger = require('../util/logger');
|
|||
const logger = new Logger('settings');
|
||||
|
||||
const SettingsStore = {
|
||||
|
||||
fileName: function(key) {
|
||||
return `${key}.json`;
|
||||
},
|
||||
|
||||
load: function(key, callback) {
|
||||
try {
|
||||
load: function(key) {
|
||||
return new Promise(resolve => {
|
||||
if (Launcher) {
|
||||
const settingsFile = Launcher.getUserDataPath(this.fileName(key));
|
||||
Launcher.fileExists(settingsFile, exists => {
|
||||
if (exists) {
|
||||
Launcher.readFile(settingsFile, 'utf8', (data, err) => {
|
||||
if (data) {
|
||||
callback(JSON.parse(data));
|
||||
} else {
|
||||
logger.error(`Error loading ${key}`, err);
|
||||
callback(undefined, err);
|
||||
}
|
||||
Launcher.readFile(settingsFile, 'utf8', data => {
|
||||
return this.parseData(key, data, resolve);
|
||||
});
|
||||
} else {
|
||||
callback();
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const data = localStorage[StringUtil.camelCase(key)];
|
||||
callback(data ? JSON.parse(data) : undefined);
|
||||
return this.parseData(key, data, resolve);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
parseData: function(key, data, resolve) {
|
||||
try {
|
||||
if (data) {
|
||||
return resolve(JSON.parse(data));
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error(`Error loading ${key}`, e);
|
||||
callback(undefined, e);
|
||||
logger.error('Error loading ' + key, e);
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
|
||||
save: function(key, data, callback) {
|
||||
try {
|
||||
save: function(key, data) {
|
||||
return new Promise(resolve => {
|
||||
if (Launcher) {
|
||||
const settingsFile = Launcher.getUserDataPath(this.fileName(key));
|
||||
Launcher.writeFile(settingsFile, JSON.stringify(data), err => {
|
||||
if (err) {
|
||||
logger.error(`Error saving ${key}`, err);
|
||||
}
|
||||
if (callback) { callback(err); }
|
||||
resolve();
|
||||
});
|
||||
} else if (typeof localStorage !== 'undefined') {
|
||||
localStorage[StringUtil.camelCase(key)] = JSON.stringify(data);
|
||||
if (callback) { callback(); }
|
||||
resolve();
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error(`Error saving ${key}`, e);
|
||||
if (callback) { callback(e); }
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -49,25 +49,14 @@ const AppSettingsModel = Backbone.Model.extend({
|
|||
},
|
||||
|
||||
load: function() {
|
||||
return new Promise((resolve, reject) => {
|
||||
SettingsStore.load('app-settings', (data, err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
this.onLoaded(data);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
return SettingsStore.load('app-settings').then(data => {
|
||||
if (data) {
|
||||
this.upgrade(data);
|
||||
this.set(data, {silent: true});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onLoaded: function(data) {
|
||||
if (data) {
|
||||
this.upgrade(data);
|
||||
this.set(data, {silent: true});
|
||||
}
|
||||
},
|
||||
|
||||
upgrade: function(data) {
|
||||
if (data.rememberKeyFiles === true) {
|
||||
data.rememberKeyFiles = 'data';
|
||||
|
|
|
@ -11,24 +11,13 @@ const RuntimeDataModel = Backbone.Model.extend({
|
|||
},
|
||||
|
||||
load: function() {
|
||||
return new Promise((resolve, reject) => {
|
||||
SettingsStore.load('runtime-data', (data, err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
this.onLoaded(data);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
return SettingsStore.load('runtime-data').then(data => {
|
||||
if (data) {
|
||||
this.set(data, {silent: true});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onLoaded: function(data) {
|
||||
if (data) {
|
||||
this.set(data, {silent: true});
|
||||
}
|
||||
},
|
||||
|
||||
save: function() {
|
||||
SettingsStore.save('runtime-data', this.attributes);
|
||||
}
|
||||
|
|
|
@ -21,31 +21,21 @@ const UpdateModel = Backbone.Model.extend({
|
|||
},
|
||||
|
||||
load: function() {
|
||||
return new Promise((resolve, reject) => {
|
||||
SettingsStore.load('update-info', (data, err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
this.onLoaded(data);
|
||||
resolve();
|
||||
return SettingsStore.load('update-info').then(data => {
|
||||
if (data) {
|
||||
try {
|
||||
_.each(data, (val, key) => {
|
||||
if (/Date$/.test(key)) {
|
||||
data[key] = val ? new Date(val) : null;
|
||||
}
|
||||
});
|
||||
this.set(data, {silent: true});
|
||||
} catch (e) { /* failed to load model */
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onLoaded: function(data) {
|
||||
if (data) {
|
||||
try {
|
||||
_.each(data, (val, key) => {
|
||||
if (/Date$/.test(key)) {
|
||||
data[key] = val ? new Date(val) : null;
|
||||
}
|
||||
});
|
||||
this.set(data, { silent: true });
|
||||
} catch (e) { /* failed to load model */ }
|
||||
}
|
||||
},
|
||||
|
||||
save: function() {
|
||||
const attr = _.clone(this.attributes);
|
||||
Object.keys(attr).forEach(key => {
|
||||
|
|
|
@ -19,8 +19,7 @@ const PluginManager = Backbone.Model.extend({
|
|||
|
||||
init() {
|
||||
const ts = this.logger.ts();
|
||||
return Promise.resolve().then(() => {
|
||||
const state = this.loadState();
|
||||
return SettingsStore.load('plugins').then(state => {
|
||||
if (!state || !state.plugins || !state.plugins.length) {
|
||||
return;
|
||||
}
|
||||
|
@ -78,10 +77,6 @@ const PluginManager = Backbone.Model.extend({
|
|||
url: plugin.get('url')
|
||||
}))
|
||||
});
|
||||
},
|
||||
|
||||
loadState() {
|
||||
return SettingsStore.load('plugins');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user