@netless/window-manager 0.4.0-canary.15 → 0.4.0-canary.16

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/src/AppContext.ts CHANGED
@@ -59,10 +59,7 @@ export class AppContext<TAttributes = any, TMagixEventPayloads = any, TAppOption
59
59
  public getScenes = (): SceneDefinition[] | undefined => {
60
60
  const appAttr = this.store.getAppAttributes(this.appId);
61
61
  if (appAttr?.isDynamicPPT) {
62
- const appProxy = this.manager.appProxies.get(this.appId);
63
- if (appProxy) {
64
- return appProxy.scenes;
65
- }
62
+ return this.appProxy.scenes;
66
63
  } else {
67
64
  return appAttr?.options["scenes"];
68
65
  }
package/src/AppProxy.ts CHANGED
@@ -7,7 +7,7 @@ import { emitter } from "./index";
7
7
  import { Fields } from "./AttributesDelegate";
8
8
  import { debounce, get } from "lodash";
9
9
  import { log } from "./Utils/log";
10
- import { setScenePath, setViewFocusScenePath, getScenePath } from "./Utils/Common";
10
+ import { setScenePath, setViewFocusScenePath, getScenePath, removeScenes } from "./Utils/Common";
11
11
  import type {
12
12
  AppEmitterEvent,
13
13
  AppInitState,
@@ -377,6 +377,9 @@ export class AppProxy extends Base {
377
377
  }
378
378
  if (cleanAttrs) {
379
379
  this.store.cleanAppAttributes(this.id);
380
+ if (this.scenePath) {
381
+ removeScenes(this.manager.room, this.scenePath);
382
+ }
380
383
  }
381
384
  this.appProxies.delete(this.id);
382
385
 
package/src/BoxManager.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  TELE_BOX_STATE,
6
6
  TeleBoxCollector,
7
7
  TeleBoxManager,
8
+ TeleBoxConfig,
8
9
  } from "@netless/telebox-insider";
9
10
  import { emitter, WindowManager } from "./index";
10
11
  import type { AddAppOptions, AppInitState, EmitterType, CallbacksType } from "./index";
@@ -379,6 +380,10 @@ export class BoxManager {
379
380
  }
380
381
  }
381
382
 
383
+ public updateBox(id: string, payload: TeleBoxConfig, skipUpdate = true): void {
384
+ this.teleBoxManager.update(id, payload, skipUpdate);
385
+ }
386
+
382
387
  public setReadonly(readonly: boolean) {
383
388
  this.teleBoxManager.setReadonly(readonly);
384
389
  }
@@ -10,34 +10,39 @@ class AppRegister {
10
10
 
11
11
  public async register(params: RegisterParams): Promise<void> {
12
12
  this.registered.set(params.kind, params);
13
-
14
- const srcOrAppOrFunction = params.src
15
- let downloadApp: () => Promise<NetlessApp>
16
-
13
+
14
+ const srcOrAppOrFunction = params.src;
15
+ let downloadApp: () => Promise<NetlessApp>;
16
+
17
17
  if (typeof srcOrAppOrFunction === "string") {
18
18
  downloadApp = async () => {
19
- const appClass = await loadApp(srcOrAppOrFunction, params.kind);
19
+ let appClass = (await loadApp(srcOrAppOrFunction, params.kind)) as any;
20
20
  if (appClass) {
21
- return appClass
21
+ if (appClass.__esModule) {
22
+ appClass = appClass.default;
23
+ }
24
+ return appClass;
22
25
  } else {
23
- throw new Error(`[WindowManager]: load remote script failed, ${srcOrAppOrFunction}`);
26
+ throw new Error(
27
+ `[WindowManager]: load remote script failed, ${srcOrAppOrFunction}`
28
+ );
24
29
  }
25
- }
30
+ };
26
31
  } else if (typeof srcOrAppOrFunction === "function") {
27
- downloadApp = srcOrAppOrFunction
32
+ downloadApp = srcOrAppOrFunction;
28
33
  } else {
29
- downloadApp = async () => srcOrAppOrFunction
34
+ downloadApp = async () => srcOrAppOrFunction;
30
35
  }
31
36
 
32
37
  this.appClasses.set(params.kind, async () => {
33
- let app = this.appClassesCache.get(params.kind)
38
+ let app = this.appClassesCache.get(params.kind);
34
39
  if (!app) {
35
- app = downloadApp()
36
- this.appClassesCache.set(params.kind, app)
40
+ app = downloadApp();
41
+ this.appClassesCache.set(params.kind, app);
37
42
  }
38
- return app
43
+ return app;
39
44
  });
40
-
45
+
41
46
  if (params.addHooks) {
42
47
  const emitter = this.createKindEmitter(params.kind);
43
48
  if (emitter) {
@@ -46,7 +51,11 @@ class AppRegister {
46
51
  }
47
52
  }
48
53
 
49
- public async notifyApp<T extends keyof RegisterEvents>(kind: string, event: T, payload: RegisterEvents[T]) {
54
+ public async notifyApp<T extends keyof RegisterEvents>(
55
+ kind: string,
56
+ event: T,
57
+ payload: RegisterEvents[T]
58
+ ) {
50
59
  const emitter = this.kindEmitters.get(kind);
51
60
  await emitter?.emit(event, payload);
52
61
  }
@@ -8,7 +8,7 @@ const TIMEOUT = 10000; // 10 秒超时
8
8
  export const getScript = async (url: string): Promise<string> => {
9
9
  const item = await getItem(url);
10
10
  if (item) {
11
- return item;
11
+ return item.sourceCode;
12
12
  } else {
13
13
  const result = await fetchWithTimeout(url, { timeout: TIMEOUT });
14
14
  const text = await result.text();
@@ -3,6 +3,11 @@ const DatabaseName = "__WindowManagerAppCache";
3
3
  let db: IDBDatabase;
4
4
  let store: IDBObjectStore;
5
5
 
6
+ export type Item = {
7
+ kind: string;
8
+ sourceCode: string;
9
+ }
10
+
6
11
  export const initDb = async () => {
7
12
  db = await createDb();
8
13
  }
@@ -12,7 +17,7 @@ export const setItem = (key: string, val: any) => {
12
17
  return addRecord(db, { kind: key, sourceCode: val })
13
18
  };
14
19
 
15
- export const getItem = async (key: string): Promise<string | null> => {
20
+ export const getItem = async (key: string): Promise<Item | null> => {
16
21
  if (!db) return null;
17
22
  return await query(db, key);
18
23
  };
@@ -1,6 +1,7 @@
1
1
  import { appRegister } from "../Register";
2
2
  import { debounce } from "lodash";
3
3
  import { emitter } from "../index";
4
+ import { ScenePathType } from "white-web-sdk";
4
5
  import { v4 } from "uuid";
5
6
  import type { PublicEvent } from "../index";
6
7
  import type { Displayer, ViewVisionMode, Room, View } from "white-web-sdk";
@@ -26,7 +27,7 @@ export const setViewSceneIndex = (view: View, index: number) => {
26
27
  view.focusSceneIndex = index;
27
28
  return view;
28
29
  }
29
- }
30
+ };
30
31
 
31
32
  export const setScenePath = (room: Room | undefined, scenePath: string) => {
32
33
  if (room && room.isWritable) {
@@ -50,6 +51,15 @@ export const getScenePath = (
50
51
  }
51
52
  };
52
53
 
54
+ export const removeScenes = (room: Room | undefined, scenePath: string) => {
55
+ if (room) {
56
+ const type = room.scenePathType(scenePath);
57
+ if (type !== ScenePathType.None) {
58
+ room.removeScenes(scenePath);
59
+ }
60
+ }
61
+ };
62
+
53
63
  export const setViewMode = (view: View, mode: ViewVisionMode) => {
54
64
  if (!(view as any).didRelease && view.mode !== mode) {
55
65
  view.mode = mode;
@@ -105,7 +115,7 @@ export const parseSceneDir = (scenePath: string) => {
105
115
  sceneDir = "/";
106
116
  }
107
117
  return sceneDir;
108
- }
118
+ };
109
119
 
110
120
  export const ensureValidScenePath = (scenePath: string) => {
111
121
  if (scenePath.endsWith("/")) {
package/src/index.ts CHANGED
@@ -428,6 +428,12 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
428
428
  const appScenePath = appManager.store.getAppScenePath(appId);
429
429
  if (appScenePath && appScenePath === scenePath) {
430
430
  console.warn(`[WindowManager]: ScenePath ${scenePath} Already opened`);
431
+ if (this.boxManager) {
432
+ const topBox = this.boxManager.getTopBox();
433
+ if (topBox) {
434
+ this.boxManager.setZIndex(appId, topBox.zIndex + 1, false);
435
+ }
436
+ }
431
437
  return;
432
438
  }
433
439
  }