Finished with async settings store,

Removed cloud drives from cordova
This commit is contained in:
Alex Shpak 2017-02-04 19:31:26 +01:00
parent b35edd8c9c
commit a9d3b08c49
6 changed files with 41 additions and 15 deletions

View File

@ -11,9 +11,12 @@ const FileInfoCollection = Backbone.Collection.extend({
},
load: function () {
const data = SettingsStore.load('file-info');
SettingsStore.load('file-info', this.onLoaded.bind(this));
},
onLoaded: function(data) {
if (data) {
this.reset(data, {silent: true});
this.reset(data, { silent: true });
}
},

View File

@ -1,6 +1,6 @@
'use strict';
const Launcher = false; // require('./launcher');
const Launcher = require('./launcher');
const StringUtil = require('../util/string-util');
const Logger = require('../util/logger');
@ -12,7 +12,7 @@ const SettingsStore = {
return `${key}.json`;
},
load: function(key, callback, error) {
load: function(key, callback) {
try {
if (Launcher) {
const settingsFile = Launcher.getUserDataPath(this.fileName(key));
@ -20,7 +20,9 @@ const SettingsStore = {
if (exists) {
Launcher.readFile(settingsFile, data => {
callback(JSON.parse(data));
}, error);
}, err => { // eslint-disable-line handle-callback-err
callback(undefined);
});
}
});
} else {
@ -32,13 +34,14 @@ const SettingsStore = {
}
},
save: function(key, data, callback, error) {
save: function(key, data, callback) {
try {
if (Launcher) {
const settingsFile = Launcher.getUserDataPath(this.fileName(key));
Launcher.writeFile(settingsFile, JSON.stringify(data), callback, error);
Launcher.writeFile(settingsFile, JSON.stringify(data), callback, callback);
} else if (typeof localStorage !== 'undefined') {
localStorage[StringUtil.camelCase(key)] = JSON.stringify(data);
callback && callback();
}
} catch (e) {
logger.error(`Error saving ${key}`, e);

View File

@ -46,7 +46,10 @@ const AppSettingsModel = Backbone.Model.extend({
},
load: function() {
const data = SettingsStore.load('app-settings');
SettingsStore.load('app-settings', this.onLoaded.bind(this));
},
onLoaded: function(data) {
if (data) {
this.upgrade(data);
}

View File

@ -11,7 +11,10 @@ const RuntimeDataModel = Backbone.Model.extend({
},
load: function() {
const data = SettingsStore.load('runtime-data');
SettingsStore.load('runtime-data', this.onLoaded.bind(this));
},
onLoaded: function(data) {
if (data) {
this.set(data, {silent: true});
}

View File

@ -21,7 +21,10 @@ const UpdateModel = Backbone.Model.extend({
},
load: function() {
const data = SettingsStore.load('update-info');
SettingsStore.load('update-info', this.onLoaded.bind(this));
},
onLoaded: function(data) {
if (data) {
try {
_.each(data, (val, key) => {

View File

@ -2,13 +2,24 @@
const Launcher = require('../comp/launcher');
const Storage = {
const FileStorage = {
file: require('./storage-file'),
dropbox: require('./storage-dropbox'),
webdav: require('./storage-webdav'),
gdrive: require('./storage-gdrive'),
onedrive: require('./storage-onedrive'),
cache: Launcher ? require('./storage-file-cache') : require('./storage-cache')
};
const ThirdPartyStorage = {
dropbox: require('./storage-dropbox'),
webdav: require('./storage-webdav'),
gdrive: require('./storage-gdrive'),
onedrive: require('./storage-onedrive')
};
let Storage = [];
if (window.cordova) {
Storage = FileStorage;
} else {
Storage = FileStorage.concat(ThirdPartyStorage);
}
module.exports = Storage;