diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2020-07-28 19:02:28 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2020-07-28 19:02:28 +0900 |
| commit | 595ad04ddbbf9ff9fc6842f345d4738a9f1cc150 (patch) | |
| tree | ffa14aa146b4831d0c0089598fe8bce5a476c0f2 /src/client | |
| parent | enhance(client): Use tab component for page list (diff) | |
| download | sharkey-595ad04ddbbf9ff9fc6842f345d4738a9f1cc150.tar.gz sharkey-595ad04ddbbf9ff9fc6842f345d4738a9f1cc150.tar.bz2 sharkey-595ad04ddbbf9ff9fc6842f345d4738a9f1cc150.zip | |
feat(client): プラグインを無効にできるように
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/init.ts | 2 | ||||
| -rw-r--r-- | src/client/pages/preferences/plugins.vue | 16 | ||||
| -rw-r--r-- | src/client/scripts/aiscript/api.ts | 17 | ||||
| -rw-r--r-- | src/client/store.ts | 14 |
4 files changed, 44 insertions, 5 deletions
diff --git a/src/client/init.ts b/src/client/init.ts index b819a16e5a..d76e94c5a3 100644 --- a/src/client/init.ts +++ b/src/client/init.ts @@ -242,7 +242,7 @@ os.init(async () => { //store.commit('instance/set', ); }); - for (const plugin of store.state.deviceUser.plugins) { + for (const plugin of store.state.deviceUser.plugins.filter(p => p.active)) { console.info('Plugin installed:', plugin.name, 'v' + plugin.version); const aiscript = new AiScript(createPluginEnv(app, { diff --git a/src/client/pages/preferences/plugins.vue b/src/client/pages/preferences/plugins.vue index 8bd522ddc6..b61b2c8daf 100644 --- a/src/client/pages/preferences/plugins.vue +++ b/src/client/pages/preferences/plugins.vue @@ -18,6 +18,9 @@ <option v-for="x in $store.state.deviceUser.plugins" :value="x.id" :key="x.id">{{ x.name }}</option> </mk-select> <template v-if="selectedPlugin"> + <div style="margin: -8px 0 8px 0;"> + <mk-switch :value="selectedPlugin.active" @change="changeActive(selectedPlugin, $event)">{{ $t('makeActive') }}</mk-switch> + </div> <div class="_keyValue"> <div>{{ $t('version') }}:</div> <div>{{ selectedPlugin.version }}</div> @@ -49,6 +52,7 @@ import MkButton from '../../components/ui/button.vue'; import MkTextarea from '../../components/ui/textarea.vue'; import MkSelect from '../../components/ui/select.vue'; import MkInfo from '../../components/ui/info.vue'; +import MkSwitch from '../../components/ui/switch.vue'; export default Vue.extend({ components: { @@ -56,6 +60,7 @@ export default Vue.extend({ MkTextarea, MkSelect, MkInfo, + MkSwitch, }, data() { @@ -174,6 +179,17 @@ export default Vue.extend({ this.$nextTick(() => { location.reload(); }); + }, + + changeActive(plugin, active) { + this.$store.commit('deviceUser/changePluginActive', { + id: plugin.id, + active: active + }); + + this.$nextTick(() => { + location.reload(); + }); } }, }); diff --git a/src/client/scripts/aiscript/api.ts b/src/client/scripts/aiscript/api.ts index 9ca16df494..bfbfe8d59d 100644 --- a/src/client/scripts/aiscript/api.ts +++ b/src/client/scripts/aiscript/api.ts @@ -14,9 +14,9 @@ export function createAiScriptEnv(vm, opts) { text: text.value, }); }), - 'Mk:confirm': values.FN_NATIVE(async ([title, text]) => { + 'Mk:confirm': values.FN_NATIVE(async ([title, text, type]) => { const confirm = await vm.$root.dialog({ - type: 'warning', + type: type ? type.value : 'question', showCancelButton: true, title: title.value, text: text.value, @@ -44,12 +44,13 @@ export function createAiScriptEnv(vm, opts) { export function createPluginEnv(vm, opts) { const config = new Map(); - for (const [k, v] of Object.entries(opts.plugin.config)) { + for (const [k, v] of Object.entries(opts.plugin.config || {})) { config.set(k, jsToVal(opts.plugin.configData[k] || v.default)); } return { ...createAiScriptEnv(vm, { ...opts, token: opts.plugin.token }), + //#region Deprecated 'Mk:register_post_form_action': values.FN_NATIVE(([title, handler]) => { vm.$store.commit('registerPostFormAction', { pluginId: opts.plugin.id, title: title.value, handler }); }), @@ -59,6 +60,16 @@ export function createPluginEnv(vm, opts) { 'Mk:register_note_action': values.FN_NATIVE(([title, handler]) => { vm.$store.commit('registerNoteAction', { pluginId: opts.plugin.id, title: title.value, handler }); }), + //#endregion + 'Plugin:register_post_form_action': values.FN_NATIVE(([title, handler]) => { + vm.$store.commit('registerPostFormAction', { pluginId: opts.plugin.id, title: title.value, handler }); + }), + 'Plugin:register_user_action': values.FN_NATIVE(([title, handler]) => { + vm.$store.commit('registerUserAction', { pluginId: opts.plugin.id, title: title.value, handler }); + }), + 'Plugin:register_note_action': values.FN_NATIVE(([title, handler]) => { + vm.$store.commit('registerNoteAction', { pluginId: opts.plugin.id, title: title.value, handler }); + }), 'Plugin:config': values.OBJ(config), }; } diff --git a/src/client/store.ts b/src/client/store.ts index 2bf44088af..67dd6ea06a 100644 --- a/src/client/store.ts +++ b/src/client/store.ts @@ -45,7 +45,14 @@ export const defaultDeviceUserSettings = { columns: [], layout: [], }, - plugins: [], + plugins: [] as { + id: string; + name: string; + active: boolean; + configData: Record<string, any>; + token: string; + ast: any[]; + }[], }; export const defaultDeviceSettings = { @@ -591,6 +598,7 @@ export default () => new Vuex.Store({ installPlugin(state, { meta, ast, token }) { state.plugins.push({ ...meta, + active: true, configData: {}, token: token, ast: ast @@ -604,6 +612,10 @@ export default () => new Vuex.Store({ configPlugin(state, { id, config }) { state.plugins.find(p => p.id === id).configData = config; }, + + changePluginActive(state, { id, active }) { + state.plugins.find(p => p.id === id).active = active; + }, } }, |