enhance(frontend): improve plugin management
This commit is contained in:
parent
6cefabc6b6
commit
0402866b43
|
@ -222,7 +222,7 @@ import { isEnabledUrlPreview } from '@/instance.js';
|
||||||
import { focusPrev, focusNext } from '@/utility/focus.js';
|
import { focusPrev, focusNext } from '@/utility/focus.js';
|
||||||
import { getAppearNote } from '@/utility/get-appear-note.js';
|
import { getAppearNote } from '@/utility/get-appear-note.js';
|
||||||
import { prefer } from '@/preferences.js';
|
import { prefer } from '@/preferences.js';
|
||||||
import { noteViewInterruptors } from '@/plugin.js';
|
import { getPluginHandlers } from '@/plugin.js';
|
||||||
|
|
||||||
const props = withDefaults(defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
note: Misskey.entities.Note;
|
note: Misskey.entities.Note;
|
||||||
|
@ -248,6 +248,7 @@ const currentClip = inject<Ref<Misskey.entities.Clip> | null>('currentClip', nul
|
||||||
const note = ref(deepClone(props.note));
|
const note = ref(deepClone(props.note));
|
||||||
|
|
||||||
// plugin
|
// plugin
|
||||||
|
const noteViewInterruptors = getPluginHandlers('note_view_interruptor');
|
||||||
if (noteViewInterruptors.length > 0) {
|
if (noteViewInterruptors.length > 0) {
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
let result: Misskey.entities.Note | null = deepClone(note.value);
|
let result: Misskey.entities.Note | null = deepClone(note.value);
|
||||||
|
|
|
@ -254,7 +254,7 @@ import MkButton from '@/components/MkButton.vue';
|
||||||
import { isEnabledUrlPreview } from '@/instance.js';
|
import { isEnabledUrlPreview } from '@/instance.js';
|
||||||
import { getAppearNote } from '@/utility/get-appear-note.js';
|
import { getAppearNote } from '@/utility/get-appear-note.js';
|
||||||
import { prefer } from '@/preferences.js';
|
import { prefer } from '@/preferences.js';
|
||||||
import { noteViewInterruptors } from '@/plugin.js';
|
import { getPluginHandlers } from '@/plugin.js';
|
||||||
|
|
||||||
const props = withDefaults(defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
note: Misskey.entities.Note;
|
note: Misskey.entities.Note;
|
||||||
|
@ -268,6 +268,7 @@ const inChannel = inject('inChannel', null);
|
||||||
const note = ref(deepClone(props.note));
|
const note = ref(deepClone(props.note));
|
||||||
|
|
||||||
// plugin
|
// plugin
|
||||||
|
const noteViewInterruptors = getPluginHandlers('note_view_interruptor');
|
||||||
if (noteViewInterruptors.length > 0) {
|
if (noteViewInterruptors.length > 0) {
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
let result: Misskey.entities.Note | null = deepClone(note.value);
|
let result: Misskey.entities.Note | null = deepClone(note.value);
|
||||||
|
|
|
@ -136,7 +136,7 @@ import { claimAchievement } from '@/utility/achievements.js';
|
||||||
import { emojiPicker } from '@/utility/emoji-picker.js';
|
import { emojiPicker } from '@/utility/emoji-picker.js';
|
||||||
import { mfmFunctionPicker } from '@/utility/mfm-function-picker.js';
|
import { mfmFunctionPicker } from '@/utility/mfm-function-picker.js';
|
||||||
import { prefer } from '@/preferences.js';
|
import { prefer } from '@/preferences.js';
|
||||||
import { notePostInterruptors, postFormActions } from '@/plugin.js';
|
import { getPluginHandlers } from '@/plugin.js';
|
||||||
|
|
||||||
const $i = signinRequired();
|
const $i = signinRequired();
|
||||||
|
|
||||||
|
@ -197,6 +197,7 @@ const showingOptions = ref(false);
|
||||||
const textAreaReadOnly = ref(false);
|
const textAreaReadOnly = ref(false);
|
||||||
const justEndedComposition = ref(false);
|
const justEndedComposition = ref(false);
|
||||||
const renoteTargetNote: ShallowRef<PostFormProps['renote'] | null> = shallowRef(props.renote);
|
const renoteTargetNote: ShallowRef<PostFormProps['renote'] | null> = shallowRef(props.renote);
|
||||||
|
const postFormActions = getPluginHandlers('post_form_action');
|
||||||
|
|
||||||
const draftKey = computed((): string => {
|
const draftKey = computed((): string => {
|
||||||
let key = props.channel ? `channel:${props.channel.id}` : '';
|
let key = props.channel ? `channel:${props.channel.id}` : '';
|
||||||
|
@ -823,6 +824,7 @@ async function post(ev?: MouseEvent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// plugin
|
// plugin
|
||||||
|
const notePostInterruptors = getPluginHandlers('note_post_interruptor');
|
||||||
if (notePostInterruptors.length > 0) {
|
if (notePostInterruptors.length > 0) {
|
||||||
for (const interruptor of notePostInterruptors) {
|
for (const interruptor of notePostInterruptors) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -122,7 +122,7 @@ import { getStaticImageUrl } from '@/utility/media-proxy.js';
|
||||||
import { copyToClipboard } from '@/utility/copy-to-clipboard.js';
|
import { copyToClipboard } from '@/utility/copy-to-clipboard.js';
|
||||||
import { useRouter } from '@/router/supplier.js';
|
import { useRouter } from '@/router/supplier.js';
|
||||||
import { prefer } from '@/preferences.js';
|
import { prefer } from '@/preferences.js';
|
||||||
import { pageViewInterruptors } from '@/plugin.js';
|
import { getPluginHandlers } from '@/plugin.js';
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
@ -151,6 +151,7 @@ function fetchPage() {
|
||||||
page.value = _page;
|
page.value = _page;
|
||||||
|
|
||||||
// plugin
|
// plugin
|
||||||
|
const pageViewInterruptors = getPluginHandlers('page_view_interruptor');
|
||||||
if (pageViewInterruptors.length > 0) {
|
if (pageViewInterruptors.length > 0) {
|
||||||
let result = deepClone(_page);
|
let result = deepClone(_page);
|
||||||
for (const interruptor of pageViewInterruptors) {
|
for (const interruptor of pageViewInterruptors) {
|
||||||
|
|
|
@ -28,14 +28,14 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
</template>
|
</template>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<div class="_buttons">
|
<div class="_buttons">
|
||||||
<MkButton v-if="plugin.config" inline @click="config(plugin)"><i class="ti ti-settings"></i> {{ i18n.ts.settings }}</MkButton>
|
<MkButton :disabled="!plugin.active" @click="reload(plugin)"><i class="ti ti-refresh"></i> {{ i18n.ts.reload }}</MkButton>
|
||||||
<MkButton inline danger @click="uninstall(plugin)"><i class="ti ti-trash"></i> {{ i18n.ts.uninstall }}</MkButton>
|
<MkButton danger @click="uninstall(plugin)"><i class="ti ti-trash"></i> {{ i18n.ts.uninstall }}</MkButton>
|
||||||
|
<MkButton v-if="plugin.config" style="margin-left: auto;" @click="config(plugin)"><i class="ti ti-settings"></i> {{ i18n.ts.settings }}</MkButton>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<div class="_gaps_m">
|
<div class="_gaps_m">
|
||||||
<div class="_gaps_s">
|
<div class="_gaps_s">
|
||||||
<span style="display: flex; align-items: center;"><b>{{ plugin.name }}</b><span style="margin-left: auto;">v{{ plugin.version }}</span></span>
|
|
||||||
<MkSwitch :modelValue="plugin.active" @update:modelValue="changeActive(plugin, $event)">{{ i18n.ts.makeActive }}</MkSwitch>
|
<MkSwitch :modelValue="plugin.active" @update:modelValue="changeActive(plugin, $event)">{{ i18n.ts.makeActive }}</MkSwitch>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -64,10 +64,6 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
<template #label>{{ i18n.ts._plugin.viewLog }}</template>
|
<template #label>{{ i18n.ts._plugin.viewLog }}</template>
|
||||||
|
|
||||||
<div class="_gaps_s">
|
<div class="_gaps_s">
|
||||||
<div class="_buttons">
|
|
||||||
<MkButton inline @click="copy(pluginLogs.get(plugin.installId)?.join('\n'))"><i class="ti ti-copy"></i> {{ i18n.ts.copy }}</MkButton>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<MkCode :code="pluginLogs.get(plugin.installId)?.join('\n') ?? ''"/>
|
<MkCode :code="pluginLogs.get(plugin.installId)?.join('\n') ?? ''"/>
|
||||||
</div>
|
</div>
|
||||||
</MkFolder>
|
</MkFolder>
|
||||||
|
@ -77,10 +73,6 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
<template #label>{{ i18n.ts._plugin.viewSource }}</template>
|
<template #label>{{ i18n.ts._plugin.viewSource }}</template>
|
||||||
|
|
||||||
<div class="_gaps_s">
|
<div class="_gaps_s">
|
||||||
<div class="_buttons">
|
|
||||||
<MkButton inline @click="copy(plugin.src)"><i class="ti ti-copy"></i> {{ i18n.ts.copy }}</MkButton>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<MkCode :code="plugin.src ?? ''" lang="ais"/>
|
<MkCode :code="plugin.src ?? ''" lang="ais"/>
|
||||||
</div>
|
</div>
|
||||||
</MkFolder>
|
</MkFolder>
|
||||||
|
@ -94,6 +86,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { nextTick, ref, computed } from 'vue';
|
import { nextTick, ref, computed } from 'vue';
|
||||||
|
import type { Plugin } from '@/plugin.js';
|
||||||
import FormLink from '@/components/form/link.vue';
|
import FormLink from '@/components/form/link.vue';
|
||||||
import MkSwitch from '@/components/MkSwitch.vue';
|
import MkSwitch from '@/components/MkSwitch.vue';
|
||||||
import FormSection from '@/components/form/section.vue';
|
import FormSection from '@/components/form/section.vue';
|
||||||
|
@ -101,36 +94,30 @@ import MkButton from '@/components/MkButton.vue';
|
||||||
import MkCode from '@/components/MkCode.vue';
|
import MkCode from '@/components/MkCode.vue';
|
||||||
import MkFolder from '@/components/MkFolder.vue';
|
import MkFolder from '@/components/MkFolder.vue';
|
||||||
import MkKeyValue from '@/components/MkKeyValue.vue';
|
import MkKeyValue from '@/components/MkKeyValue.vue';
|
||||||
import * as os from '@/os.js';
|
|
||||||
import { copyToClipboard } from '@/utility/copy-to-clipboard.js';
|
|
||||||
import { unisonReload } from '@/utility/unison-reload.js';
|
import { unisonReload } from '@/utility/unison-reload.js';
|
||||||
import { i18n } from '@/i18n.js';
|
import { i18n } from '@/i18n.js';
|
||||||
import { definePageMetadata } from '@/utility/page-metadata.js';
|
import { definePageMetadata } from '@/utility/page-metadata.js';
|
||||||
import { changePluginActive, configPlugin, pluginLogs, uninstallPlugin } from '@/plugin.js';
|
import { changePluginActive, configPlugin, pluginLogs, uninstallPlugin, reloadPlugin } from '@/plugin.js';
|
||||||
import { prefer } from '@/preferences.js';
|
import { prefer } from '@/preferences.js';
|
||||||
|
|
||||||
const plugins = prefer.r.plugins;
|
const plugins = prefer.r.plugins;
|
||||||
|
|
||||||
async function uninstall(plugin) {
|
async function uninstall(plugin: Plugin) {
|
||||||
await uninstallPlugin(plugin);
|
await uninstallPlugin(plugin);
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
unisonReload();
|
unisonReload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function copy(text) {
|
function reload(plugin: Plugin) {
|
||||||
copyToClipboard(text ?? '');
|
reloadPlugin(plugin);
|
||||||
os.success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function config(plugin) {
|
async function config(plugin: Plugin) {
|
||||||
await configPlugin(plugin);
|
await configPlugin(plugin);
|
||||||
nextTick(() => {
|
|
||||||
location.reload();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeActive(plugin, active) {
|
function changeActive(plugin: Plugin, active: boolean) {
|
||||||
changePluginActive(plugin, active);
|
changePluginActive(plugin, active);
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
location.reload();
|
location.reload();
|
||||||
|
|
|
@ -37,40 +37,6 @@ export type AiScriptPluginMeta = {
|
||||||
config?: Record<string, any>;
|
config?: Record<string, any>;
|
||||||
};
|
};
|
||||||
|
|
||||||
interface PostFormAction {
|
|
||||||
title: string,
|
|
||||||
handler: <T>(form: T, update: (key: unknown, value: unknown) => void) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface UserAction {
|
|
||||||
title: string,
|
|
||||||
handler: (user: Misskey.entities.UserDetailed) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface NoteAction {
|
|
||||||
title: string,
|
|
||||||
handler: (note: Misskey.entities.Note) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface NoteViewInterruptor {
|
|
||||||
handler: (note: Misskey.entities.Note) => unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface NotePostInterruptor {
|
|
||||||
handler: (note: FIXME) => unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface PageViewInterruptor {
|
|
||||||
handler: (page: Misskey.entities.Page) => unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const postFormActions: PostFormAction[] = [];
|
|
||||||
export const userActions: UserAction[] = [];
|
|
||||||
export const noteActions: NoteAction[] = [];
|
|
||||||
export const noteViewInterruptors: NoteViewInterruptor[] = [];
|
|
||||||
export const notePostInterruptors: NotePostInterruptor[] = [];
|
|
||||||
export const pageViewInterruptors: PageViewInterruptor[] = [];
|
|
||||||
|
|
||||||
const parser = new Parser();
|
const parser = new Parser();
|
||||||
|
|
||||||
export function isSupportedAiScriptVersion(version: string): boolean {
|
export function isSupportedAiScriptVersion(version: string): boolean {
|
||||||
|
@ -215,6 +181,42 @@ export function changePluginActive(plugin: Plugin, active: boolean) {
|
||||||
const pluginContexts = new Map<string, Interpreter>();
|
const pluginContexts = new Map<string, Interpreter>();
|
||||||
export const pluginLogs = ref(new Map<string, string[]>());
|
export const pluginLogs = ref(new Map<string, string[]>());
|
||||||
|
|
||||||
|
type HandlerDef = {
|
||||||
|
post_form_action: {
|
||||||
|
title: string,
|
||||||
|
handler: <T>(form: T, update: (key: unknown, value: unknown) => void) => void;
|
||||||
|
};
|
||||||
|
user_action: {
|
||||||
|
title: string,
|
||||||
|
handler: (user: Misskey.entities.UserDetailed) => void;
|
||||||
|
};
|
||||||
|
note_action: {
|
||||||
|
title: string,
|
||||||
|
handler: (note: Misskey.entities.Note) => void;
|
||||||
|
};
|
||||||
|
note_view_interruptor: {
|
||||||
|
handler: (note: Misskey.entities.Note) => unknown;
|
||||||
|
};
|
||||||
|
note_post_interruptor: {
|
||||||
|
handler: (note: FIXME) => unknown;
|
||||||
|
};
|
||||||
|
page_view_interruptor: {
|
||||||
|
handler: (page: Misskey.entities.Page) => unknown;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
type PluginHandler<K extends keyof HandlerDef> = {
|
||||||
|
pluginInstallId: string;
|
||||||
|
type: K;
|
||||||
|
ctx: HandlerDef[K];
|
||||||
|
};
|
||||||
|
|
||||||
|
let pluginHandlers: PluginHandler<keyof HandlerDef>[] = [];
|
||||||
|
|
||||||
|
function addPluginHandler<K extends keyof HandlerDef>(installId: Plugin['installId'], type: K, ctx: PluginHandler<K>['ctx']) {
|
||||||
|
pluginHandlers.push({ pluginInstallId: installId, type, ctx });
|
||||||
|
}
|
||||||
|
|
||||||
export async function launchPlugin(plugin: Plugin): Promise<void> {
|
export async function launchPlugin(plugin: Plugin): Promise<void> {
|
||||||
// 後方互換性のため
|
// 後方互換性のため
|
||||||
if (plugin.src == null) return;
|
if (plugin.src == null) return;
|
||||||
|
@ -252,6 +254,18 @@ export async function launchPlugin(plugin: Plugin): Promise<void> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function reloadPlugin(plugin: Plugin): void {
|
||||||
|
const pluginContext = pluginContexts.get(plugin.installId);
|
||||||
|
if (!pluginContext) return;
|
||||||
|
|
||||||
|
pluginContext.abort();
|
||||||
|
pluginContexts.delete(plugin.installId);
|
||||||
|
pluginLogs.value.delete(plugin.installId);
|
||||||
|
pluginHandlers = pluginHandlers.filter(x => x.pluginInstallId !== plugin.installId);
|
||||||
|
|
||||||
|
launchPlugin(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Record<string, values.Value> {
|
function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Record<string, values.Value> {
|
||||||
const id = opts.plugin.installId;
|
const id = opts.plugin.installId;
|
||||||
|
|
||||||
|
@ -260,111 +274,90 @@ function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Record<s
|
||||||
config.set(k, utils.jsToVal(typeof opts.plugin.configData[k] !== 'undefined' ? opts.plugin.configData[k] : v.default));
|
config.set(k, utils.jsToVal(typeof opts.plugin.configData[k] !== 'undefined' ? opts.plugin.configData[k] : v.default));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function withContext<T>(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 {
|
return {
|
||||||
...createAiScriptEnv({ ...opts, token: store.state.pluginTokens[id] }),
|
...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.assertString(title);
|
||||||
registerPostFormAction({ pluginId: id, title: title.value, handler });
|
utils.assertFunction(handler);
|
||||||
}),
|
addPluginHandler(id, 'post_form_action', {
|
||||||
'Plugin:register_user_action': values.FN_NATIVE(([title, handler]) => {
|
title: title.value,
|
||||||
utils.assertString(title);
|
handler: withContext(ctx => (form, update) => {
|
||||||
registerUserAction({ pluginId: id, title: title.value, handler });
|
ctx.execFn(handler, [utils.jsToVal(form), values.FN_NATIVE(([key, value]) => {
|
||||||
}),
|
|
||||||
'Plugin:register_note_action': values.FN_NATIVE(([title, handler]) => {
|
|
||||||
utils.assertString(title);
|
|
||||||
registerNoteAction({ pluginId: id, title: title.value, handler });
|
|
||||||
}),
|
|
||||||
'Plugin:register_note_view_interruptor': values.FN_NATIVE(([handler]) => {
|
|
||||||
registerNoteViewInterruptor({ pluginId: id, handler });
|
|
||||||
}),
|
|
||||||
'Plugin:register_note_post_interruptor': values.FN_NATIVE(([handler]) => {
|
|
||||||
registerNotePostInterruptor({ pluginId: id, handler });
|
|
||||||
}),
|
|
||||||
'Plugin:register_page_view_interruptor': values.FN_NATIVE(([handler]) => {
|
|
||||||
registerPageViewInterruptor({ pluginId: id, handler });
|
|
||||||
}),
|
|
||||||
'Plugin:open_url': values.FN_NATIVE(([url]) => {
|
|
||||||
utils.assertString(url);
|
|
||||||
window.open(url.value, '_blank', 'noopener');
|
|
||||||
}),
|
|
||||||
'Plugin:config': values.OBJ(config),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function registerPostFormAction({ pluginId, title, handler }): void {
|
|
||||||
postFormActions.push({
|
|
||||||
title, handler: (form, update) => {
|
|
||||||
const pluginContext = pluginContexts.get(pluginId);
|
|
||||||
if (!pluginContext) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pluginContext.execFn(handler, [utils.jsToVal(form), values.FN_NATIVE(([key, value]) => {
|
|
||||||
if (!key || !value) {
|
if (!key || !value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
update(utils.valToJs(key), utils.valToJs(value));
|
update(utils.valToJs(key), utils.valToJs(value));
|
||||||
})]);
|
})]);
|
||||||
},
|
}),
|
||||||
});
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
|
'Plugin:register_user_action': values.FN_NATIVE(([title, handler]) => {
|
||||||
|
utils.assertString(title);
|
||||||
|
utils.assertFunction(handler);
|
||||||
|
addPluginHandler(id, 'user_action', {
|
||||||
|
title: title.value,
|
||||||
|
handler: withContext(ctx => (user) => {
|
||||||
|
ctx.execFn(handler, [utils.jsToVal(user)]);
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
|
'Plugin:register_note_action': values.FN_NATIVE(([title, handler]) => {
|
||||||
|
utils.assertString(title);
|
||||||
|
utils.assertFunction(handler);
|
||||||
|
addPluginHandler(id, 'note_action', {
|
||||||
|
title: title.value,
|
||||||
|
handler: withContext(ctx => (note) => {
|
||||||
|
ctx.execFn(handler, [utils.jsToVal(note)]);
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
|
'Plugin:register_note_view_interruptor': values.FN_NATIVE(([handler]) => {
|
||||||
|
utils.assertFunction(handler);
|
||||||
|
addPluginHandler(id, 'note_view_interruptor', {
|
||||||
|
handler: withContext(ctx => async (note) => {
|
||||||
|
return utils.valToJs(await ctx.execFn(handler, [utils.jsToVal(note)]));
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
|
'Plugin:register_note_post_interruptor': values.FN_NATIVE(([handler]) => {
|
||||||
|
utils.assertFunction(handler);
|
||||||
|
addPluginHandler(id, 'note_post_interruptor', {
|
||||||
|
handler: withContext(ctx => async (note) => {
|
||||||
|
return utils.valToJs(await ctx.execFn(handler, [utils.jsToVal(note)]));
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
|
'Plugin:register_page_view_interruptor': values.FN_NATIVE(([handler]) => {
|
||||||
|
utils.assertFunction(handler);
|
||||||
|
addPluginHandler(id, 'page_view_interruptor', {
|
||||||
|
handler: withContext(ctx => async (page) => {
|
||||||
|
return utils.valToJs(await ctx.execFn(handler, [utils.jsToVal(page)]));
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
|
'Plugin:open_url': values.FN_NATIVE(([url]) => {
|
||||||
|
utils.assertString(url);
|
||||||
|
window.open(url.value, '_blank', 'noopener');
|
||||||
|
}),
|
||||||
|
|
||||||
|
'Plugin:config': values.OBJ(config),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerUserAction({ pluginId, title, handler }): void {
|
export function getPluginHandlers<K extends keyof HandlerDef>(type: K): HandlerDef[K][] {
|
||||||
userActions.push({
|
return pluginHandlers.filter((x): x is PluginHandler<K> => x.type === type).map(x => x.ctx);
|
||||||
title, handler: (user) => {
|
|
||||||
const pluginContext = pluginContexts.get(pluginId);
|
|
||||||
if (!pluginContext) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pluginContext.execFn(handler, [utils.jsToVal(user)]);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function registerNoteAction({ pluginId, title, handler }): void {
|
|
||||||
noteActions.push({
|
|
||||||
title, handler: (note) => {
|
|
||||||
const pluginContext = pluginContexts.get(pluginId);
|
|
||||||
if (!pluginContext) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pluginContext.execFn(handler, [utils.jsToVal(note)]);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function registerNoteViewInterruptor({ pluginId, handler }): void {
|
|
||||||
noteViewInterruptors.push({
|
|
||||||
handler: async (note) => {
|
|
||||||
const pluginContext = pluginContexts.get(pluginId);
|
|
||||||
if (!pluginContext) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return utils.valToJs(await pluginContext.execFn(handler, [utils.jsToVal(note)]));
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function registerNotePostInterruptor({ pluginId, handler }): void {
|
|
||||||
notePostInterruptors.push({
|
|
||||||
handler: async (note) => {
|
|
||||||
const pluginContext = pluginContexts.get(pluginId);
|
|
||||||
if (!pluginContext) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return utils.valToJs(await pluginContext.execFn(handler, [utils.jsToVal(note)]));
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function registerPageViewInterruptor({ pluginId, handler }): void {
|
|
||||||
pageViewInterruptors.push({
|
|
||||||
handler: async (page) => {
|
|
||||||
const pluginContext = pluginContexts.get(pluginId);
|
|
||||||
if (!pluginContext) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return utils.valToJs(await pluginContext.execFn(handler, [utils.jsToVal(page)]));
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ import { isSupportShare } from '@/utility/navigator.js';
|
||||||
import { getAppearNote } from '@/utility/get-appear-note.js';
|
import { getAppearNote } from '@/utility/get-appear-note.js';
|
||||||
import { genEmbedCode } from '@/utility/get-embed-code.js';
|
import { genEmbedCode } from '@/utility/get-embed-code.js';
|
||||||
import { prefer } from '@/preferences.js';
|
import { prefer } from '@/preferences.js';
|
||||||
import { noteActions } from '@/plugin.js';
|
import { getPluginHandlers } from '@/plugin.js';
|
||||||
|
|
||||||
export async function getNoteClipMenu(props: {
|
export async function getNoteClipMenu(props: {
|
||||||
note: Misskey.entities.Note;
|
note: Misskey.entities.Note;
|
||||||
|
@ -497,6 +497,7 @@ export function getNoteMenu(props: {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const noteActions = getPluginHandlers('note_action');
|
||||||
if (noteActions.length > 0) {
|
if (noteActions.length > 0) {
|
||||||
menuItems.push({ type: 'divider' });
|
menuItems.push({ type: 'divider' });
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ import { antennasCache, rolesCache, userListsCache } from '@/cache.js';
|
||||||
import { mainRouter } from '@/router/main.js';
|
import { mainRouter } from '@/router/main.js';
|
||||||
import { genEmbedCode } from '@/utility/get-embed-code.js';
|
import { genEmbedCode } from '@/utility/get-embed-code.js';
|
||||||
import { prefer } from '@/preferences.js';
|
import { prefer } from '@/preferences.js';
|
||||||
import { userActions } from '@/plugin.js';
|
import { getPluginHandlers } from '@/plugin.js';
|
||||||
|
|
||||||
export function getUserMenu(user: Misskey.entities.UserDetailed, router: IRouter = mainRouter) {
|
export function getUserMenu(user: Misskey.entities.UserDetailed, router: IRouter = mainRouter) {
|
||||||
const meId = $i ? $i.id : null;
|
const meId = $i ? $i.id : null;
|
||||||
|
@ -419,6 +419,7 @@ export function getUserMenu(user: Misskey.entities.UserDetailed, router: IRouter
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const userActions = getPluginHandlers('user_action');
|
||||||
if (userActions.length > 0) {
|
if (userActions.length > 0) {
|
||||||
menuItems.push({ type: 'divider' }, ...userActions.map(action => ({
|
menuItems.push({ type: 'divider' }, ...userActions.map(action => ({
|
||||||
icon: 'ti ti-plug',
|
icon: 'ti ti-plug',
|
||||||
|
|
Loading…
Reference in New Issue