@netless/window-manager 0.4.21 → 0.4.22

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.21",
3
+ "version": "0.4.22",
4
4
  "description": "",
5
5
  "main": "dist/index.es.js",
6
6
  "module": "dist/index.es.js",
@@ -63,6 +63,10 @@ export class AppListeners {
63
63
  this.refreshHandler();
64
64
  break;
65
65
  }
66
+ case Events.InitMainViewCamera: {
67
+ this.initMainViewCameraHandler();
68
+ break;
69
+ }
66
70
  default:
67
71
  break;
68
72
  }
@@ -111,4 +115,8 @@ export class AppListeners {
111
115
  private refreshHandler = () => {
112
116
  this.manager.windowManger._refresh();
113
117
  }
118
+
119
+ private initMainViewCameraHandler = () => {
120
+ this.manager.mainViewProxy.addCameraReaction();
121
+ }
114
122
  }
package/src/AppManager.ts CHANGED
@@ -5,9 +5,9 @@ import { AppProxy } from "./App";
5
5
  import { appRegister } from "./Register";
6
6
  import { autorun, isPlayer, isRoom, ScenePathType } from "white-web-sdk";
7
7
  import { callbacks } from "./callback";
8
+ import { debounce, get, isInteger, orderBy } from "lodash";
8
9
  import { emitter } from "./InternalEmitter";
9
10
  import { Fields, store } from "./AttributesDelegate";
10
- import { debounce, get, isInteger, orderBy } from "lodash";
11
11
  import { log } from "./Utils/log";
12
12
  import { MainViewProxy } from "./View/MainView";
13
13
  import { onObjectRemoved, safeListenPropsUpdated } from "./Utils/Reactive";
@@ -132,7 +132,7 @@ export class AppManager {
132
132
  public async onRootDirRemoved(needClose = true) {
133
133
  this.setMainViewScenePath(INIT_DIR);
134
134
  this.createRootDirScenesCallback();
135
-
135
+
136
136
  for (const [id, appProxy] of this.appProxies.entries()) {
137
137
  if (appProxy.view) {
138
138
  await this.closeApp(id, needClose);
@@ -312,7 +312,7 @@ export class AppManager {
312
312
  }
313
313
  );
314
314
  });
315
- }
315
+ };
316
316
 
317
317
  public addAppCloseListener = () => {
318
318
  this.refresher?.add("appsClose", () => {
@@ -320,7 +320,7 @@ export class AppManager {
320
320
  this.onAppDelete(this.attributes.apps);
321
321
  });
322
322
  });
323
- }
323
+ };
324
324
 
325
325
  private onMainViewIndexChange = (index: number) => {
326
326
  if (index !== undefined && this._prevSceneIndex !== index) {
@@ -331,7 +331,7 @@ export class AppManager {
331
331
  }
332
332
  this._prevSceneIndex = index;
333
333
  }
334
- }
334
+ };
335
335
 
336
336
  private onFocusChange = (focused: string | undefined) => {
337
337
  if (this._prevFocused !== focused) {
@@ -349,9 +349,12 @@ export class AppManager {
349
349
  }, 0);
350
350
  }
351
351
  }
352
- }
352
+ };
353
353
 
354
- public attributesUpdateCallback = debounce((apps: any) => this._attributesUpdateCallback(apps), 100);
354
+ public attributesUpdateCallback = debounce(
355
+ (apps: any) => this._attributesUpdateCallback(apps),
356
+ 100
357
+ );
355
358
 
356
359
  /**
357
360
  * 插件更新 attributes 时的回调
@@ -742,7 +745,7 @@ export class AppManager {
742
745
 
743
746
  public updateRootDirRemoving = (removing: boolean) => {
744
747
  this.rootDirRemoving = removing;
745
- }
748
+ };
746
749
 
747
750
  public dispatchInternalEvent(event: Events, payload?: any) {
748
751
  this.safeDispatchMagixEvent(MagixEventName, {
@@ -8,6 +8,7 @@ import { setViewFocusScenePath } from "../Utils/Common";
8
8
  import { SideEffectManager } from "side-effect-manager";
9
9
  import type { Camera, Size, View } from "white-web-sdk";
10
10
  import type { AppManager } from "../AppManager";
11
+ import { Events } from "../constants";
11
12
 
12
13
  export class MainViewProxy {
13
14
  private scale?: number;
@@ -22,13 +23,12 @@ export class MainViewProxy {
22
23
  this.mainView = this.createMainView();
23
24
  this.moveCameraSizeByAttributes();
24
25
  emitter.once("mainViewMounted").then(() => {
25
- setTimeout(() => {
26
- this.addMainViewListener();
27
- this.start();
28
- if (!this.mainViewCamera || !this.mainViewSize) {
29
- this.setCameraAndSize();
30
- }
31
- }, 200); // 等待 mainView 挂载完毕再进行监听,否则会触发不必要的 onSizeUpdated
26
+ this.addMainViewListener();
27
+ this.start();
28
+ if (!this.mainViewCamera || !this.mainViewSize) {
29
+ manager.dispatchInternalEvent(Events.InitMainViewCamera)
30
+ this.setCameraAndSize();
31
+ }
32
32
  });
33
33
  const playgroundSizeChangeListener = () => {
34
34
  this.sizeChangeHandler(this.mainViewSize);
@@ -56,10 +56,14 @@ export class MainViewProxy {
56
56
  if (this.started) return;
57
57
  this.sizeChangeHandler(this.mainViewSize);
58
58
  this.addCameraListener();
59
- this.manager.refresher?.add(Fields.MainViewCamera, this.cameraReaction);
59
+ this.addCameraReaction();
60
60
  this.started = true;
61
61
  }
62
62
 
63
+ public addCameraReaction = () => {
64
+ this.manager.refresher?.add(Fields.MainViewCamera, this.cameraReaction);
65
+ }
66
+
63
67
  public setCameraAndSize(): void {
64
68
  this.store.setMainViewCamera({ ...this.mainView.camera, id: this.manager.uid });
65
69
  this.store.setMainViewSize({ ...this.mainView.size, id: this.manager.uid });
@@ -73,10 +77,7 @@ export class MainViewProxy {
73
77
  this.moveCameraToContian(this.mainViewSize);
74
78
  this.moveCamera(camera);
75
79
  }
76
- },
77
- {
78
- fireImmediately: true,
79
- }
80
+ }, { fireImmediately: true }
80
81
  );
81
82
  };
82
83
 
package/src/constants.ts CHANGED
@@ -15,6 +15,7 @@ export enum Events {
15
15
  CursorMove = "CursorMove",
16
16
  RootDirRemoved = "RootDirRemoved",
17
17
  Refresh = "Refresh",
18
+ InitMainViewCamera = "InitMainViewCamera",
18
19
  }
19
20
 
20
21
  export const MagixEventName = "__WindowManger";