Remove settings.initialize/uninitialize
this simplifies the startup sequence
This commit is contained in:
+16
-22
@@ -3,9 +3,6 @@
|
||||
exports = module.exports = {
|
||||
SettingsError: SettingsError,
|
||||
|
||||
initialize: initialize,
|
||||
uninitialize: uninitialize,
|
||||
|
||||
getAppAutoupdatePattern: getAppAutoupdatePattern,
|
||||
setAppAutoupdatePattern: setAppAutoupdatePattern,
|
||||
|
||||
@@ -57,7 +54,8 @@ exports = module.exports = {
|
||||
TIME_ZONE_KEY: 'time_zone',
|
||||
CLOUDRON_NAME_KEY: 'cloudron_name',
|
||||
|
||||
events: null
|
||||
on: on,
|
||||
removeListener: removeListener
|
||||
};
|
||||
|
||||
var addons = require('./addons.js'),
|
||||
@@ -100,6 +98,8 @@ var gDefaults = (function () {
|
||||
return result;
|
||||
})();
|
||||
|
||||
let gEvents = new (require('events').EventEmitter)();
|
||||
|
||||
function SettingsError(reason, errorOrMessage) {
|
||||
assert.strictEqual(typeof reason, 'string');
|
||||
assert(errorOrMessage instanceof Error || typeof errorOrMessage === 'string' || typeof errorOrMessage === 'undefined');
|
||||
@@ -124,18 +124,12 @@ SettingsError.EXTERNAL_ERROR = 'External Error';
|
||||
SettingsError.NOT_FOUND = 'Not Found';
|
||||
SettingsError.BAD_FIELD = 'Bad Field';
|
||||
|
||||
function initialize(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
exports.events = new (require('events').EventEmitter)();
|
||||
callback();
|
||||
function on(key, handler) {
|
||||
gEvents.on(key, handler);
|
||||
}
|
||||
|
||||
function uninitialize(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
exports.events = null;
|
||||
callback();
|
||||
function removeListener(key, handler) {
|
||||
gEvents.removeListener(key, handler);
|
||||
}
|
||||
|
||||
function setAppAutoupdatePattern(pattern, callback) {
|
||||
@@ -150,7 +144,7 @@ function setAppAutoupdatePattern(pattern, callback) {
|
||||
settingsdb.set(exports.APP_AUTOUPDATE_PATTERN_KEY, pattern, function (error) {
|
||||
if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, error));
|
||||
|
||||
exports.events.emit(exports.APP_AUTOUPDATE_PATTERN_KEY, pattern);
|
||||
gEvents.emit(exports.APP_AUTOUPDATE_PATTERN_KEY, pattern);
|
||||
|
||||
return callback(null);
|
||||
});
|
||||
@@ -179,7 +173,7 @@ function setBoxAutoupdatePattern(pattern, callback) {
|
||||
settingsdb.set(exports.BOX_AUTOUPDATE_PATTERN_KEY, pattern, function (error) {
|
||||
if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, error));
|
||||
|
||||
exports.events.emit(exports.BOX_AUTOUPDATE_PATTERN_KEY, pattern);
|
||||
gEvents.emit(exports.BOX_AUTOUPDATE_PATTERN_KEY, pattern);
|
||||
|
||||
return callback(null);
|
||||
});
|
||||
@@ -205,7 +199,7 @@ function setTimeZone(tz, callback) {
|
||||
settingsdb.set(exports.TIME_ZONE_KEY, tz, function (error) {
|
||||
if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, error));
|
||||
|
||||
exports.events.emit(exports.TIME_ZONE_KEY, tz);
|
||||
gEvents.emit(exports.TIME_ZONE_KEY, tz);
|
||||
|
||||
return callback(null);
|
||||
});
|
||||
@@ -244,7 +238,7 @@ function setCloudronName(name, callback) {
|
||||
settingsdb.set(exports.CLOUDRON_NAME_KEY, name, function (error) {
|
||||
if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, error));
|
||||
|
||||
exports.events.emit(exports.CLOUDRON_NAME_KEY, name);
|
||||
gEvents.emit(exports.CLOUDRON_NAME_KEY, name);
|
||||
|
||||
return callback(null);
|
||||
});
|
||||
@@ -293,7 +287,7 @@ function setDynamicDnsConfig(enabled, callback) {
|
||||
settingsdb.set(exports.DYNAMIC_DNS_KEY, enabled ? 'enabled' : '', function (error) {
|
||||
if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, error));
|
||||
|
||||
exports.events.emit(exports.DYNAMIC_DNS_KEY, enabled);
|
||||
gEvents.emit(exports.DYNAMIC_DNS_KEY, enabled);
|
||||
|
||||
return callback(null);
|
||||
});
|
||||
@@ -324,7 +318,7 @@ function setBackupConfig(backupConfig, callback) {
|
||||
settingsdb.set(exports.BACKUP_CONFIG_KEY, JSON.stringify(backupConfig), function (error) {
|
||||
if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, error));
|
||||
|
||||
exports.events.emit(exports.BACKUP_CONFIG_KEY, backupConfig);
|
||||
gEvents.emit(exports.BACKUP_CONFIG_KEY, backupConfig);
|
||||
|
||||
callback(null);
|
||||
});
|
||||
@@ -349,7 +343,7 @@ function setEmailDigest(enabled, callback) {
|
||||
settingsdb.set(exports.EMAIL_DIGEST, enabled ? 'enabled' : '', function (error) {
|
||||
if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, error));
|
||||
|
||||
exports.events.emit(exports.EMAIL_DIGEST, enabled);
|
||||
gEvents.emit(exports.EMAIL_DIGEST, enabled);
|
||||
|
||||
callback(null);
|
||||
});
|
||||
@@ -422,7 +416,7 @@ function setAppstoreConfig(appstoreConfig, callback) {
|
||||
settingsdb.set(exports.APPSTORE_CONFIG_KEY, JSON.stringify(data), function (error) {
|
||||
if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, error));
|
||||
|
||||
exports.events.emit(exports.APPSTORE_CONFIG_KEY, appstoreConfig);
|
||||
gEvents.emit(exports.APPSTORE_CONFIG_KEY, appstoreConfig);
|
||||
|
||||
callback(null);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user