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/plugin.ts | |
| 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/plugin.ts')
| -rw-r--r-- | packages/frontend/src/plugin.ts | 25 |
1 files changed, 17 insertions, 8 deletions
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 { |