@netless/window-manager 1.0.5 → 1.0.6-beta.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/dist/index.d.ts +27 -1
- package/dist/index.js +15 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/AppManager.ts +6 -2
- package/src/ExtendPluginManager.ts +49 -0
- package/src/index.ts +11 -0
package/package.json
CHANGED
package/src/AppManager.ts
CHANGED
@@ -523,7 +523,7 @@ export class AppManager {
|
|
523
523
|
throw new Error("appAttributes is undefined");
|
524
524
|
}
|
525
525
|
|
526
|
-
this.appCreateQueue.push<AppProxy>(async() => {
|
526
|
+
this.appCreateQueue.push<AppProxy>(async () => {
|
527
527
|
this.appStatus.set(id, AppStatus.StartCreate);
|
528
528
|
const appProxy = await this.baseInsertApp(
|
529
529
|
{
|
@@ -534,7 +534,11 @@ export class AppManager {
|
|
534
534
|
id,
|
535
535
|
false
|
536
536
|
);
|
537
|
-
if (
|
537
|
+
if (
|
538
|
+
appProxy &&
|
539
|
+
this.store.focus === id &&
|
540
|
+
this._focusAppCreatedResolve
|
541
|
+
) {
|
538
542
|
this._focusAppCreatedResolve(appProxy);
|
539
543
|
}
|
540
544
|
return appProxy;
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import type { WindowManager } from ".";
|
2
|
+
import Emittery from "emittery";
|
3
|
+
import type { EmitterType } from "./InternalEmitter";
|
4
|
+
|
5
|
+
export interface ExtendContext {
|
6
|
+
readonly manager: ExtendPluginManager;
|
7
|
+
readonly windowManager: WindowManager;
|
8
|
+
readonly internalEmitter: EmitterType;
|
9
|
+
}
|
10
|
+
|
11
|
+
export abstract class ExtendPlugin extends Emittery {
|
12
|
+
context!: ExtendContext;
|
13
|
+
abstract readonly kind: string;
|
14
|
+
protected _inject(context: ExtendContext) {
|
15
|
+
this.context = context;
|
16
|
+
}
|
17
|
+
abstract onCreate(): void;
|
18
|
+
abstract onDestroy(): void;
|
19
|
+
}
|
20
|
+
|
21
|
+
export type ExtendPluginInstance<T extends ExtendPlugin> = T;
|
22
|
+
|
23
|
+
export interface ExtendManagerOptions {
|
24
|
+
readonly windowManager: WindowManager;
|
25
|
+
readonly internalEmitter: EmitterType;
|
26
|
+
}
|
27
|
+
|
28
|
+
export class ExtendPluginManager {
|
29
|
+
private extends: Map<string, ExtendPluginInstance<any>> = new Map();
|
30
|
+
private context: ExtendContext;
|
31
|
+
constructor(props: ExtendManagerOptions) {
|
32
|
+
this.context = {
|
33
|
+
manager: this,
|
34
|
+
windowManager: props.windowManager,
|
35
|
+
internalEmitter: props.internalEmitter,
|
36
|
+
};
|
37
|
+
}
|
38
|
+
use(extend: ExtendPluginInstance<any>) {
|
39
|
+
this.extends.set(extend.kind, extend);
|
40
|
+
extend._inject(this.context);
|
41
|
+
extend.onCreate();
|
42
|
+
}
|
43
|
+
destroy() {
|
44
|
+
this.extends.forEach(extend => {
|
45
|
+
this.extends.delete(extend.kind);
|
46
|
+
extend.onDestroy();
|
47
|
+
});
|
48
|
+
}
|
49
|
+
}
|
package/src/index.ts
CHANGED
@@ -57,6 +57,7 @@ import type { PageController, AddPageParams, PageState } from "./Page";
|
|
57
57
|
import { boxEmitter } from "./BoxEmitter";
|
58
58
|
import { IframeBridge } from "./View/IframeBridge";
|
59
59
|
import { setOptions } from "@netless/app-media-player";
|
60
|
+
import { ExtendPluginManager } from "./ExtendPluginManager";
|
60
61
|
export * from "./View/IframeBridge";
|
61
62
|
|
62
63
|
export type WindowMangerAttributes = {
|
@@ -196,6 +197,8 @@ export class WindowManager
|
|
196
197
|
private containerResizeObserver?: ContainerResizeObserver;
|
197
198
|
public containerSizeRatio = WindowManager.containerSizeRatio;
|
198
199
|
|
200
|
+
private extendPluginManager?: ExtendPluginManager;
|
201
|
+
|
199
202
|
constructor(context: InvisiblePluginContext) {
|
200
203
|
super(context);
|
201
204
|
WindowManager.displayer = context.displayer;
|
@@ -275,6 +278,11 @@ export class WindowManager
|
|
275
278
|
params.cursorOptions,
|
276
279
|
params.applianceIcons
|
277
280
|
);
|
281
|
+
manager.extendPluginManager = new ExtendPluginManager({
|
282
|
+
internalEmitter: internalEmitter,
|
283
|
+
windowManager: manager,
|
284
|
+
});
|
285
|
+
|
278
286
|
if (containerSizeRatio) {
|
279
287
|
manager.containerSizeRatio = containerSizeRatio;
|
280
288
|
}
|
@@ -919,6 +927,7 @@ export class WindowManager
|
|
919
927
|
this.containerResizeObserver?.disconnect();
|
920
928
|
this.appManager?.destroy();
|
921
929
|
this.cursorManager?.destroy();
|
930
|
+
this.extendPluginManager?.destroy();
|
922
931
|
WindowManager.container = undefined;
|
923
932
|
WindowManager.wrapper = undefined;
|
924
933
|
WindowManager.sizer = undefined;
|
@@ -1091,3 +1100,5 @@ export * from "./typings";
|
|
1091
1100
|
|
1092
1101
|
export { BuiltinApps } from "./BuiltinApps";
|
1093
1102
|
export type { PublicEvent } from "./callback";
|
1103
|
+
|
1104
|
+
export * from "./ExtendPluginManager";
|