@netless/window-manager 0.4.15 → 0.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/window-manager",
3
- "version": "0.4.15",
3
+ "version": "0.4.16",
4
4
  "description": "",
5
5
  "main": "dist/index.es.js",
6
6
  "module": "dist/index.es.js",
@@ -99,6 +99,8 @@ export class AppListeners {
99
99
  };
100
100
 
101
101
  private rootDirRemovedHandler = () => {
102
- this.manager.onRootDirRemoved();
103
- };
102
+ this.manager.createRootDirScenesCallback();
103
+ this.manager.mainViewProxy.rebind();
104
+ emitter.emit("rootDirRemoved");
105
+ }
104
106
  }
package/src/AppManager.ts CHANGED
@@ -59,6 +59,8 @@ export class AppManager {
59
59
 
60
60
  public sceneState: SceneState | null = null;
61
61
 
62
+ public rootDirRemoving = false;
63
+
62
64
  constructor(public windowManger: WindowManager) {
63
65
  this.displayer = windowManger.displayer;
64
66
  this.store.setContext({
@@ -106,10 +108,10 @@ export class AppManager {
106
108
  });
107
109
  }
108
110
 
109
- private onRemoveScenes = (scenePath: string) => {
111
+ private onRemoveScenes = async (scenePath: string) => {
110
112
  // 如果移除根目录就把 scenePath 设置为初始值
111
113
  if (scenePath === ROOT_DIR) {
112
- this.onRootDirRemoved();
114
+ await this.onRootDirRemoved();
113
115
  this.dispatchInternalEvent(Events.RootDirRemoved);
114
116
  return;
115
117
  }
@@ -127,19 +129,22 @@ export class AppManager {
127
129
  * 根目录被删除时所有的 scene 都会被删除.
128
130
  * 所以需要关掉所有开启了 view 的 app
129
131
  */
130
- public onRootDirRemoved() {
132
+ public async onRootDirRemoved(needClose = true) {
133
+ this.rootDirRemoving = true;
131
134
  this.setMainViewScenePath(INIT_DIR);
132
- this.createRootDirScenesCallback();
133
135
 
134
- this.appProxies.forEach(appProxy => {
136
+ this.createRootDirScenesCallback();
137
+
138
+ for (const [id, appProxy] of this.appProxies.entries()) {
135
139
  if (appProxy.view) {
136
- this.closeApp(appProxy.id);
140
+ await this.closeApp(id, needClose);
137
141
  }
138
- });
142
+ }
139
143
  // 删除了根目录的 scenes 之后 mainview 需要重新绑定, 否则主白板会不能渲染
140
144
  this.mainViewProxy.rebind();
141
145
 
142
146
  emitter.emit("rootDirRemoved");
147
+ this.rootDirRemoving = false;
143
148
  }
144
149
 
145
150
  private onReadonlyChanged = () => {
@@ -159,7 +164,7 @@ export class AppManager {
159
164
  });
160
165
  };
161
166
 
162
- private createRootDirScenesCallback = () => {
167
+ public createRootDirScenesCallback = () => {
163
168
  let isRecreate = false;
164
169
  if (this.callbacksNode) {
165
170
  this.callbacksNode.dispose();
@@ -361,14 +366,13 @@ export class AppManager {
361
366
  for (const { id } of orderBy(appsWithCreatedAt, "createdAt", "asc")) {
362
367
  if (!this.appProxies.has(id) && !this.appStatus.has(id)) {
363
368
  const app = apps[id];
364
-
365
- this.appStatus.set(id, AppStatus.StartCreate);
366
369
  try {
367
370
  const appAttributes = this.attributes[id];
368
371
  if (!appAttributes) {
369
372
  throw new Error("appAttributes is undefined");
370
373
  }
371
374
  this.appCreateQueue.push(() => {
375
+ this.appStatus.set(id, AppStatus.StartCreate);
372
376
  return this.baseInsertApp(
373
377
  {
374
378
  kind: app.kind,
@@ -505,10 +509,10 @@ export class AppManager {
505
509
  }
506
510
  }
507
511
 
508
- public async closeApp(appId: string) {
512
+ public async closeApp(appId: string, needClose = true) {
509
513
  const appProxy = this.appProxies.get(appId);
510
514
  if (appProxy) {
511
- appProxy.destroy(true, true, false);
515
+ appProxy.destroy(true, needClose, false);
512
516
  }
513
517
  }
514
518
 
package/src/AppProxy.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Emittery from "emittery";
2
- import { AppAttributes, AppEvents, Events } from "./constants";
2
+ import { AppAttributes, AppEvents, Events, SETUP_APP_DELAY } from "./constants";
3
3
  import { AppContext } from "./AppContext";
4
4
  import { appRegister } from "./Register";
5
5
  import { autorun } from "white-web-sdk";
@@ -168,7 +168,7 @@ export class AppProxy {
168
168
  appRegister.notifyApp(this.kind, "created", { appId, result });
169
169
  this.afterSetupApp(boxInitState);
170
170
  this.fixMobileSize();
171
- }, 50);
171
+ }, SETUP_APP_DELAY);
172
172
  });
173
173
  this.boxManager?.createBox({
174
174
  appId: appId,
@@ -346,6 +346,7 @@ export class AppProxy {
346
346
 
347
347
  public setViewFocusScenePath() {
348
348
  const fullPath = this.getFullScenePath();
349
+ console.log("setViewFocusScenePath", this.kind, this.id, fullPath)
349
350
  if (fullPath && this.view) {
350
351
  setViewFocusScenePath(this.view, fullPath);
351
352
  }
@@ -380,6 +381,7 @@ export class AppProxy {
380
381
  if (cleanAttrs) {
381
382
  this.store.cleanAppAttributes(this.id);
382
383
  if (this.scenePath) {
384
+ console.log("put closeApp", this.scenePath);
383
385
  removeScenes(this.manager.room, this.scenePath);
384
386
  }
385
387
  }
@@ -1,5 +1,6 @@
1
1
  import { callbacks } from "../callback";
2
2
  import type { AppProxy } from "../AppProxy";
3
+ import { SETUP_APP_DELAY } from "../constants";
3
4
 
4
5
  export type Invoker = () => Promise<AppProxy | undefined>;
5
6
 
@@ -60,11 +61,18 @@ export class AppCreateQueue {
60
61
 
61
62
  public emitReady() {
62
63
  if (!this.isEmit) {
63
- callbacks.emit("ready");
64
+ setTimeout(() => {
65
+ callbacks.emit("ready");
66
+ }, SETUP_APP_DELAY);
64
67
  }
65
68
  this.isEmit = true;
66
69
  }
67
70
 
71
+ public empty() {
72
+ this.list = [];
73
+ this.clear();
74
+ }
75
+
68
76
  public destroy() {
69
77
  if (this.timer) {
70
78
  this.clear();
@@ -1,12 +1,12 @@
1
1
  import { appRegister } from "../Register";
2
2
  import { debounce } from "lodash";
3
3
  import { emitter } from "../InternalEmitter";
4
+ import { ROOT_DIR } from "../constants";
4
5
  import { ScenePathType } from "white-web-sdk";
5
6
  import { v4 } from "uuid";
6
7
  import type { PublicEvent } from "../callback";
7
- import type { Displayer, ViewVisionMode, Room, View } from "white-web-sdk";
8
+ import type { Displayer, ViewVisionMode, Room, View , SceneDefinition} from "white-web-sdk";
8
9
  import type Emittery from "emittery";
9
- import { ROOT_DIR } from "../constants";
10
10
 
11
11
  export const genAppId = async (kind: string) => {
12
12
  const impl = await appRegister.appClasses.get(kind)?.();
@@ -104,6 +104,9 @@ export const entireScenes = (displayer: Displayer) => {
104
104
  return displayer.entireScenes();
105
105
  };
106
106
 
107
+ export const putScenes = (room: Room | undefined, path: string, scenes: SceneDefinition[]) => {
108
+ return room?.putScenes(path, scenes);
109
+ }
107
110
 
108
111
  export const isValidScenePath = (scenePath: string) => {
109
112
  return scenePath.startsWith("/");
package/src/constants.ts CHANGED
@@ -51,3 +51,5 @@ export const DEFAULT_CONTAINER_RATIO = 9 / 16;
51
51
 
52
52
  export const ROOT_DIR = "/";
53
53
  export const INIT_DIR = "/init";
54
+
55
+ export const SETUP_APP_DELAY = 50;
package/src/index.ts CHANGED
@@ -25,6 +25,7 @@ import {
25
25
  ensureValidScenePath,
26
26
  entireScenes,
27
27
  isValidScenePath,
28
+ putScenes,
28
29
  wait,
29
30
  } from "./Utils/Common";
30
31
  import type { TELE_BOX_STATE, BoxManager } from "./BoxManager";
@@ -387,6 +388,28 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
387
388
  * 创建一个 app 至白板
388
389
  */
389
390
  public async addApp<T = any>(params: AddAppParams<T>): Promise<string | undefined> {
391
+ if (this.appManager) {
392
+ // 移除根目录时需要做一些异步的释放操作 addApp 需要等待释放完成才可以继续添加
393
+ if (this.appManager.rootDirRemoving) {
394
+ return new Promise((resolve, reject) => {
395
+ emitter.once("rootDirRemoved").then(async () => {
396
+ try {
397
+ const appId = await this._addApp(params);
398
+ resolve(appId);
399
+ } catch (error) {
400
+ reject(error.message);
401
+ }
402
+ });
403
+ });
404
+ } else {
405
+ return this._addApp(params);
406
+ }
407
+ } else {
408
+ throw new AppManagerNotInitError();
409
+ }
410
+ }
411
+
412
+ private async _addApp<T = any>(params: AddAppParams<T>): Promise<string | undefined> {
390
413
  if (this.appManager) {
391
414
  if (!params.kind || typeof params.kind !== "string") {
392
415
  throw new ParamsInvalidError();
@@ -438,16 +461,16 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
438
461
  if (this.isDynamicPPT(scenes)) {
439
462
  isDynamicPPT = true;
440
463
  if (!entireScenes(this.displayer)[scenePath]) {
441
- this.room?.putScenes(scenePath, scenes);
464
+ putScenes(this.room, scenePath, scenes);
442
465
  }
443
466
  } else {
444
467
  if (!entireScenes(this.displayer)[scenePath]) {
445
- this.room?.putScenes(scenePath, [{ name: scenes[0].name }]);
468
+ putScenes(this.room, scenePath, [{ name: scenes[0].name }]);
446
469
  }
447
470
  }
448
471
  }
449
472
  if (scenePath && scenes === undefined) {
450
- this.room?.putScenes(scenePath, [{}]);
473
+ putScenes(this.room, scenePath, [{}]);
451
474
  }
452
475
  }
453
476
  return isDynamicPPT;