diff options
| author | FineArchs <133759614+FineArchs@users.noreply.github.com> | 2024-03-13 22:38:26 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-13 22:38:26 +0900 |
| commit | 88d47ab0245bf5990096e59ced280f62cb7e7a60 (patch) | |
| tree | 6cbbdb3707d10770bf729f5fe82be71e4fef1024 /packages/frontend/src | |
| parent | chore: add missing SPDX ID and workflow check (#13570) (diff) | |
| download | sharkey-88d47ab0245bf5990096e59ced280f62cb7e7a60.tar.gz sharkey-88d47ab0245bf5990096e59ced280f62cb7e7a60.tar.bz2 sharkey-88d47ab0245bf5990096e59ced280f62cb7e7a60.zip | |
プラグインの簡易的なログを表示する機能 (#13564)
* add plugin logging
* change variable name
* Update plugin.ts
* Update CHANGELOG.md
Diffstat (limited to 'packages/frontend/src')
| -rw-r--r-- | packages/frontend/src/pages/settings/plugin.vue | 20 | ||||
| -rw-r--r-- | packages/frontend/src/plugin.ts | 25 |
2 files changed, 34 insertions, 11 deletions
diff --git a/packages/frontend/src/pages/settings/plugin.vue b/packages/frontend/src/pages/settings/plugin.vue index 0ab75b95a2..9804454e66 100644 --- a/packages/frontend/src/pages/settings/plugin.vue +++ b/packages/frontend/src/pages/settings/plugin.vue @@ -42,12 +42,25 @@ SPDX-License-Identifier: AGPL-3.0-only </div> <MkFolder> + <template #icon><i class="ti ti-terminal-2"></i></template> + <template #label>{{ i18n.ts._plugin.viewLog }}</template> + + <div class="_gaps_s"> + <div class="_buttons"> + <MkButton inline @click="copy(pluginLogs.get(plugin.id)?.join('\n'))"><i class="ti ti-copy"></i> {{ i18n.ts.copy }}</MkButton> + </div> + + <MkCode :code="pluginLogs.get(plugin.id)?.join('\n') ?? ''"/> + </div> + </MkFolder> + + <MkFolder> <template #icon><i class="ti ti-code"></i></template> <template #label>{{ i18n.ts._plugin.viewSource }}</template> <div class="_gaps_s"> <div class="_buttons"> - <MkButton inline @click="copy(plugin)"><i class="ti ti-copy"></i> {{ i18n.ts.copy }}</MkButton> + <MkButton inline @click="copy(plugin.src)"><i class="ti ti-copy"></i> {{ i18n.ts.copy }}</MkButton> </div> <MkCode :code="plugin.src ?? ''" lang="is"/> @@ -74,6 +87,7 @@ import { ColdDeviceStorage } from '@/store.js'; import { unisonReload } from '@/scripts/unison-reload.js'; import { i18n } from '@/i18n.js'; import { definePageMetadata } from '@/scripts/page-metadata.js'; +import { pluginLogs } from '@/plugin.js'; const plugins = ref(ColdDeviceStorage.get('plugins')); @@ -87,8 +101,8 @@ async function uninstall(plugin) { }); } -function copy(plugin) { - copyToClipboard(plugin.src ?? ''); +function copy(text) { + copyToClipboard(text ?? ''); os.success(); } diff --git a/packages/frontend/src/plugin.ts b/packages/frontend/src/plugin.ts index 743cadc36a..81233a5a5e 100644 --- a/packages/frontend/src/plugin.ts +++ b/packages/frontend/src/plugin.ts @@ -3,6 +3,7 @@ * SPDX-License-Identifier: AGPL-3.0-only */ +import { ref } from 'vue'; import { Interpreter, Parser, utils, values } from '@syuilo/aiscript'; import { aiScriptReadline, createAiScriptEnv } from '@/scripts/aiscript/api.js'; import { inputText } from '@/os.js'; @@ -10,6 +11,7 @@ import { Plugin, noteActions, notePostInterruptors, noteViewInterruptors, postFo const parser = new Parser(); const pluginContexts = new Map<string, Interpreter>(); +export const pluginLogs = ref(new Map<string, string[]>()); export async function install(plugin: Plugin): Promise<void> { // 後方互換性のため @@ -22,21 +24,27 @@ export async function install(plugin: Plugin): Promise<void> { in: aiScriptReadline, out: (value): void => { console.log(value); + pluginLogs.value.get(plugin.id).push(utils.reprValue(value)); }, log: (): void => { }, + err: (err): void => { + pluginLogs.value.get(plugin.id).push(`${err}`); + throw err; // install時のtry-catchに反応させる + }, }); initPlugin({ plugin, aiscript }); - try { - await aiscript.exec(parser.parse(plugin.src)); - } catch (err) { - console.error('Plugin install failed:', plugin.name, 'v' + plugin.version); - return; - } - - console.info('Plugin installed:', plugin.name, 'v' + plugin.version); + aiscript.exec(parser.parse(plugin.src)).then( + () => { + console.info('Plugin installed:', plugin.name, 'v' + plugin.version); + }, + (err) => { + console.error('Plugin install failed:', plugin.name, 'v' + plugin.version); + throw err; + }, + ); } function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Record<string, values.Value> { @@ -92,6 +100,7 @@ function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Record<s function initPlugin({ plugin, aiscript }): void { pluginContexts.set(plugin.id, aiscript); + pluginLogs.value.set(plugin.id, []); } function registerPostFormAction({ pluginId, title, handler }): void { |