- {{ i18n.ts.copy }}
+ {{ i18n.ts.copy }}
@@ -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
();
+export const pluginLogs = ref(new Map());
export async function install(plugin: Plugin): Promise {
// 後方互換性のため
@@ -22,21 +24,27 @@ export async function install(plugin: Plugin): Promise {
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 {
@@ -92,6 +100,7 @@ function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Record