@netless/window-manager 0.4.30-canary.1 → 0.4.32

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/AppManager.ts CHANGED
@@ -4,6 +4,8 @@ import { AppListeners } from "./AppListener";
4
4
  import { AppProxy } from "./App";
5
5
  import { appRegister } from "./Register";
6
6
  import { autorun, isPlayer, isRoom, ScenePathType } from "white-web-sdk";
7
+ import { boxEmitter } from "./BoxEmitter";
8
+ import { calculateNextIndex } from "./Page";
7
9
  import { callbacks } from "./callback";
8
10
  import { debounce, get, isInteger, orderBy } from "lodash";
9
11
  import { emitter } from "./InternalEmitter";
@@ -16,7 +18,7 @@ import { RedoUndo } from "./RedoUndo";
16
18
  import { SideEffectManager } from "side-effect-manager";
17
19
  import { ViewManager } from "./View/ViewManager";
18
20
  import type { SyncRegisterAppPayload } from "./Register";
19
- import type { EmitterEvent , RemoveSceneParams } from "./InternalEmitter";
21
+ import type { RemoveSceneParams } from "./InternalEmitter";
20
22
  import {
21
23
  entireScenes,
22
24
  genAppId,
@@ -37,7 +39,14 @@ import type {
37
39
  SceneState,
38
40
  } from "white-web-sdk";
39
41
  import type { AddAppParams, BaseInsertParams, TeleBoxRect } from "./index";
40
- import { calculateNextIndex } from "./Page";
42
+ import type {
43
+ BoxClosePayload,
44
+ BoxFocusPayload,
45
+ BoxMovePayload,
46
+ BoxResizePayload,
47
+ BoxStateChangePayload,
48
+ } from "./BoxEmitter";
49
+
41
50
 
42
51
  export class AppManager {
43
52
  public displayer: Displayer;
@@ -202,27 +211,30 @@ export class AppManager {
202
211
  const scene = this.callbacksNode?.scenes[index];
203
212
  setTimeout(() => {
204
213
  if (scene) {
205
- removeScenes(this.room, `${ROOT_DIR}${scene}`, index)
214
+ removeScenes(this.room, `${ROOT_DIR}${scene}`, index);
206
215
  }
207
216
  }, 100);
208
217
  return new Promise<boolean>((resolve, reject) => {
209
- emitter.once("rootDirSceneRemoved").then(name => {
210
- if (name === scene) {
211
- resolve(true);
212
- }
213
- }).catch(e => {
214
- console.log(`[WindowManager]: removePage error: ${e}`);
215
- reject(false);
216
- });
218
+ emitter
219
+ .once("rootDirSceneRemoved")
220
+ .then(name => {
221
+ if (name === scene) {
222
+ resolve(true);
223
+ }
224
+ })
225
+ .catch(e => {
226
+ console.log(`[WindowManager]: removePage error: ${e}`);
227
+ reject(false);
228
+ });
217
229
  });
218
- }
230
+ };
219
231
 
220
232
  public setSceneIndexWithoutSync = (index: number) => {
221
233
  const sceneName = this.callbacksNode?.scenes[index];
222
234
  if (sceneName) {
223
235
  this.mainViewProxy.setFocusScenePath(`${ROOT_DIR}${sceneName}`);
224
236
  }
225
- }
237
+ };
226
238
 
227
239
  private onSceneChange = (node: ScenesCallbacksNode) => {
228
240
  this.mainViewScenesLength = node.scenes.length;
@@ -299,7 +311,11 @@ export class AppManager {
299
311
  private async onCreated() {
300
312
  await this.attributesUpdateCallback(this.attributes.apps);
301
313
  emitter.emit("updateManagerRect");
302
- emitter.onAny(this.boxEventListener);
314
+ boxEmitter.on("move", this.onBoxMove);
315
+ boxEmitter.on("resize", this.onBoxResize);
316
+ boxEmitter.on("focus", this.onBoxFocus);
317
+ boxEmitter.on("close", this.onBoxClose);
318
+ boxEmitter.on("boxStateChange", this.onBoxStateChange);
303
319
 
304
320
  this.addAppsChangeListener();
305
321
  this.addAppCloseListener();
@@ -352,6 +368,39 @@ export class AppManager {
352
368
  });
353
369
  }
354
370
 
371
+ private onBoxMove = (payload: BoxMovePayload) => {
372
+ this.dispatchInternalEvent(Events.AppMove, payload);
373
+ this.store.updateAppState(payload.appId, AppAttributes.Position, {
374
+ x: payload.x,
375
+ y: payload.y,
376
+ });
377
+ };
378
+
379
+ private onBoxResize = (payload: BoxResizePayload) => {
380
+ if (payload.width && payload.height) {
381
+ this.dispatchInternalEvent(Events.AppResize, payload);
382
+ this.store.updateAppState(payload.appId, AppAttributes.Size, {
383
+ width: payload.width,
384
+ height: payload.height,
385
+ });
386
+ }
387
+ };
388
+
389
+ private onBoxFocus = (payload: BoxFocusPayload) => {
390
+ this.windowManger.safeSetAttributes({ focus: payload.appId });
391
+ };
392
+
393
+ private onBoxClose = (payload: BoxClosePayload) => {
394
+ const appProxy = this.appProxies.get(payload.appId);
395
+ if (appProxy) {
396
+ appProxy.destroy(false, true, true, payload.error);
397
+ }
398
+ };
399
+
400
+ private onBoxStateChange = (payload: BoxStateChangePayload) => {
401
+ this.dispatchInternalEvent(Events.AppBoxStateChange, payload);
402
+ };
403
+
355
404
  public addAppsChangeListener = () => {
356
405
  this.refresher?.add("apps", () => {
357
406
  return safeListenPropsUpdated(
@@ -371,7 +420,6 @@ export class AppManager {
371
420
  });
372
421
  };
373
422
 
374
-
375
423
  private onMainViewIndexChange = (index: number) => {
376
424
  if (index !== undefined && this._prevSceneIndex !== index) {
377
425
  callbacks.emit("mainViewSceneIndexChange", index);
@@ -432,7 +480,7 @@ export class AppManager {
432
480
  if (!appAttributes) {
433
481
  throw new Error("appAttributes is undefined");
434
482
  }
435
- this.appCreateQueue.push(() => {
483
+ this.appCreateQueue.push<AppProxy>(() => {
436
484
  this.appStatus.set(id, AppStatus.StartCreate);
437
485
  return this.baseInsertApp(
438
486
  {
@@ -558,7 +606,7 @@ export class AppManager {
558
606
  private afterAddApp(appProxy: AppProxy | undefined) {
559
607
  if (appProxy && appProxy.box) {
560
608
  const box = appProxy.box;
561
- emitter.emit("move", {
609
+ boxEmitter.emit("move", {
562
610
  appId: appProxy.id,
563
611
  x: box?.intrinsicX,
564
612
  y: box?.intrinsicY,
@@ -694,7 +742,7 @@ export class AppManager {
694
742
  if (this.room) {
695
743
  if (this.store.getMainViewSceneIndex() === index) return;
696
744
  const sceneName = this.callbacksNode?.scenes[index];
697
- const scenePath =`${ROOT_DIR}${sceneName}`;
745
+ const scenePath = `${ROOT_DIR}${sceneName}`;
698
746
  if (sceneName) {
699
747
  const success = this.setMainViewFocusPath(scenePath);
700
748
  if (success) {
@@ -727,46 +775,6 @@ export class AppManager {
727
775
  }
728
776
  }
729
777
 
730
- private boxEventListener = (eventName: keyof EmitterEvent, payload: any) => {
731
- switch (eventName) {
732
- case "move": {
733
- this.dispatchInternalEvent(Events.AppMove, payload);
734
- this.store.updateAppState(payload.appId, AppAttributes.Position, {
735
- x: payload.x,
736
- y: payload.y,
737
- });
738
- break;
739
- }
740
- case "focus": {
741
- this.windowManger.safeSetAttributes({ focus: payload.appId });
742
- break;
743
- }
744
- case "resize": {
745
- if (payload.width && payload.height) {
746
- this.dispatchInternalEvent(Events.AppResize, payload);
747
- this.store.updateAppState(payload.appId, AppAttributes.Size, {
748
- width: payload.width,
749
- height: payload.height,
750
- });
751
- }
752
- break;
753
- }
754
- case "close": {
755
- const appProxy = this.appProxies.get(payload.appId);
756
- if (appProxy) {
757
- appProxy.destroy(false, true, payload.error);
758
- }
759
- break;
760
- }
761
- case "boxStateChange": {
762
- this.dispatchInternalEvent(Events.AppBoxStateChange, payload);
763
- break;
764
- }
765
- default:
766
- break;
767
- }
768
- };
769
-
770
778
  public focusByAttributes(apps: any) {
771
779
  if (apps && Object.keys(apps).length === this.boxManager?.boxSize) {
772
780
  const focusAppId = this.store.focus;
@@ -806,7 +814,7 @@ export class AppManager {
806
814
  this.displayer.callbacks.off(this.eventName, this.displayerStateListener);
807
815
  this.displayer.callbacks.off("onEnableWriteNowChanged", this.displayerWritableListener);
808
816
  this.appListeners.removeListeners();
809
- emitter.offAny(this.boxEventListener);
817
+ boxEmitter.clearListeners();
810
818
  emitter.clearListeners();
811
819
  if (this.appProxies.size) {
812
820
  this.appProxies.forEach(appProxy => {
@@ -0,0 +1,19 @@
1
+ import type { TELE_BOX_STATE } from "@netless/telebox-insider";
2
+ import Emittery from "emittery";
3
+
4
+ export type BoxMovePayload = { appId: string, x: number; y: number };
5
+ export type BoxFocusPayload = { appId: string };
6
+ export type BoxResizePayload = { appId: string, width: number; height: number, x?: number, y?: number };
7
+ export type BoxClosePayload = { appId: string, error?: Error };
8
+ export type BoxStateChangePayload = { appId: string, state: TELE_BOX_STATE };
9
+
10
+ export type BoxEvent = {
11
+ move: BoxMovePayload;
12
+ focus: BoxFocusPayload;
13
+ resize: BoxResizePayload;
14
+ close: BoxClosePayload;
15
+ boxStateChange: BoxStateChangePayload
16
+ }
17
+
18
+ export type BoxEmitterType = Emittery<BoxEvent>;
19
+ export const boxEmitter: BoxEmitterType = new Emittery();
package/src/BoxManager.ts CHANGED
@@ -2,6 +2,7 @@ import { AppAttributes, Events, MIN_HEIGHT, MIN_WIDTH } from "./constants";
2
2
  import { debounce } from "lodash";
3
3
  import { TELE_BOX_STATE, TeleBoxCollector, TeleBoxManager } from "@netless/telebox-insider";
4
4
  import { WindowManager } from "./index";
5
+ import type { BoxEmitterType } from "./BoxEmitter";
5
6
  import type { AddAppOptions, AppInitState } from "./index";
6
7
  import type {
7
8
  TeleBoxManagerUpdateConfig,
@@ -51,6 +52,7 @@ export type BoxManagerContext = {
51
52
  getMainView: () => View;
52
53
  updateAppState: (appId: string, field: AppAttributes, value: any) => void;
53
54
  emitter: EmitterType;
55
+ boxEmitter: BoxEmitterType;
54
56
  callbacks: CallbacksType;
55
57
  canOperate: () => boolean;
56
58
  notifyContainerRectUpdate: (rect: TeleBoxRect) => void;
@@ -62,6 +64,7 @@ export const createBoxManager = (
62
64
  manager: WindowManager,
63
65
  callbacks: CallbacksType,
64
66
  emitter: EmitterType,
67
+ boxEmitter: BoxEmitterType,
65
68
  options: CreateTeleBoxManagerConfig
66
69
  ) => {
67
70
  return new BoxManager(
@@ -76,6 +79,7 @@ export const createBoxManager = (
76
79
  setAppFocus: (appId: string) => manager.appManager?.store.setAppFocus(appId, true),
77
80
  callbacks,
78
81
  emitter,
82
+ boxEmitter
79
83
  },
80
84
  options
81
85
  );
@@ -88,7 +92,7 @@ export class BoxManager {
88
92
  private context: BoxManagerContext,
89
93
  private createTeleBoxManagerConfig?: CreateTeleBoxManagerConfig
90
94
  ) {
91
- const { emitter, callbacks } = context;
95
+ const { emitter, callbacks, boxEmitter } = context;
92
96
  this.teleBoxManager = this.setupBoxManager(createTeleBoxManagerConfig);
93
97
 
94
98
  // 使用 _xxx$.reaction 订阅修改的值, 不管有没有 skipUpdate, 修改值都会触发回调
@@ -123,19 +127,19 @@ export class BoxManager {
123
127
  });
124
128
  this.teleBoxManager.events.on("removed", boxes => {
125
129
  boxes.forEach(box => {
126
- emitter.emit("close", { appId: box.id });
130
+ boxEmitter.emit("close", { appId: box.id });
127
131
  });
128
132
  });
129
133
  this.teleBoxManager.events.on(
130
134
  "intrinsic_move",
131
135
  debounce((box: ReadonlyTeleBox): void => {
132
- emitter.emit("move", { appId: box.id, x: box.intrinsicX, y: box.intrinsicY });
136
+ boxEmitter.emit("move", { appId: box.id, x: box.intrinsicX, y: box.intrinsicY });
133
137
  }, 50)
134
138
  );
135
139
  this.teleBoxManager.events.on(
136
140
  "intrinsic_resize",
137
141
  debounce((box: ReadonlyTeleBox): void => {
138
- emitter.emit("resize", {
142
+ boxEmitter.emit("resize", {
139
143
  appId: box.id,
140
144
  width: box.intrinsicWidth,
141
145
  height: box.intrinsicHeight,
@@ -145,7 +149,7 @@ export class BoxManager {
145
149
  this.teleBoxManager.events.on("focused", box => {
146
150
  if (box) {
147
151
  if (this.canOperate) {
148
- emitter.emit("focus", { appId: box.id });
152
+ boxEmitter.emit("focus", { appId: box.id });
149
153
  } else {
150
154
  this.teleBoxManager.blurBox(box.id);
151
155
  }
@@ -221,7 +225,7 @@ export class BoxManager {
221
225
  const box = this.teleBoxManager.queryOne({ id: appId });
222
226
  if (box) {
223
227
  if (box.state === TELE_BOX_STATE.Maximized) {
224
- this.context.emitter.emit("resize", {
228
+ this.context.boxEmitter.emit("resize", {
225
229
  appId: appId,
226
230
  x: box.x,
227
231
  y: box.y,
@@ -1,5 +1,4 @@
1
1
  import App from "./Cursor.svelte";
2
- import { ApplianceMap } from "./icons";
3
2
  import { ApplianceNames } from "white-web-sdk";
4
3
  import { findMemberByUid } from "../Helper";
5
4
  import { omit } from "lodash";
@@ -159,8 +158,9 @@ export class Cursor {
159
158
 
160
159
  private getIcon() {
161
160
  if (this.member) {
162
- const applianceSrc = ApplianceMap[this.memberApplianceName || ApplianceNames.shape];
163
- return applianceSrc || ApplianceMap[ApplianceNames.shape];
161
+ const icons = this.cursorManager.applianceIcons;
162
+ const applianceSrc = icons[this.memberApplianceName || ApplianceNames.shape];
163
+ return applianceSrc || icons[ApplianceNames.shape];
164
164
  }
165
165
  }
166
166
 
@@ -5,10 +5,11 @@ import { emitter } from "../InternalEmitter";
5
5
  import { SideEffectManager } from "side-effect-manager";
6
6
  import { throttle } from "lodash";
7
7
  import { WindowManager } from "../index";
8
- import type { CursorMovePayload } from "../index";
8
+ import type { CursorMovePayload , ApplianceIcons} from "../index";
9
9
  import type { PositionType } from "../AttributesDelegate";
10
10
  import type { Point, RoomMember, View } from "white-web-sdk";
11
11
  import type { AppManager } from "../AppManager";
12
+ import { ApplianceMap } from "./icons";
12
13
 
13
14
  export type EventType = {
14
15
  type: PositionType;
@@ -20,6 +21,7 @@ export type MoveCursorParams = {
20
21
  x: number;
21
22
  y: number;
22
23
  };
24
+
23
25
  export class CursorManager {
24
26
  public containerRect?: DOMRect;
25
27
  public wrapperRect?: DOMRect;
@@ -28,8 +30,9 @@ export class CursorManager {
28
30
  private mainViewElement?: HTMLDivElement;
29
31
  private sideEffectManager = new SideEffectManager();
30
32
  private store = this.manager.store;
33
+ public applianceIcons: ApplianceIcons = ApplianceMap;
31
34
 
32
- constructor(private manager: AppManager, private enableCursor: boolean) {
35
+ constructor(private manager: AppManager, private enableCursor: boolean, applianceIcons?: ApplianceIcons) {
33
36
  this.roomMembers = this.manager.room?.state.roomMembers;
34
37
  const wrapper = WindowManager.wrapper;
35
38
  if (wrapper) {
@@ -42,6 +45,9 @@ export class CursorManager {
42
45
  this.sideEffectManager.add(() => {
43
46
  return emitter.on("playgroundSizeChange", () => this.updateContainerRect());
44
47
  });
48
+ if (applianceIcons) {
49
+ this.applianceIcons = { ...ApplianceMap, ...applianceIcons };
50
+ }
45
51
  }
46
52
 
47
53
  private onCursorMove = (payload: CursorMovePayload) => {
@@ -8,10 +8,6 @@ export type RemoveSceneParams = {
8
8
  export type EmitterEvent = {
9
9
  onCreated: undefined;
10
10
  InitReplay: AppInitState;
11
- move: { appId: string; x: number; y: number };
12
- focus: { appId: string };
13
- close: { appId: string };
14
- resize: { appId: string; width: number; height: number; x?: number; y?: number };
15
11
  error: Error;
16
12
  seekStart: undefined;
17
13
  seek: number;
@@ -1,8 +1,7 @@
1
1
  import { callbacks } from "../callback";
2
2
  import { SETUP_APP_DELAY } from "../constants";
3
- import type { AppProxy } from "../App";
4
3
 
5
- export type Invoker = () => Promise<AppProxy | undefined>;
4
+ export type Invoker<T = any> = () => Promise<T | undefined>;
6
5
 
7
6
  export class AppCreateQueue {
8
7
  private list: Invoker[] = [];
@@ -16,7 +15,7 @@ export class AppCreateQueue {
16
15
  }, 50);
17
16
  }
18
17
 
19
- public push(item: Invoker) {
18
+ public push<T>(item: Invoker<T>) {
20
19
  this.list.push(item);
21
20
  this.invoke();
22
21
  if (this.timer === undefined && this.list.length > 0) {
package/src/index.ts CHANGED
@@ -29,13 +29,7 @@ import {
29
29
  wait,
30
30
  } from "./Utils/Common";
31
31
  import type { TELE_BOX_STATE, BoxManager } from "./BoxManager";
32
- import {
33
- AppCreateError,
34
- AppManagerNotInitError,
35
- BindContainerRoomPhaseInvalidError,
36
- InvalidScenePath,
37
- ParamsInvalidError,
38
- } from "./Utils/error";
32
+ import * as Errors from "./Utils/error";
39
33
  import type { Apps, Position } from "./AttributesDelegate";
40
34
  import type {
41
35
  Displayer,
@@ -54,12 +48,13 @@ import type {
54
48
  SceneState,
55
49
  } from "white-web-sdk";
56
50
  import type { AppListeners } from "./AppListener";
57
- import type { NetlessApp, RegisterParams } from "./typings";
51
+ import type { ApplianceIcons, NetlessApp, RegisterParams } from "./typings";
58
52
  import type { TeleBoxColorScheme, TeleBoxState } from "@netless/telebox-insider";
59
53
  import type { AppProxy } from "./App";
60
54
  import type { PublicEvent } from "./callback";
61
55
  import type Emittery from "emittery";
62
56
  import type { PageController, AddPageParams, PageState } from "./Page";
57
+ import { boxEmitter } from "./BoxEmitter";
63
58
 
64
59
  export type WindowMangerAttributes = {
65
60
  modelValue?: string;
@@ -142,6 +137,7 @@ export type MountParams = {
142
137
  debug?: boolean;
143
138
  disableCameraTransform?: boolean;
144
139
  prefersColorScheme?: TeleBoxColorScheme;
140
+ applianceIcons?: ApplianceIcons;
145
141
  };
146
142
 
147
143
  export const reconnectRefresher = new ReconnectRefresher({ emitter });
@@ -237,7 +233,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
237
233
 
238
234
  manager.appManager = new AppManager(manager);
239
235
  manager._pageState = new PageStateImpl(manager.appManager);
240
- manager.cursorManager = new CursorManager(manager.appManager, Boolean(cursor));
236
+ manager.cursorManager = new CursorManager(manager.appManager, Boolean(cursor), params.applianceIcons);
241
237
  if (containerSizeRatio) {
242
238
  manager.containerSizeRatio = containerSizeRatio;
243
239
  }
@@ -320,8 +316,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
320
316
  }
321
317
 
322
318
  public bindContainer(container: HTMLElement) {
323
- if (this.room.phase !== RoomPhase.Connected) {
324
- throw new BindContainerRoomPhaseInvalidError();
319
+ if (isRoom(this.displayer) && this.room.phase !== RoomPhase.Connected) {
320
+ throw new Errors.BindContainerRoomPhaseInvalidError();
325
321
  }
326
322
  if (WindowManager.isCreated && WindowManager.container) {
327
323
  if (WindowManager.container.firstChild) {
@@ -339,7 +335,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
339
335
  if (this.boxManager) {
340
336
  this.boxManager.destroy();
341
337
  }
342
- const boxManager = createBoxManager(this, callbacks, emitter, {
338
+ const boxManager = createBoxManager(this, callbacks, emitter, boxEmitter, {
343
339
  collectorContainer: params.collectorContainer,
344
340
  collectorStyles: params.collectorStyles,
345
341
  prefersColorScheme: params.prefersColorScheme,
@@ -407,19 +403,19 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
407
403
  return this._addApp(params);
408
404
  }
409
405
  } else {
410
- throw new AppManagerNotInitError();
406
+ throw new Errors.AppManagerNotInitError();
411
407
  }
412
408
  }
413
409
 
414
410
  private async _addApp<T = any>(params: AddAppParams<T>): Promise<string | undefined> {
415
411
  if (this.appManager) {
416
412
  if (!params.kind || typeof params.kind !== "string") {
417
- throw new ParamsInvalidError();
413
+ throw new Errors.ParamsInvalidError();
418
414
  }
419
415
  const appImpl = await appRegister.appClasses.get(params.kind)?.();
420
416
  if (appImpl && appImpl.config?.singleton) {
421
417
  if (this.appManager.appProxies.has(params.kind)) {
422
- throw new AppCreateError();
418
+ throw new Errors.AppCreateError();
423
419
  }
424
420
  }
425
421
  const isDynamicPPT = this.setupScenePath(params, this.appManager);
@@ -432,7 +428,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
432
428
  const appId = await this.appManager.addApp(params, Boolean(isDynamicPPT));
433
429
  return appId;
434
430
  } else {
435
- throw new AppManagerNotInitError();
431
+ throw new Errors.AppManagerNotInitError();
436
432
  }
437
433
  }
438
434
 
@@ -442,7 +438,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
442
438
  const { scenePath, scenes } = params.options;
443
439
  if (scenePath) {
444
440
  if (!isValidScenePath(scenePath)) {
445
- throw new InvalidScenePath();
441
+ throw new Errors.InvalidScenePath();
446
442
  }
447
443
  const apps = Object.keys(this.apps || {});
448
444
  for (const appId of apps) {
@@ -645,7 +641,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
645
641
  if (this.appManager) {
646
642
  return this.appManager.mainViewProxy.view;
647
643
  } else {
648
- throw new AppManagerNotInitError();
644
+ throw new Errors.AppManagerNotInitError();
649
645
  }
650
646
  }
651
647
 
@@ -653,7 +649,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
653
649
  if (this.appManager) {
654
650
  return this.appManager.mainViewProxy.view.camera;
655
651
  } else {
656
- throw new AppManagerNotInitError();
652
+ throw new Errors.AppManagerNotInitError();
657
653
  }
658
654
  }
659
655
 
@@ -661,7 +657,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
661
657
  if (this.appManager) {
662
658
  return this.appManager.mainViewProxy.cameraState;
663
659
  } else {
664
- throw new AppManagerNotInitError();
660
+ throw new Errors.AppManagerNotInitError();
665
661
  }
666
662
  }
667
663
 
@@ -673,7 +669,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
673
669
  if (this.appManager) {
674
670
  return this.appManager.boxManager?.boxState;
675
671
  } else {
676
- throw new AppManagerNotInitError();
672
+ throw new Errors.AppManagerNotInitError();
677
673
  }
678
674
  }
679
675
 
@@ -685,7 +681,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
685
681
  if (this.appManager) {
686
682
  return this.appManager.boxManager?.prefersColorScheme;
687
683
  } else {
688
- throw new AppManagerNotInitError();
684
+ throw new Errors.AppManagerNotInitError();
689
685
  }
690
686
  }
691
687
 
@@ -705,7 +701,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
705
701
  if (this.appManager) {
706
702
  return this.appManager?.getMainViewSceneDir();
707
703
  } else {
708
- throw new AppManagerNotInitError();
704
+ throw new Errors.AppManagerNotInitError();
709
705
  }
710
706
  }
711
707
 
@@ -730,7 +726,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
730
726
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
731
727
  return this.appManager.sceneState!;
732
728
  } else {
733
- throw new AppManagerNotInitError();
729
+ throw new Errors.AppManagerNotInitError();
734
730
  }
735
731
  }
736
732
 
@@ -738,7 +734,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
738
734
  if (this._pageState) {
739
735
  return this._pageState.toObject();
740
736
  } else {
741
- throw new AppManagerNotInitError();
737
+ throw new Errors.AppManagerNotInitError();
742
738
  }
743
739
  }
744
740
 
package/src/typings.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type Emittery from "emittery";
2
2
  import type {
3
3
  AnimationMode,
4
+ ApplianceNames,
4
5
  Displayer,
5
6
  DisplayerState,
6
7
  Player,
@@ -75,6 +76,8 @@ export type RegisterParams<AppOptions = any, SetupResult = any, Attributes = any
75
76
 
76
77
  export type AppListenerKeys = keyof AppEmitterEvent;
77
78
 
79
+ export type ApplianceIcons = Partial<Record<ApplianceNames, string>>;
80
+
78
81
  export type { AppContext } from "./App/AppContext";
79
82
  export type { ReadonlyTeleBox, TeleBoxRect };
80
83
  export type { SceneState, SceneDefinition, View, AnimationMode, Displayer, Room, Player };
@@ -1,12 +0,0 @@
1
- import type { ScenesCallbacks, ScenesCallbacksNode } from "white-web-sdk";
2
- import type { AppManager } from "../AppManager";
3
- export declare class ScenesCallbackManager {
4
- private manager;
5
- private nodes;
6
- constructor(manager: AppManager);
7
- createNode(path: string, callbacks?: Partial<ScenesCallbacks>): ScenesCallbacksNode | null;
8
- getScenes(path: string): readonly string[] | undefined;
9
- getScenesOnce(path: string): readonly string[] | undefined;
10
- removeNode(path: string): void;
11
- destroy(): void;
12
- }
@@ -1,47 +0,0 @@
1
- import type { ScenesCallbacks, ScenesCallbacksNode } from "white-web-sdk";
2
- import type { AppManager } from "../AppManager";
3
-
4
- export class ScenesCallbackManager {
5
-
6
- private nodes: Map<string, ScenesCallbacksNode> = new Map();
7
-
8
- constructor(private manager: AppManager) {}
9
-
10
- public createNode(path: string, callbacks?: Partial<ScenesCallbacks>): ScenesCallbacksNode | null {
11
- const node = this.manager.displayer.createScenesCallback(path, callbacks);
12
- if (node) {
13
- this.nodes.set(path, node);
14
- }
15
- return node;
16
- }
17
-
18
- public getScenes(path: string) {
19
- const node = this.nodes.get(path);
20
- return node?.scenes;
21
- }
22
-
23
- public getScenesOnce(path: string) {
24
- let node = this.nodes.get(path);
25
- if (!node) {
26
- const created = this.createNode(path);
27
- if (created) {
28
- node = created;
29
- }
30
- }
31
- const scenes = node?.scenes;
32
- this.removeNode(path);
33
- return scenes;
34
- }
35
-
36
- public removeNode(path: string) {
37
- const node = this.nodes.get(path);
38
- if (node) {
39
- node.dispose();
40
- this.nodes.delete(path);
41
- }
42
- }
43
-
44
- public destroy(): void {
45
- this.nodes.forEach(node => node.dispose());
46
- }
47
- }