2016-07-16 05:29:42 +08:00
|
|
|
import ko from 'ko';
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { StorageResultType, Notification } from 'Common/Enums';
|
|
|
|
import { getNotification } from 'Common/Translator';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { showScreenPopup } from 'Knoin/Knoin';
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
import PluginStore from 'Stores/Admin/Plugin';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/Admin/Fetch';
|
2015-05-03 04:22:32 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
class PluginsAdminSettings {
|
2016-07-16 05:29:42 +08:00
|
|
|
constructor() {
|
2020-09-04 18:05:17 +08:00
|
|
|
this.enabledPlugins = ko.observable(!!rl.settings.get('EnabledPlugins'));
|
2015-11-19 01:32:29 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.plugins = PluginStore.plugins;
|
|
|
|
this.pluginsError = PluginStore.plugins.error;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.visibility = ko.computed(() => (PluginStore.plugins.loading() ? 'visible' : 'hidden'));
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-07-20 21:47:33 +08:00
|
|
|
this.onPluginLoadRequest = this.onPluginLoadRequest.bind(this);
|
|
|
|
this.onPluginDisableRequest = this.onPluginDisableRequest.bind(this);
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
disablePlugin(plugin) {
|
|
|
|
plugin.disabled(!plugin.disabled());
|
|
|
|
Remote.pluginDisable(this.onPluginDisableRequest, plugin.name, plugin.disabled());
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
configurePlugin(plugin) {
|
|
|
|
Remote.plugin(this.onPluginLoadRequest, plugin.name);
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
onBuild(oDom) {
|
2020-08-30 16:30:50 +08:00
|
|
|
oDom.addEventListener('click', event => {
|
|
|
|
let el = event.target.closestWithin('.e-item .configure-plugin-action', oDom);
|
|
|
|
el && ko.dataFor(el) && this.configurePlugin(ko.dataFor(el));
|
|
|
|
|
|
|
|
el = event.target.closestWithin('.e-item .disabled-plugin', oDom);
|
|
|
|
el && ko.dataFor(el) && this.disablePlugin(ko.dataFor(el));
|
|
|
|
});
|
2016-07-16 05:29:42 +08:00
|
|
|
|
|
|
|
this.enabledPlugins.subscribe((value) => {
|
|
|
|
Remote.saveAdminConfig(null, {
|
2020-07-30 03:49:41 +08:00
|
|
|
'EnabledPlugins': value ? '1' : '0'
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
onShow() {
|
|
|
|
PluginStore.plugins.error('');
|
2020-09-15 15:29:25 +08:00
|
|
|
rl.app.reloadPluginList();
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
onPluginLoadRequest(result, data) {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (StorageResultType.Success === result && data && data.Result) {
|
2016-07-16 05:29:42 +08:00
|
|
|
showScreenPopup(require('View/Popup/Plugin'), [data.Result]);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
onPluginDisableRequest(result, data) {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (StorageResultType.Success === result && data) {
|
|
|
|
if (!data.Result && data.ErrorCode) {
|
2020-07-28 23:20:14 +08:00
|
|
|
if (Notification.UnsupportedPluginPackage === data.ErrorCode && data.ErrorMessage && data.ErrorMessage) {
|
2016-07-16 05:29:42 +08:00
|
|
|
PluginStore.plugins.error(data.ErrorMessage);
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2016-07-16 05:29:42 +08:00
|
|
|
PluginStore.plugins.error(getNotification(data.ErrorCode));
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-15 15:29:25 +08:00
|
|
|
rl.app.reloadPluginList();
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
export { PluginsAdminSettings, PluginsAdminSettings as default };
|