floating-live 0.16.6 → 0.17.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.yarn/install-state.gz +0 -0
- package/.yarnrc.yml +6 -0
- package/LICENSE +8 -8
- package/README.md +36 -36
- package/dist/FloatingLive.js +2 -2
- package/dist/app.d.ts +8 -7
- package/dist/app.js +12 -26
- package/dist/command/manager.d.ts +1 -1
- package/dist/command/manager.js +1 -1
- package/dist/live/room.d.ts +22 -0
- package/dist/live/room.js +45 -0
- package/dist/plugin/context/CommonPluginContext.d.ts +7 -2
- package/dist/plugin/context/CommonPluginContext.js +18 -24
- package/dist/plugin/manager.d.ts +19 -3
- package/dist/plugin/manager.js +71 -10
- package/dist/plugin/types.d.ts +15 -8
- package/dist/value/manager.d.ts +1 -1
- package/dist/value/manager.js +1 -1
- package/package.json +23 -23
- package/playground/error.md +23 -0
- package/src/source.md +29 -29
- package/dist/plugin/context/CorePluginContext.d.ts +0 -8
- package/dist/plugin/context/CorePluginContext.js +0 -25
|
Binary file
|
package/.yarnrc.yml
ADDED
package/LICENSE
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Minteea
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Minteea
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
9
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
# Floating Live
|
|
2
|
-
|
|
3
|
-
一个用于处理和保存直播弹幕的 Web 小工具,开箱即用。
|
|
4
|
-
|
|
5
|
-
本体无弹幕获取功能,需要配合[floating-live-plugins](https://github.com/Minteea/floating-live-plugins)中的插件使用。
|
|
6
|
-
|
|
7
|
-
目前插件库支持 bilibili 和 AcFun 的直播弹幕,不同平台的弹幕会转换为同一种格式便于保存。
|
|
8
|
-
|
|
9
|
-
项目仍在开发中,功能尚未完善,目前除了记录保存直播弹幕外暂时没有别的用处啦,敬请期待。
|
|
10
|
-
|
|
11
|
-
注意:当前项目未进入正式版本阶段,程序结构及导出数据结构可能随时改动,**非常不建议用于正式项目中**。
|
|
12
|
-
|
|
13
|
-
GUI 版本:[Minteea/floating-live-gui](https://github.com/Minteea/floating-live-gui)
|
|
14
|
-
|
|
15
|
-
## 使用方法
|
|
16
|
-
|
|
17
|
-
### npm 安装
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
npm install floating-live
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
```javascript
|
|
24
|
-
// 导入FloatingLive本体
|
|
25
|
-
import { FloatingLive } from "floating-live";
|
|
26
|
-
// 导入bilibili房间生成插件
|
|
27
|
-
import bilibili from "@floating-live/bilibili";
|
|
28
|
-
|
|
29
|
-
// 创建一个FloatingLive实例
|
|
30
|
-
const live = new FloatingLive();
|
|
31
|
-
// 注册插件
|
|
32
|
-
live.plugin.register(bilibili);
|
|
33
|
-
|
|
34
|
-
// 添加房间并自动打开
|
|
35
|
-
live.room.add("bilibili", 6, true);
|
|
36
|
-
```
|
|
1
|
+
# Floating Live
|
|
2
|
+
|
|
3
|
+
一个用于处理和保存直播弹幕的 Web 小工具,开箱即用。
|
|
4
|
+
|
|
5
|
+
本体无弹幕获取功能,需要配合[floating-live-plugins](https://github.com/Minteea/floating-live-plugins)中的插件使用。
|
|
6
|
+
|
|
7
|
+
目前插件库支持 bilibili 和 AcFun 的直播弹幕,不同平台的弹幕会转换为同一种格式便于保存。
|
|
8
|
+
|
|
9
|
+
项目仍在开发中,功能尚未完善,目前除了记录保存直播弹幕外暂时没有别的用处啦,敬请期待。
|
|
10
|
+
|
|
11
|
+
注意:当前项目未进入正式版本阶段,程序结构及导出数据结构可能随时改动,**非常不建议用于正式项目中**。
|
|
12
|
+
|
|
13
|
+
GUI 版本:[Minteea/floating-live-gui](https://github.com/Minteea/floating-live-gui)
|
|
14
|
+
|
|
15
|
+
## 使用方法
|
|
16
|
+
|
|
17
|
+
### npm 安装
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
npm install floating-live
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
// 导入FloatingLive本体
|
|
25
|
+
import { FloatingLive } from "floating-live";
|
|
26
|
+
// 导入bilibili房间生成插件
|
|
27
|
+
import bilibili from "@floating-live/bilibili";
|
|
28
|
+
|
|
29
|
+
// 创建一个FloatingLive实例
|
|
30
|
+
const live = new FloatingLive();
|
|
31
|
+
// 注册插件
|
|
32
|
+
live.plugin.register(bilibili);
|
|
33
|
+
|
|
34
|
+
// 添加房间并自动打开
|
|
35
|
+
live.room.add("bilibili", 6, true);
|
|
36
|
+
```
|
package/dist/FloatingLive.js
CHANGED
|
@@ -4,8 +4,8 @@ import { Platform } from "./plugins/platform/index.js";
|
|
|
4
4
|
export class FloatingLive extends App {
|
|
5
5
|
constructor() {
|
|
6
6
|
super();
|
|
7
|
-
this.room = this.registerSync(Room, {
|
|
8
|
-
this.platform = this.registerSync(Platform, {
|
|
7
|
+
this.room = this.registerSync(Room, {}, { unremovable: true, accessApp: true, pluginType: "core" });
|
|
8
|
+
this.platform = this.registerSync(Platform, {}, { unremovable: true, accessApp: true, pluginType: "core" });
|
|
9
9
|
}
|
|
10
10
|
/** 添加房间 */
|
|
11
11
|
add(platform, id, options) {
|
package/dist/app.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { AppError } from "./error/index.js";
|
|
|
4
4
|
import { AppEventDetailMap, AppEventEmitOptions, AppEventListener } from "./event/index.js";
|
|
5
5
|
import { AppHookMap, HookCallOptions, HookContext, HookFunction, HookUseOptions } from "./hook/index.js";
|
|
6
6
|
import { HookManager } from "./hook/manager.js";
|
|
7
|
-
import {
|
|
8
|
-
import { PluginManager } from "./plugin/manager.js";
|
|
7
|
+
import { PluginConstructor, PluginContext, PluginInitOptions, PluginItem, PluginRegisterOptions } from "./plugin/index.js";
|
|
8
|
+
import { PluginManager, WhenRegisterCallback } from "./plugin/manager.js";
|
|
9
9
|
import { CustomEventEmitter } from "./utils/EventEmitter.js";
|
|
10
10
|
import { AppValueMap, ValueOptions } from "./value/index.js";
|
|
11
11
|
import { ValueManager } from "./value/manager.js";
|
|
@@ -24,14 +24,14 @@ export declare class App extends CustomEventEmitter implements PluginContext {
|
|
|
24
24
|
throw(err?: Error): void;
|
|
25
25
|
error(id: string, detail?: Record<string, any>): AppError;
|
|
26
26
|
/** 注册插件 */
|
|
27
|
-
register<P extends PluginItem>(plugin: PluginConstructor<P>, options?: PluginInitOptions): Promise<P>;
|
|
27
|
+
register<P extends PluginItem>(plugin: PluginConstructor<P>, options?: PluginInitOptions, registerOptions?: PluginRegisterOptions): Promise<P>;
|
|
28
28
|
/** 同步注册插件 */
|
|
29
|
-
registerSync<P extends PluginItem>(plugin: PluginConstructor<P>, options?: PluginInitOptions): P;
|
|
30
|
-
/**
|
|
29
|
+
registerSync<P extends PluginItem>(plugin: PluginConstructor<P>, options?: PluginInitOptions, registerOptions?: PluginRegisterOptions): P;
|
|
30
|
+
/** 注销插件 */
|
|
31
31
|
unregister(pluginName: string): void;
|
|
32
32
|
getPlugin(pluginName: string): void;
|
|
33
|
-
whenRegister
|
|
34
|
-
|
|
33
|
+
whenRegister(pluginName: string, callback: WhenRegisterCallback): void;
|
|
34
|
+
cancelWhenRegister(pluginName: string, callback: WhenRegisterCallback): void;
|
|
35
35
|
getPluginExposes(pluginName: string): any;
|
|
36
36
|
hasPlugin(pluginName: string): boolean;
|
|
37
37
|
registerCommand<T extends keyof AppCommandMap>(name: T, func: CommandFunction<AppCommandMap[T]>, options?: CommandOptions): void;
|
|
@@ -53,5 +53,6 @@ export declare class App extends CustomEventEmitter implements PluginContext {
|
|
|
53
53
|
destroy(): void;
|
|
54
54
|
/** 拓展值 */
|
|
55
55
|
define(key: string, value: ((...args: any[]) => any) | PropertyDescriptor): void;
|
|
56
|
+
getApp(): App;
|
|
56
57
|
get signal(): AbortSignal;
|
|
57
58
|
}
|
package/dist/app.js
CHANGED
|
@@ -41,14 +41,14 @@ export class App extends CustomEventEmitter {
|
|
|
41
41
|
}
|
|
42
42
|
//--- 插件机制 ---//
|
|
43
43
|
/** 注册插件 */
|
|
44
|
-
register(plugin, options) {
|
|
45
|
-
return this.pluginManager.register(plugin, options);
|
|
44
|
+
register(plugin, options, registerOptions) {
|
|
45
|
+
return this.pluginManager.register(plugin, options, registerOptions);
|
|
46
46
|
}
|
|
47
47
|
/** 同步注册插件 */
|
|
48
|
-
registerSync(plugin, options) {
|
|
49
|
-
return this.pluginManager.registerSync(plugin, options);
|
|
48
|
+
registerSync(plugin, options, registerOptions) {
|
|
49
|
+
return this.pluginManager.registerSync(plugin, options, registerOptions);
|
|
50
50
|
}
|
|
51
|
-
/**
|
|
51
|
+
/** 注销插件 */
|
|
52
52
|
unregister(pluginName) {
|
|
53
53
|
this.pluginManager.unregister(pluginName);
|
|
54
54
|
}
|
|
@@ -56,27 +56,10 @@ export class App extends CustomEventEmitter {
|
|
|
56
56
|
this.pluginManager.getPlugin(pluginName);
|
|
57
57
|
}
|
|
58
58
|
whenRegister(pluginName, callback) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
this.on("plugin:register", ({ pluginName: name }) => {
|
|
65
|
-
if (pluginName == name) {
|
|
66
|
-
if (registered) {
|
|
67
|
-
whenUnregistered?.();
|
|
68
|
-
}
|
|
69
|
-
whenUnregistered = callback(this.getPluginExposes(pluginName));
|
|
70
|
-
registered = true;
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
this.on("plugin:unregister", ({ pluginName: name }) => {
|
|
74
|
-
if (pluginName == name) {
|
|
75
|
-
whenUnregistered?.();
|
|
76
|
-
whenUnregistered = undefined;
|
|
77
|
-
registered = false;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
59
|
+
return this.pluginManager.whenRegister(pluginName, callback);
|
|
60
|
+
}
|
|
61
|
+
cancelWhenRegister(pluginName, callback) {
|
|
62
|
+
return this.pluginManager.cancelWhenRegister(pluginName, callback);
|
|
80
63
|
}
|
|
81
64
|
getPluginExposes(pluginName) {
|
|
82
65
|
return this.pluginManager.getExposes(pluginName);
|
|
@@ -148,6 +131,9 @@ export class App extends CustomEventEmitter {
|
|
|
148
131
|
Object.defineProperty(this, key, value);
|
|
149
132
|
}
|
|
150
133
|
}
|
|
134
|
+
getApp() {
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
151
137
|
get signal() {
|
|
152
138
|
return this.abortController.signal;
|
|
153
139
|
}
|
|
@@ -7,7 +7,7 @@ export declare class CommandManager {
|
|
|
7
7
|
constructor(app: App);
|
|
8
8
|
/** 注册命令 */
|
|
9
9
|
register(name: string, call: CommandFunction<any>, options?: CommandOptions): void;
|
|
10
|
-
/**
|
|
10
|
+
/** 注销命令 */
|
|
11
11
|
unregister(name: string): void;
|
|
12
12
|
/** 调用命令 */
|
|
13
13
|
call(name: string, ...args: any[]): any;
|
package/dist/command/manager.js
CHANGED
package/dist/live/room.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { UserInfo } from "./messageInfo.js";
|
|
|
5
5
|
/** 直播间信息流监听类 */
|
|
6
6
|
export declare abstract class LiveRoom extends CustomEventEmitter implements LiveRoomData {
|
|
7
7
|
constructor();
|
|
8
|
+
get valid(): boolean;
|
|
8
9
|
/** 平台 */
|
|
9
10
|
abstract readonly platform: string;
|
|
10
11
|
/** 房间id */
|
|
@@ -60,6 +61,8 @@ export interface LiveRoom {
|
|
|
60
61
|
}
|
|
61
62
|
/** 房间数据 */
|
|
62
63
|
export interface LiveRoomData {
|
|
64
|
+
/** 房间有效性 */
|
|
65
|
+
valid: boolean;
|
|
63
66
|
/** 平台id */
|
|
64
67
|
platform: string;
|
|
65
68
|
/** 房间id */
|
|
@@ -193,3 +196,22 @@ export interface LiveRoomEventMap {
|
|
|
193
196
|
/** 关闭直播间连接 */
|
|
194
197
|
close: {};
|
|
195
198
|
}
|
|
199
|
+
export declare class InvalidLiveRoom implements LiveRoomData {
|
|
200
|
+
get valid(): false;
|
|
201
|
+
constructor(platform: string, id: string | number);
|
|
202
|
+
readonly platform: string;
|
|
203
|
+
readonly id: string | number;
|
|
204
|
+
detail: LiveRoomDetailInfo;
|
|
205
|
+
stats?: LiveRoomStatsInfo;
|
|
206
|
+
anchor: UserInfo;
|
|
207
|
+
status: LiveRoomStatus;
|
|
208
|
+
timestamp: number;
|
|
209
|
+
connectionStatus: LiveConnectionStatus;
|
|
210
|
+
openStatus: LiveRoomOpenStatus;
|
|
211
|
+
liveId?: string;
|
|
212
|
+
get opened(): boolean;
|
|
213
|
+
available: boolean;
|
|
214
|
+
/** 生成房间数据 */
|
|
215
|
+
toData(): LiveRoomData;
|
|
216
|
+
get key(): string;
|
|
217
|
+
}
|
package/dist/live/room.js
CHANGED
|
@@ -13,6 +13,9 @@ export class LiveRoom extends CustomEventEmitter {
|
|
|
13
13
|
this.openStatus = 0;
|
|
14
14
|
this.available = false;
|
|
15
15
|
}
|
|
16
|
+
get valid() {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
16
19
|
get opened() {
|
|
17
20
|
return this.openStatus == 2;
|
|
18
21
|
}
|
|
@@ -64,6 +67,7 @@ export class LiveRoom extends CustomEventEmitter {
|
|
|
64
67
|
/** 生成房间数据 */
|
|
65
68
|
toData() {
|
|
66
69
|
return {
|
|
70
|
+
valid: this.valid,
|
|
67
71
|
platform: this.platform,
|
|
68
72
|
id: this.id,
|
|
69
73
|
detail: this.detail,
|
|
@@ -118,3 +122,44 @@ export const LiveRoomOpenStatus = {
|
|
|
118
122
|
/** 已开启 */
|
|
119
123
|
opened: 2,
|
|
120
124
|
};
|
|
125
|
+
export class InvalidLiveRoom {
|
|
126
|
+
get valid() {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
constructor(platform, id) {
|
|
130
|
+
this.detail = {};
|
|
131
|
+
this.anchor = { name: "", id: 0 };
|
|
132
|
+
this.status = LiveRoomStatus.off;
|
|
133
|
+
this.timestamp = 0;
|
|
134
|
+
this.connectionStatus = LiveConnectionStatus.off;
|
|
135
|
+
this.openStatus = 0;
|
|
136
|
+
this.available = false;
|
|
137
|
+
this.platform = platform;
|
|
138
|
+
this.id = id;
|
|
139
|
+
}
|
|
140
|
+
get opened() {
|
|
141
|
+
return this.openStatus == 2;
|
|
142
|
+
}
|
|
143
|
+
/** 生成房间数据 */
|
|
144
|
+
toData() {
|
|
145
|
+
return {
|
|
146
|
+
valid: this.valid,
|
|
147
|
+
platform: this.platform,
|
|
148
|
+
id: this.id,
|
|
149
|
+
detail: this.detail,
|
|
150
|
+
stats: this.stats,
|
|
151
|
+
anchor: this.anchor,
|
|
152
|
+
timestamp: this.timestamp,
|
|
153
|
+
status: this.status,
|
|
154
|
+
liveId: this.liveId,
|
|
155
|
+
openStatus: this.openStatus,
|
|
156
|
+
opened: this.opened,
|
|
157
|
+
available: this.available,
|
|
158
|
+
connectionStatus: this.connectionStatus,
|
|
159
|
+
key: this.key,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
get key() {
|
|
163
|
+
return `${this.platform}:${this.id}`;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -4,14 +4,18 @@ import { AppError, ErrorOptions } from "../../error/index.js";
|
|
|
4
4
|
import { AppEventListener, AppEventEmitOptions, AppEventDetailMap } from "../../event/index.js";
|
|
5
5
|
import { HookUseOptions, HookCallOptions, AppHookMap, HookFunction, HookContext } from "../../hook/index.js";
|
|
6
6
|
import { AppValueMap, ValueContext, ValueOptions } from "../../value/index.js";
|
|
7
|
+
import { WhenRegisterCallback } from "../manager.js";
|
|
7
8
|
import type { PluginContext, PluginConstructor, PluginInitOptions, AppPluginExposesMap, PluginItem } from "../types.js";
|
|
8
9
|
export declare class CommonPluginContext implements PluginContext {
|
|
9
10
|
#private;
|
|
10
11
|
get safe(): boolean;
|
|
12
|
+
getApp(): App | null;
|
|
11
13
|
getRegisteredPlugins(): string[];
|
|
12
14
|
/** 插件名称 */
|
|
13
15
|
readonly pluginName: string;
|
|
14
|
-
constructor(app: App, pluginName: string
|
|
16
|
+
constructor(app: App, pluginName: string, options?: {
|
|
17
|
+
accessApp?: boolean;
|
|
18
|
+
});
|
|
15
19
|
/** 抛出错误
|
|
16
20
|
*
|
|
17
21
|
* 一般用于自身导致的错误,若非插件本身导致的错误,使用throw语句即可
|
|
@@ -21,7 +25,8 @@ export declare class CommonPluginContext implements PluginContext {
|
|
|
21
25
|
register<P extends PluginItem>(plugin: PluginConstructor<P>, options?: PluginInitOptions): Promise<P>;
|
|
22
26
|
unregister(pluginName: string): void;
|
|
23
27
|
getPluginExposes<K extends keyof AppPluginExposesMap>(pluginName: K): AppPluginExposesMap[K];
|
|
24
|
-
whenRegister(pluginName: string, callback:
|
|
28
|
+
whenRegister(pluginName: string, callback: WhenRegisterCallback): void;
|
|
29
|
+
cancelWhenRegister(pluginName: string, callback: WhenRegisterCallback): void;
|
|
25
30
|
hasPlugin(pluginName: string): boolean;
|
|
26
31
|
registerValue<K extends keyof AppValueMap>(name: K, options: ValueOptions<AppValueMap[K]>): ValueContext<AppValueMap[K]>;
|
|
27
32
|
unregisterValue(name: string): void;
|
|
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _CommonPluginContext_app, _CommonPluginContext_abortController, _CommonPluginContext_registered;
|
|
12
|
+
var _CommonPluginContext_app, _CommonPluginContext_accessApp, _CommonPluginContext_abortController, _CommonPluginContext_registered, _CommonPluginContext_whenRegisterMap;
|
|
13
13
|
import { AppError } from "../../error/index.js";
|
|
14
14
|
class ListMap extends Map {
|
|
15
15
|
addItem(key, value) {
|
|
@@ -29,12 +29,16 @@ export class CommonPluginContext {
|
|
|
29
29
|
get safe() {
|
|
30
30
|
return false;
|
|
31
31
|
}
|
|
32
|
+
getApp() {
|
|
33
|
+
return __classPrivateFieldGet(this, _CommonPluginContext_accessApp, "f") ? __classPrivateFieldGet(this, _CommonPluginContext_app, "f") : null;
|
|
34
|
+
}
|
|
32
35
|
getRegisteredPlugins() {
|
|
33
36
|
return [...__classPrivateFieldGet(this, _CommonPluginContext_registered, "f").plugins];
|
|
34
37
|
}
|
|
35
|
-
constructor(app, pluginName) {
|
|
38
|
+
constructor(app, pluginName, options) {
|
|
36
39
|
/** 主程序,插件不可访问 */
|
|
37
40
|
_CommonPluginContext_app.set(this, void 0);
|
|
41
|
+
_CommonPluginContext_accessApp.set(this, void 0);
|
|
38
42
|
/** AbortController,插件不可访问 */
|
|
39
43
|
_CommonPluginContext_abortController.set(this, new AbortController());
|
|
40
44
|
_CommonPluginContext_registered.set(this, {
|
|
@@ -44,8 +48,10 @@ export class CommonPluginContext {
|
|
|
44
48
|
hooks: new ListMap(),
|
|
45
49
|
events: new ListMap(),
|
|
46
50
|
});
|
|
51
|
+
_CommonPluginContext_whenRegisterMap.set(this, new ListMap());
|
|
47
52
|
__classPrivateFieldSet(this, _CommonPluginContext_app, app, "f");
|
|
48
53
|
this.pluginName = pluginName;
|
|
54
|
+
__classPrivateFieldSet(this, _CommonPluginContext_accessApp, options?.accessApp ?? false, "f");
|
|
49
55
|
}
|
|
50
56
|
/** 抛出错误
|
|
51
57
|
*
|
|
@@ -81,27 +87,12 @@ export class CommonPluginContext {
|
|
|
81
87
|
return __classPrivateFieldGet(this, _CommonPluginContext_app, "f").getPluginExposes(pluginName);
|
|
82
88
|
}
|
|
83
89
|
whenRegister(pluginName, callback) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this
|
|
90
|
-
if (pluginName == name) {
|
|
91
|
-
if (registered) {
|
|
92
|
-
whenUnregistered?.();
|
|
93
|
-
}
|
|
94
|
-
whenUnregistered = callback(this.getPluginExposes(pluginName));
|
|
95
|
-
registered = true;
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
this.on("plugin:unregister", ({ pluginName: name }) => {
|
|
99
|
-
if (pluginName == name) {
|
|
100
|
-
whenUnregistered?.();
|
|
101
|
-
whenUnregistered = undefined;
|
|
102
|
-
registered = false;
|
|
103
|
-
}
|
|
104
|
-
});
|
|
90
|
+
__classPrivateFieldGet(this, _CommonPluginContext_app, "f").whenRegister(pluginName, callback);
|
|
91
|
+
__classPrivateFieldGet(this, _CommonPluginContext_whenRegisterMap, "f").addItem(pluginName, callback);
|
|
92
|
+
}
|
|
93
|
+
cancelWhenRegister(pluginName, callback) {
|
|
94
|
+
__classPrivateFieldGet(this, _CommonPluginContext_app, "f").cancelWhenRegister(pluginName, callback);
|
|
95
|
+
__classPrivateFieldGet(this, _CommonPluginContext_whenRegisterMap, "f").deleteItem(pluginName, callback);
|
|
105
96
|
}
|
|
106
97
|
hasPlugin(pluginName) {
|
|
107
98
|
return __classPrivateFieldGet(this, _CommonPluginContext_app, "f").hasPlugin(pluginName);
|
|
@@ -282,6 +273,9 @@ export class CommonPluginContext {
|
|
|
282
273
|
}
|
|
283
274
|
}
|
|
284
275
|
destroy() {
|
|
276
|
+
__classPrivateFieldGet(this, _CommonPluginContext_whenRegisterMap, "f").forEach((callbacks, pluginName) => {
|
|
277
|
+
callbacks.forEach((callback) => __classPrivateFieldGet(this, _CommonPluginContext_app, "f").cancelWhenRegister(pluginName, callback));
|
|
278
|
+
});
|
|
285
279
|
const { plugins, values, hooks, commands } = __classPrivateFieldGet(this, _CommonPluginContext_registered, "f");
|
|
286
280
|
plugins.forEach((pluginName) => __classPrivateFieldGet(this, _CommonPluginContext_app, "f").unregister(pluginName));
|
|
287
281
|
hooks.forEach((hookList, name) => hookList.forEach((hookFunc) => __classPrivateFieldGet(this, _CommonPluginContext_app, "f").off(name, hookFunc)));
|
|
@@ -293,4 +287,4 @@ export class CommonPluginContext {
|
|
|
293
287
|
return __classPrivateFieldGet(this, _CommonPluginContext_abortController, "f").signal;
|
|
294
288
|
}
|
|
295
289
|
}
|
|
296
|
-
_CommonPluginContext_app = new WeakMap(), _CommonPluginContext_abortController = new WeakMap(), _CommonPluginContext_registered = new WeakMap();
|
|
290
|
+
_CommonPluginContext_app = new WeakMap(), _CommonPluginContext_accessApp = new WeakMap(), _CommonPluginContext_abortController = new WeakMap(), _CommonPluginContext_registered = new WeakMap(), _CommonPluginContext_whenRegisterMap = new WeakMap();
|
package/dist/plugin/manager.d.ts
CHANGED
|
@@ -4,16 +4,26 @@ export interface PluginData<T> {
|
|
|
4
4
|
plugin: PluginItem;
|
|
5
5
|
context: PluginContext;
|
|
6
6
|
exposes?: T;
|
|
7
|
-
|
|
7
|
+
unremovable: boolean;
|
|
8
|
+
/** 可访问App实例 */
|
|
9
|
+
accessApp: boolean;
|
|
10
|
+
/** 插件类型 */
|
|
11
|
+
pluginType: "core" | "framework" | "";
|
|
8
12
|
}
|
|
13
|
+
/** 插件注册监听回调
|
|
14
|
+
* 当目标插件已经注册时,回调会被立即调用,否则将在目标插件注册时调用。
|
|
15
|
+
* 回调可以返回一个函数作为注销时的回调。
|
|
16
|
+
*/
|
|
17
|
+
export type WhenRegisterCallback = () => (() => void) | void;
|
|
9
18
|
export declare class PluginManager {
|
|
10
19
|
/** 插件列表 */
|
|
11
20
|
private list;
|
|
21
|
+
private whenRegisterMap;
|
|
12
22
|
protected readonly app: App;
|
|
13
23
|
constructor(app: App);
|
|
14
|
-
registerSync<P extends PluginItem>(pluginConstructor: PluginConstructor<P>, options?: Record<string, any>, { context, core }?: PluginRegisterOptions): P;
|
|
24
|
+
registerSync<P extends PluginItem>(pluginConstructor: PluginConstructor<P>, options?: Record<string, any>, { context, core, unremovable, accessApp, pluginType }?: PluginRegisterOptions): P;
|
|
15
25
|
/** 注册插件 */
|
|
16
|
-
register<P extends PluginItem>(pluginConstructor: PluginConstructor<P>, options?: Record<string, any>, { context, core }?: PluginRegisterOptions): Promise<P>;
|
|
26
|
+
register<P extends PluginItem>(pluginConstructor: PluginConstructor<P>, options?: Record<string, any>, { context, core, unremovable, accessApp, pluginType }?: PluginRegisterOptions): Promise<P>;
|
|
17
27
|
/** 移除插件 */
|
|
18
28
|
unregister(pluginName: string): Promise<void>;
|
|
19
29
|
/** 获取插件实例 */
|
|
@@ -21,6 +31,12 @@ export declare class PluginManager {
|
|
|
21
31
|
has(pluginName: string): boolean;
|
|
22
32
|
getPlugin(pluginName: string): PluginItem | undefined;
|
|
23
33
|
getExposes(pluginName: string): any;
|
|
34
|
+
/** 在插件已注册时执行回调
|
|
35
|
+
* param skipError 在安装来源插件调用该方法且目标插件已安装时,是否跳过回调函数抛出的错误(默认为false)
|
|
36
|
+
*/
|
|
37
|
+
whenRegister(pluginName: string, callback: WhenRegisterCallback): void;
|
|
38
|
+
/** 取消插件已注册时的执行回调 */
|
|
39
|
+
cancelWhenRegister(pluginName: string, callback: WhenRegisterCallback): void;
|
|
24
40
|
toSnapshot(): {
|
|
25
41
|
pluginName: string;
|
|
26
42
|
}[];
|
package/dist/plugin/manager.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { CommonPluginContext } from "./context/CommonPluginContext.js";
|
|
2
2
|
import { AppError } from "../error/index.js";
|
|
3
|
-
import { CorePluginContext } from "./context/CorePluginContext.js";
|
|
4
3
|
import { bindCommand } from "../utils/index.js";
|
|
5
4
|
export class PluginManager {
|
|
6
5
|
constructor(app) {
|
|
7
6
|
/** 插件列表 */
|
|
8
7
|
this.list = new Map();
|
|
8
|
+
this.whenRegisterMap = new Map();
|
|
9
9
|
this.app = app;
|
|
10
10
|
app.registerCommand("plugin.snapshot", bindCommand(this.toSnapshot, this));
|
|
11
11
|
}
|
|
12
|
-
registerSync(pluginConstructor, options = {}, { context, core } = {}) {
|
|
12
|
+
registerSync(pluginConstructor, options = {}, { context, core, unremovable, accessApp, pluginType } = {}) {
|
|
13
13
|
const pluginName = pluginConstructor.pluginName;
|
|
14
14
|
if (!pluginName) {
|
|
15
15
|
throw new AppError("plugin:register_id_missing", {
|
|
@@ -26,7 +26,7 @@ export class PluginManager {
|
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
const registerCtx = { pluginName, options };
|
|
29
|
-
const pluginCtx = context || new
|
|
29
|
+
const pluginCtx = context || new CommonPluginContext(this.app, pluginName);
|
|
30
30
|
try {
|
|
31
31
|
const ctx = this.app.callHookSync("plugin.register", registerCtx);
|
|
32
32
|
if (ctx.defaultPrevented)
|
|
@@ -41,13 +41,24 @@ export class PluginManager {
|
|
|
41
41
|
plugin.init?.(pluginCtx, registerCtx.options || {});
|
|
42
42
|
// 调用插件的expose钩子
|
|
43
43
|
const exposes = plugin.expose?.(pluginCtx);
|
|
44
|
+
// 将插件数据注册到列表中
|
|
44
45
|
this.list.set(pluginName, {
|
|
45
46
|
plugin,
|
|
46
47
|
context: pluginCtx,
|
|
47
48
|
exposes,
|
|
48
|
-
core,
|
|
49
|
+
unremovable: core || unremovable || false,
|
|
50
|
+
accessApp: core || accessApp || false,
|
|
51
|
+
pluginType: core ? "core" : pluginType || "",
|
|
49
52
|
});
|
|
50
53
|
this.app.emit("plugin:register", { pluginName });
|
|
54
|
+
// 如果有whenRegister的回调,调用回调函数
|
|
55
|
+
const callbackMap = this.whenRegisterMap.get(pluginName);
|
|
56
|
+
if (callbackMap) {
|
|
57
|
+
for (const [callback] of callbackMap.entries()) {
|
|
58
|
+
const whenUnregistered = callback();
|
|
59
|
+
callbackMap.set(callback, whenUnregistered || null);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
51
62
|
return plugin;
|
|
52
63
|
}
|
|
53
64
|
catch (err) {
|
|
@@ -59,7 +70,7 @@ export class PluginManager {
|
|
|
59
70
|
}
|
|
60
71
|
}
|
|
61
72
|
/** 注册插件 */
|
|
62
|
-
async register(pluginConstructor, options = {}, { context, core } = {}) {
|
|
73
|
+
async register(pluginConstructor, options = {}, { context, core, unremovable, accessApp, pluginType } = {}) {
|
|
63
74
|
const pluginName = pluginConstructor.pluginName;
|
|
64
75
|
if (!pluginName) {
|
|
65
76
|
throw new AppError("plugin:register_id_missing", {
|
|
@@ -96,9 +107,19 @@ export class PluginManager {
|
|
|
96
107
|
plugin,
|
|
97
108
|
context: pluginCtx,
|
|
98
109
|
exposes,
|
|
99
|
-
core,
|
|
110
|
+
unremovable: core || unremovable || false,
|
|
111
|
+
accessApp: core || accessApp || false,
|
|
112
|
+
pluginType: core ? "core" : pluginType || "",
|
|
100
113
|
});
|
|
101
114
|
this.app.emit("plugin:register", { pluginName });
|
|
115
|
+
// 如果有whenRegister的回调,调用回调函数
|
|
116
|
+
const callbackMap = this.whenRegisterMap.get(pluginName);
|
|
117
|
+
if (callbackMap) {
|
|
118
|
+
for (const [callback] of callbackMap.entries()) {
|
|
119
|
+
const whenUnregistered = callback();
|
|
120
|
+
callbackMap.set(callback, whenUnregistered || null);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
102
123
|
return plugin;
|
|
103
124
|
})
|
|
104
125
|
.catch((err) => {
|
|
@@ -121,11 +142,11 @@ export class PluginManager {
|
|
|
121
142
|
});
|
|
122
143
|
}
|
|
123
144
|
else {
|
|
124
|
-
const { plugin, context,
|
|
125
|
-
if (
|
|
126
|
-
throw new AppError("plugin:
|
|
145
|
+
const { plugin, context, unremovable } = pluginData;
|
|
146
|
+
if (unremovable) {
|
|
147
|
+
throw new AppError("plugin:unregister_unremovable", {
|
|
127
148
|
message: `插件移除失败: ${pluginName}`,
|
|
128
|
-
cause: "
|
|
149
|
+
cause: "不可移除的插件",
|
|
129
150
|
target: `plugin/${pluginName}`,
|
|
130
151
|
});
|
|
131
152
|
}
|
|
@@ -136,6 +157,14 @@ export class PluginManager {
|
|
|
136
157
|
this.list.delete(pluginName);
|
|
137
158
|
// 移除插件注册事件
|
|
138
159
|
this.app.emit("plugin:unregister", { pluginName });
|
|
160
|
+
// 如果有whenRegister的回调,调用whenUnregistered函数并将回调函数从列表中移除
|
|
161
|
+
const callbackMap = this.whenRegisterMap.get(pluginName);
|
|
162
|
+
if (callbackMap) {
|
|
163
|
+
for (const [callback, whenUnregistered] of callbackMap.entries()) {
|
|
164
|
+
whenUnregistered?.();
|
|
165
|
+
callbackMap.delete(callback);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
139
168
|
}
|
|
140
169
|
}
|
|
141
170
|
/** 获取插件实例 */
|
|
@@ -151,6 +180,38 @@ export class PluginManager {
|
|
|
151
180
|
getExposes(pluginName) {
|
|
152
181
|
return this.list.get(pluginName)?.exposes;
|
|
153
182
|
}
|
|
183
|
+
/** 在插件已注册时执行回调
|
|
184
|
+
* param skipError 在安装来源插件调用该方法且目标插件已安装时,是否跳过回调函数抛出的错误(默认为false)
|
|
185
|
+
*/
|
|
186
|
+
whenRegister(pluginName, callback /*, { skipError = false }: { skipError?: boolean } = {} */) {
|
|
187
|
+
if (!this.whenRegisterMap.has(pluginName)) {
|
|
188
|
+
// 如果目标插件的回调列表不存在,创建一个新的回调列表并添加回调函数
|
|
189
|
+
this.whenRegisterMap.set(pluginName, new Map([[callback, null]]));
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
// 确保回调函数不重复注册
|
|
193
|
+
if (!this.whenRegisterMap.get(pluginName).has(callback)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
// 如果目标插件的回调列表已存在,直接添加回调函数
|
|
197
|
+
this.whenRegisterMap.get(pluginName).set(callback, null);
|
|
198
|
+
}
|
|
199
|
+
// 如果目标插件已经注册,直接调用回调
|
|
200
|
+
if (this.has(pluginName)) {
|
|
201
|
+
const whenUnregistered = callback();
|
|
202
|
+
this.whenRegisterMap.get(pluginName).set(callback, whenUnregistered || null);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/** 取消插件已注册时的执行回调 */
|
|
206
|
+
cancelWhenRegister(pluginName, callback) {
|
|
207
|
+
const callbackMap = this.whenRegisterMap.get(pluginName);
|
|
208
|
+
if (callbackMap?.has(callback)) {
|
|
209
|
+
const whenUnregistered = callbackMap.get(callback);
|
|
210
|
+
// 如果存在注销目标插件时调用的回调函数,则调用它
|
|
211
|
+
whenUnregistered?.();
|
|
212
|
+
callbackMap.delete(callback);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
154
215
|
toSnapshot() {
|
|
155
216
|
return [...this.list.keys()].map((n) => ({ pluginName: n }));
|
|
156
217
|
}
|
package/dist/plugin/types.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { AppError, ErrorOptions } from "../error/index.js";
|
|
|
4
4
|
import { AppEventListener, AppEventEmitOptions, AppEventDetailMap } from "../event/index.js";
|
|
5
5
|
import { AppHookMap, HookCallOptions, HookContext, HookFunction, HookUseOptions } from "../hook/index.js";
|
|
6
6
|
import { AppValueMap, ValueContext, ValueOptions } from "../value/index.js";
|
|
7
|
+
import { WhenRegisterCallback } from "./manager.js";
|
|
7
8
|
/** 插件对象 */
|
|
8
9
|
export interface PluginItem {
|
|
9
10
|
/** 插件名称 */
|
|
@@ -29,15 +30,21 @@ export interface PluginInitOptions {
|
|
|
29
30
|
export interface PluginRegisterOptions {
|
|
30
31
|
/** 提供的插件上下文 */
|
|
31
32
|
context?: PluginContext;
|
|
32
|
-
/** 核心插件,不可解除注册 */
|
|
33
|
+
/** 核心插件,不可解除注册 @deprecated */
|
|
33
34
|
core?: boolean;
|
|
35
|
+
/** 不可注销 */
|
|
36
|
+
unremovable?: boolean;
|
|
37
|
+
/** 可访问App实例 */
|
|
38
|
+
accessApp?: boolean;
|
|
39
|
+
/** 插件类型 */
|
|
40
|
+
pluginType?: "core" | "framework" | "";
|
|
34
41
|
}
|
|
35
42
|
/** 插件上下文 */
|
|
36
43
|
export interface PluginContext {
|
|
37
44
|
/** 安全插件上下文 */
|
|
38
45
|
safe?: boolean;
|
|
39
|
-
/** App实例,仅在核心插件上下文提供 */
|
|
40
|
-
|
|
46
|
+
/** 获取App实例,仅在核心插件上下文提供 */
|
|
47
|
+
getApp(): App | null;
|
|
41
48
|
/** 监听事件 */
|
|
42
49
|
on<K extends keyof AppEventDetailMap>(type: K, listener: AppEventListener<AppEventDetailMap[K]>): void;
|
|
43
50
|
/** 单次监听事件 */
|
|
@@ -52,18 +59,18 @@ export interface PluginContext {
|
|
|
52
59
|
error(id: string, options: ErrorOptions): AppError;
|
|
53
60
|
/** 注册插件 */
|
|
54
61
|
register<P extends PluginItem>(plugin: PluginConstructor<P>, options?: PluginInitOptions): Promise<P>;
|
|
55
|
-
/**
|
|
62
|
+
/** 注销插件 */
|
|
56
63
|
unregister(pluginName: string): void;
|
|
57
64
|
/** 获取插件暴露对象 */
|
|
58
65
|
getPluginExposes<K extends keyof AppPluginExposesMap>(pluginName: K): AppPluginExposesMap[K];
|
|
59
66
|
/** 等待plugin注册 */
|
|
60
|
-
whenRegister
|
|
61
|
-
|
|
67
|
+
whenRegister(pluginName: string, callback: WhenRegisterCallback): void;
|
|
68
|
+
cancelWhenRegister(pluginName: string, callback: WhenRegisterCallback): void;
|
|
62
69
|
/** 是否存在插件 */
|
|
63
70
|
hasPlugin(pluginName: string): boolean;
|
|
64
71
|
/** 注册指令 */
|
|
65
72
|
registerCommand<T extends keyof AppCommandMap>(name: T, func: CommandFunction<AppCommandMap[T]>, options?: CommandOptions): void;
|
|
66
|
-
/**
|
|
73
|
+
/** 注销指令 */
|
|
67
74
|
unregisterCommand(name: string): void;
|
|
68
75
|
/** 检测值是否存在 */
|
|
69
76
|
hasCommand(name: string): boolean;
|
|
@@ -81,7 +88,7 @@ export interface PluginContext {
|
|
|
81
88
|
callHookSync<T extends keyof AppHookMap>(name: T, ctx: AppHookMap[T], options?: HookCallOptions): HookContext<AppHookMap[T]>;
|
|
82
89
|
/** 注册值 */
|
|
83
90
|
registerValue<K extends keyof AppValueMap>(name: K, options: ValueOptions<AppValueMap[K]>): ValueContext<AppValueMap[K]>;
|
|
84
|
-
/**
|
|
91
|
+
/** 注销值 */
|
|
85
92
|
unregisterValue(name: string): void;
|
|
86
93
|
/** 监听值 */
|
|
87
94
|
watch<K extends keyof AppValueMap>(name: K, watcher: (value: AppValueMap[K]) => void): void;
|
package/dist/value/manager.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare class ValueManager {
|
|
|
6
6
|
constructor(app: App);
|
|
7
7
|
/** 注册值 */
|
|
8
8
|
register<T>(name: string, { get, set, pluginName }: ValueOptions<T>): ValueContext<T>;
|
|
9
|
-
/**
|
|
9
|
+
/** 注销值 */
|
|
10
10
|
unregister(name: string): void;
|
|
11
11
|
/** 获取值 */
|
|
12
12
|
get(name: string, options?: ValueAccessOptions): any;
|
package/dist/value/manager.js
CHANGED
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "floating-live",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"author": "Minteea",
|
|
8
|
-
"license": "MIT",
|
|
9
|
-
"devDependencies": {
|
|
10
|
-
"@types/node": "^22.8.2",
|
|
11
|
-
"rimraf": "^3.0.2",
|
|
12
|
-
"ts-node": "^10.9.1",
|
|
13
|
-
"tsc-alias": "^1.8.16",
|
|
14
|
-
"typescript": "^5.6.3"
|
|
15
|
-
},
|
|
16
|
-
"scripts": {
|
|
17
|
-
"tsc": "tsc -b",
|
|
18
|
-
"clear": "rimraf dist",
|
|
19
|
-
"build": "npm run clear && tsc -b && tsc-alias",
|
|
20
|
-
"prepack": "npm run build",
|
|
21
|
-
"postpack": "npm run clear"
|
|
22
|
-
}
|
|
23
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "floating-live",
|
|
3
|
+
"version": "0.17.0-alpha.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"author": "Minteea",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@types/node": "^22.8.2",
|
|
11
|
+
"rimraf": "^3.0.2",
|
|
12
|
+
"ts-node": "^10.9.1",
|
|
13
|
+
"tsc-alias": "^1.8.16",
|
|
14
|
+
"typescript": "^5.6.3"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"tsc": "tsc -b",
|
|
18
|
+
"clear": "rimraf dist",
|
|
19
|
+
"build": "npm run clear && tsc -b && tsc-alias",
|
|
20
|
+
"prepack": "npm run build",
|
|
21
|
+
"postpack": "npm run clear"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
错误消息机制
|
|
2
|
+
|
|
3
|
+
嵌套的错误将放入cause中
|
|
4
|
+
|
|
5
|
+
错误属性解析:
|
|
6
|
+
|
|
7
|
+
- id: 错误id;
|
|
8
|
+
- source?: 错误来源,取决于调用的插件和命令等;
|
|
9
|
+
- target?: 引发错误的对象id;
|
|
10
|
+
|
|
11
|
+
例如:
|
|
12
|
+
|
|
13
|
+
`#plugin:register_id_missing@plugin/#unnamed 插件注册失败:缺少pluginName字段`
|
|
14
|
+
`#plugin:register_id_duplicate@plugin/bilibili 插件注册失败:已存在相同id的插件`
|
|
15
|
+
`#credentials:check_failed@platform/acfun 无法获取必要cookie信息`
|
|
16
|
+
|
|
17
|
+
指令
|
|
18
|
+
|
|
19
|
+
错误反馈机制:
|
|
20
|
+
|
|
21
|
+
- 客户端发送命令导致错误时,服务端在返回前记录错误触发来源
|
|
22
|
+
|
|
23
|
+
- 因用户交互导致错误时,需通过toast机制反馈
|
package/src/source.md
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
##### 插件来源(source 字段)
|
|
2
|
-
|
|
3
|
-
- managerName
|
|
4
|
-
- "plugin:{pluginName}" (插件调用)
|
|
5
|
-
- "" (app.emit())
|
|
6
|
-
|
|
7
|
-
##### 客户端/服务端来源(client.name 字段)
|
|
8
|
-
|
|
9
|
-
- "electron" (electron 客户端)
|
|
10
|
-
- "web:{clinetId}" (网络客户端)
|
|
11
|
-
- "server" (服务端)
|
|
12
|
-
- "" (自身环境内)
|
|
13
|
-
|
|
14
|
-
#### 机制
|
|
15
|
-
|
|
16
|
-
- from server/node = source: "plugin:foo"
|
|
17
|
-
- to server/node = source: "plugin:foo" client: ""
|
|
18
|
-
- to client/browser = source: "plugin:foo" client: "server"
|
|
19
|
-
- to client/electron = source: "plugin:foo" client: "server"
|
|
20
|
-
- from client/browser = source: "plugin:foo"
|
|
21
|
-
- to client/browser = source: "plugin:foo" client: ""
|
|
22
|
-
- to server/node = source: "plugin:foo" client: "browser:10000001"
|
|
23
|
-
|
|
24
|
-
ctx.callWithOptions(name, options, ...args)
|
|
25
|
-
ctx.emitWithOptions(name, detail, options)
|
|
26
|
-
|
|
27
|
-
ctx.on()
|
|
28
|
-
|
|
29
|
-
client.emit()
|
|
1
|
+
##### 插件来源(source 字段)
|
|
2
|
+
|
|
3
|
+
- managerName
|
|
4
|
+
- "plugin:{pluginName}" (插件调用)
|
|
5
|
+
- "" (app.emit())
|
|
6
|
+
|
|
7
|
+
##### 客户端/服务端来源(client.name 字段)
|
|
8
|
+
|
|
9
|
+
- "electron" (electron 客户端)
|
|
10
|
+
- "web:{clinetId}" (网络客户端)
|
|
11
|
+
- "server" (服务端)
|
|
12
|
+
- "" (自身环境内)
|
|
13
|
+
|
|
14
|
+
#### 机制
|
|
15
|
+
|
|
16
|
+
- from server/node = source: "plugin:foo"
|
|
17
|
+
- to server/node = source: "plugin:foo" client: ""
|
|
18
|
+
- to client/browser = source: "plugin:foo" client: "server"
|
|
19
|
+
- to client/electron = source: "plugin:foo" client: "server"
|
|
20
|
+
- from client/browser = source: "plugin:foo"
|
|
21
|
+
- to client/browser = source: "plugin:foo" client: ""
|
|
22
|
+
- to server/node = source: "plugin:foo" client: "browser:10000001"
|
|
23
|
+
|
|
24
|
+
ctx.callWithOptions(name, options, ...args)
|
|
25
|
+
ctx.emitWithOptions(name, detail, options)
|
|
26
|
+
|
|
27
|
+
ctx.on()
|
|
28
|
+
|
|
29
|
+
client.emit()
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { App } from "../../index.js";
|
|
2
|
-
import { CommonPluginContext } from "./CommonPluginContext.js";
|
|
3
|
-
/** 核心插件,具有对程序的访问权限 */
|
|
4
|
-
export declare class CorePluginContext extends CommonPluginContext {
|
|
5
|
-
#private;
|
|
6
|
-
constructor(app: App, pluginName: string);
|
|
7
|
-
get app(): App;
|
|
8
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _CorePluginContext_app;
|
|
13
|
-
import { CommonPluginContext } from "./CommonPluginContext.js";
|
|
14
|
-
/** 核心插件,具有对程序的访问权限 */
|
|
15
|
-
export class CorePluginContext extends CommonPluginContext {
|
|
16
|
-
constructor(app, pluginName) {
|
|
17
|
-
super(app, pluginName);
|
|
18
|
-
_CorePluginContext_app.set(this, void 0);
|
|
19
|
-
__classPrivateFieldSet(this, _CorePluginContext_app, app, "f");
|
|
20
|
-
}
|
|
21
|
-
get app() {
|
|
22
|
-
return __classPrivateFieldGet(this, _CorePluginContext_app, "f");
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
_CorePluginContext_app = new WeakMap();
|