2016-05-13 18:09:12 +02:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
2016-05-16 17:41:39 +02:00
|
|
|
angular.module('ariaNg').factory('ariaNgSettingService', ['$location', '$translate', 'amMoment', 'localStorageService', 'ariaNgDefaultOptions', function ($location, $translate, amMoment, localStorageService, ariaNgDefaultOptions) {
|
|
|
|
var getDefaultJsonRpcHost = function () {
|
|
|
|
var rpcHost = $location.$$host + ':6800';
|
|
|
|
return rpcHost;
|
|
|
|
};
|
|
|
|
|
2016-05-13 18:09:12 +02:00
|
|
|
var setOptions = function (options) {
|
|
|
|
return localStorageService.set('Options', options);
|
|
|
|
};
|
|
|
|
|
|
|
|
var getOptions = function () {
|
|
|
|
var options = localStorageService.get('Options');
|
|
|
|
|
|
|
|
if (!options) {
|
|
|
|
options = angular.extend({}, ariaNgDefaultOptions);
|
|
|
|
setOptions(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
|
|
|
};
|
|
|
|
|
|
|
|
var getOption = function (key) {
|
2016-05-16 15:32:15 +02:00
|
|
|
var options = getOptions();
|
|
|
|
|
|
|
|
if (angular.isUndefined(options[key])) {
|
|
|
|
options[key] = ariaNgDefaultOptions[key];
|
|
|
|
setOptions(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
return options[key];
|
2016-05-13 18:09:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var setOption = function (key, value) {
|
|
|
|
var options = getOptions();
|
|
|
|
options[key] = value;
|
|
|
|
|
|
|
|
setOptions(options);
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
2016-05-16 17:41:39 +02:00
|
|
|
getAllOptions: function () {
|
|
|
|
var options = angular.extend({}, ariaNgDefaultOptions, getOptions());
|
|
|
|
|
|
|
|
if (!options.aria2RpcHost) {
|
|
|
|
options.aria2RpcHost = getDefaultJsonRpcHost();
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
2016-05-13 18:09:12 +02:00
|
|
|
},
|
2016-05-16 17:41:39 +02:00
|
|
|
setAllOptions: function (options) {
|
|
|
|
setOptions(options);
|
|
|
|
},
|
|
|
|
getLanguage: function () {
|
|
|
|
return getOption('language');
|
|
|
|
},
|
|
|
|
setLanguage: function (value) {
|
|
|
|
setOption('language', value);
|
2016-05-13 18:09:12 +02:00
|
|
|
$translate.use(value);
|
2016-05-16 17:41:39 +02:00
|
|
|
amMoment.changeLocale(value);
|
2016-05-13 18:09:12 +02:00
|
|
|
},
|
2016-05-16 15:28:23 +02:00
|
|
|
getJsonRpcUrl: function (protocol) {
|
2016-05-13 18:09:12 +02:00
|
|
|
var rpcHost = getOption('aria2RpcHost');
|
|
|
|
|
|
|
|
if (!rpcHost) {
|
2016-05-16 17:41:39 +02:00
|
|
|
rpcHost = getDefaultJsonRpcHost();
|
2016-05-13 18:09:12 +02:00
|
|
|
}
|
|
|
|
|
2016-05-16 15:28:23 +02:00
|
|
|
return protocol + '://' + rpcHost + '/jsonrpc';
|
|
|
|
},
|
2016-05-16 17:41:39 +02:00
|
|
|
setJsonRpcHost: function (value) {
|
|
|
|
setOption('aria2RpcHost', value);
|
|
|
|
},
|
2016-05-16 15:28:23 +02:00
|
|
|
getProtocol: function () {
|
|
|
|
return getOption('protocol');
|
|
|
|
},
|
|
|
|
setProtocol: function (value) {
|
|
|
|
setOption('protocol', value);
|
2016-05-13 18:09:12 +02:00
|
|
|
},
|
|
|
|
getGlobalStatRefreshInterval: function () {
|
|
|
|
return getOption('globalStatRefreshInterval');
|
|
|
|
},
|
|
|
|
getDownloadTaskRefreshInterval: function () {
|
|
|
|
return getOption('downloadTaskRefreshInterval');
|
|
|
|
},
|
|
|
|
getDisplayOrder: function () {
|
|
|
|
var value = getOption('displayOrder');
|
2016-05-16 15:28:23 +02:00
|
|
|
|
2016-05-13 18:09:12 +02:00
|
|
|
if (!value) {
|
|
|
|
value = 'default';
|
|
|
|
}
|
2016-05-16 15:28:23 +02:00
|
|
|
|
2016-05-13 18:09:12 +02:00
|
|
|
return value;
|
|
|
|
},
|
|
|
|
setDisplayOrder: function (value) {
|
|
|
|
setOption('displayOrder', value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}]);
|
|
|
|
})();
|