Skip to content

Commit 65d1e91

Browse files
committed
feat: 增加插件安装方法到window对象
1 parent 02095aa commit 65d1e91

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

client/web/src/plugin/manager.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { initMiniStar, loadSinglePlugin } from 'mini-star';
77
import _once from 'lodash/once';
88
import { builtinPlugins } from './builtin';
99
import { showPluginLoadError } from './showPluginLoadError';
10+
import { injectTailchatGlobalValue } from '@/utils/global-helper';
1011

1112
class PluginManager {
1213
/**
@@ -133,3 +134,4 @@ class PluginManager {
133134
}
134135

135136
export const pluginManager = new PluginManager();
137+
injectTailchatGlobalValue('installPlugin', pluginManager.installPlugin);

client/web/src/utils/global-helper.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type TailchatTypeMap = NonNullable<typeof window.tailchat>;
2+
3+
/**
4+
* 注入tailchat全局变量到window
5+
*/
6+
export function injectTailchatGlobalValue<T extends keyof TailchatTypeMap>(
7+
key: T,
8+
value: TailchatTypeMap[T]
9+
) {
10+
if (!window.tailchat) {
11+
window.tailchat = {};
12+
}
13+
14+
window.tailchat[key] = value;
15+
}

client/web/types/global.d.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Copy from `tailchat/client/shared/model/plugin.ts`
3+
*/
4+
interface PluginManifest {
5+
/**
6+
* 插件用于显示的名称
7+
* @example 网页面板插件
8+
*/
9+
label: string;
10+
11+
/**
12+
* 插件名, 插件唯一标识
13+
* @example com.msgbyte.webview
14+
*/
15+
name: string;
16+
17+
/**
18+
* 插件地址
19+
*/
20+
url: string;
21+
22+
/**
23+
* 插件图标
24+
* 推荐大小: 128x128
25+
*/
26+
icon?: string;
27+
28+
/**
29+
* 插件版本号
30+
* 遵循 semver 规则
31+
*
32+
* major.minor.patch
33+
* @example 1.0.0
34+
*/
35+
version: string;
36+
37+
/**
38+
* 插件维护者
39+
*/
40+
author: string;
41+
42+
/**
43+
* 插件描述
44+
*/
45+
description: string;
46+
47+
/**
48+
* 是否需要重启才能应用插件
49+
*/
50+
requireRestart: boolean;
51+
52+
/**
53+
* 文档的链接
54+
* 如果是markdown则解析, 如果是html则使用iframe
55+
*/
56+
documentUrl?: string;
57+
}
58+
59+
declare interface Window {
60+
tailchat?: {
61+
installPlugin?: (manifest: PluginManifest) => Promise<void>;
62+
};
63+
}

0 commit comments

Comments
 (0)