diff --git a/packages/frontend/src/components/MkCode.core.vue b/packages/frontend/src/components/MkCode.core.vue
index 2fc8c6591e..948419130e 100644
--- a/packages/frontend/src/components/MkCode.core.vue
+++ b/packages/frontend/src/components/MkCode.core.vue
@@ -74,10 +74,8 @@ watch(() => props.lang, (to) => {
diff --git a/packages/frontend/src/pages/settings/theme.install.vue b/packages/frontend/src/pages/settings/theme.install.vue
index c731f343e2..92f4893f1a 100644
--- a/packages/frontend/src/pages/settings/theme.install.vue
+++ b/packages/frontend/src/pages/settings/theme.install.vue
@@ -10,8 +10,8 @@ SPDX-License-Identifier: AGPL-3.0-only
- previewTheme(installThemeCode)"> {{ i18n.ts.preview }}
- install(installThemeCode)"> {{ i18n.ts.install }}
+ previewTheme(installThemeCode)"> {{ i18n.ts.preview }}
+ install(installThemeCode)"> {{ i18n.ts.install }}
@@ -24,7 +24,9 @@ import { parseThemeCode, previewTheme, installTheme } from '@/theme.js';
import * as os from '@/os.js';
import { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/utility/page-metadata.js';
+import { useRouter } from '@/router/supplier.js';
+const router = useRouter();
const installThemeCode = ref(null);
async function install(code: string): Promise {
@@ -35,6 +37,8 @@ async function install(code: string): Promise {
type: 'success',
text: i18n.tsx._theme.installed({ name: theme.name }),
});
+ installThemeCode.value = null;
+ router.push('/settings/theme');
} catch (err) {
switch (err.message.toLowerCase()) {
case 'this theme is already installed':
diff --git a/packages/frontend/src/plugin.ts b/packages/frontend/src/plugin.ts
index 613e3a9df6..5e33d196c3 100644
--- a/packages/frontend/src/plugin.ts
+++ b/packages/frontend/src/plugin.ts
@@ -131,6 +131,10 @@ export async function installPlugin(code: string, meta?: AiScriptPluginMeta) {
realMeta = meta;
}
+ if (prefer.s.plugins.some(x => x.name === realMeta.name)) {
+ throw new Error('Plugin already installed');
+ }
+
const installId = uuid();
const plugin = {
@@ -161,8 +165,14 @@ export async function uninstallPlugin(plugin: Plugin) {
}
}
-const pluginContexts = new Map();
-export const pluginLogs = ref(new Map());
+const pluginContexts = new Map();
+
+export const pluginLogs = ref(new Map());
type HandlerDef = {
post_form_action: {
@@ -197,6 +207,11 @@ type PluginHandler = {
let pluginHandlers: PluginHandler[] = [];
function addPluginHandler(installId: Plugin['installId'], type: K, ctx: PluginHandler['ctx']) {
+ pluginLogs.value.get(installId)!.push({
+ at: Date.now(),
+ isSystem: true,
+ message: `Handler registered: ${type}`,
+ });
pluginHandlers.push({ pluginInstallId: installId, type, ctx });
}
@@ -215,6 +230,19 @@ async function launchPlugin(id: Plugin['installId']): Promise {
// 後方互換性のため
if (plugin.src == null) return;
+ pluginLogs.value.set(plugin.installId, []);
+
+ function systemLog(message: string, isError = false): void {
+ pluginLogs.value.get(plugin.installId)?.push({
+ at: Date.now(),
+ isSystem: true,
+ message,
+ isError,
+ });
+ }
+
+ systemLog('Starting plugin...');
+
await authorizePlugin(plugin);
const aiscript = new Interpreter(createPluginEnv({
@@ -223,26 +251,33 @@ async function launchPlugin(id: Plugin['installId']): Promise {
}), {
in: aiScriptReadline,
out: (value): void => {
- console.log(value);
- pluginLogs.value.get(plugin.installId).push(utils.reprValue(value));
+ pluginLogs.value.get(plugin.installId)!.push({
+ at: Date.now(),
+ message: utils.reprValue(value),
+ });
},
log: (): void => {
},
err: (err): void => {
- pluginLogs.value.get(plugin.installId).push(`${err}`);
+ pluginLogs.value.get(plugin.installId)!.push({
+ at: Date.now(),
+ message: `${err}`,
+ isError: true,
+ });
throw err; // install時のtry-catchに反応させる
},
});
pluginContexts.set(plugin.installId, aiscript);
- pluginLogs.value.set(plugin.installId, []);
aiscript.exec(parser.parse(plugin.src)).then(
() => {
console.info('Plugin installed:', plugin.name, 'v' + plugin.version);
+ systemLog('Plugin started');
},
(err) => {
console.error('Plugin install failed:', plugin.name, 'v' + plugin.version);
+ systemLog(`${err}`, true);
throw err;
},
);
@@ -300,16 +335,15 @@ function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Record(fn: (ctx: Interpreter) => T): T {
- console.log('withContext', id);
const ctx = pluginContexts.get(id);
if (!ctx) throw new Error('Plugin context not found');
return fn(ctx);
}
- return {
+ const env: Record = {
...createAiScriptEnv({ ...opts, token: store.state.pluginTokens[id] }),
- 'Plugin:register_post_form_action': values.FN_NATIVE(([title, handler]) => {
+ 'Plugin:register:post_form_action': values.FN_NATIVE(([title, handler]) => {
utils.assertString(title);
utils.assertFunction(handler);
addPluginHandler(id, 'post_form_action', {
@@ -325,7 +359,7 @@ function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Record {
+ 'Plugin:register:user_action': values.FN_NATIVE(([title, handler]) => {
utils.assertString(title);
utils.assertFunction(handler);
addPluginHandler(id, 'user_action', {
@@ -336,7 +370,7 @@ function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Record {
+ 'Plugin:register:note_action': values.FN_NATIVE(([title, handler]) => {
utils.assertString(title);
utils.assertFunction(handler);
addPluginHandler(id, 'note_action', {
@@ -347,7 +381,7 @@ function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Record {
+ 'Plugin:register:note_view_interruptor': values.FN_NATIVE(([handler]) => {
utils.assertFunction(handler);
addPluginHandler(id, 'note_view_interruptor', {
handler: withContext(ctx => async (note) => {
@@ -356,7 +390,7 @@ function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Record {
+ 'Plugin:register:note_post_interruptor': values.FN_NATIVE(([handler]) => {
utils.assertFunction(handler);
addPluginHandler(id, 'note_post_interruptor', {
handler: withContext(ctx => async (note) => {
@@ -365,7 +399,7 @@ function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Record {
+ 'Plugin:register:page_view_interruptor': values.FN_NATIVE(([handler]) => {
utils.assertFunction(handler);
addPluginHandler(id, 'page_view_interruptor', {
handler: withContext(ctx => async (page) => {
@@ -381,6 +415,16 @@ function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Record(type: K): HandlerDef[K][] {