2015-10-17 23:49:24 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-11-04 20:59:22 +01:00
|
|
|
var Backbone = require('backbone'),
|
|
|
|
Launcher = require('../comp/launcher');
|
|
|
|
|
|
|
|
var FileName = 'app-settings.json';
|
2015-10-17 23:49:24 +02:00
|
|
|
|
|
|
|
var AppSettingsModel = Backbone.Model.extend({
|
|
|
|
defaults: {
|
2015-10-19 23:24:32 +02:00
|
|
|
theme: 'd',
|
2015-11-11 19:58:29 +01:00
|
|
|
expandGroups: true,
|
|
|
|
listViewWidth: null,
|
2015-11-11 20:26:04 +01:00
|
|
|
menuViewWidth: null,
|
2015-10-25 20:26:33 +01:00
|
|
|
autoUpdate: true
|
2015-10-17 23:49:24 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function() {
|
2015-10-24 21:06:44 +02:00
|
|
|
this.listenTo(this, 'change', this.save);
|
2015-10-17 23:49:24 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
load: function() {
|
2015-11-04 20:59:22 +01:00
|
|
|
try {
|
|
|
|
var data;
|
|
|
|
if (Launcher) {
|
|
|
|
data = JSON.parse(Launcher.readFile(Launcher.getUserDataPath(FileName), 'utf8'));
|
|
|
|
} else if (typeof localStorage !== 'undefined' && localStorage.appSettings) {
|
|
|
|
data = JSON.parse(localStorage.appSettings);
|
|
|
|
}
|
|
|
|
if (data) {
|
|
|
|
this.set(data, {silent: true});
|
|
|
|
}
|
2015-11-04 21:23:55 +01:00
|
|
|
} catch (e) {
|
|
|
|
console.error('Error loading settings', e);
|
2015-10-17 23:49:24 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
save: function() {
|
2015-11-04 20:59:22 +01:00
|
|
|
try {
|
|
|
|
if (Launcher) {
|
|
|
|
Launcher.writeFile(Launcher.getUserDataPath(FileName), JSON.stringify(this.attributes));
|
|
|
|
} else if (typeof localStorage !== 'undefined') {
|
|
|
|
localStorage.appSettings = JSON.stringify(this.attributes);
|
|
|
|
}
|
2015-11-04 21:23:55 +01:00
|
|
|
} catch (e) {
|
|
|
|
console.error('Error saving settings', e);
|
2015-10-17 23:49:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
AppSettingsModel.instance = new AppSettingsModel();
|
|
|
|
AppSettingsModel.instance.load();
|
|
|
|
|
|
|
|
module.exports = AppSettingsModel;
|