@netless/window-manager 1.0.12 → 1.0.13-bate.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/src/index.ts CHANGED
@@ -47,6 +47,7 @@ import type {
47
47
  Player,
48
48
  ImageInformation,
49
49
  SceneState,
50
+ Logger,
50
51
  } from "white-web-sdk";
51
52
  import type { AppListeners } from "./AppListener";
52
53
  import type { ApplianceIcons, NetlessApp, RegisterParams } from "./typings";
@@ -242,10 +243,17 @@ export class WindowManager
242
243
 
243
244
  private extendPluginManager?: ExtendPluginManager;
244
245
 
246
+ private _roomLogger?: Logger;
247
+
248
+ get Logger(): Logger | undefined {
249
+ return this._roomLogger;
250
+ }
251
+
245
252
  constructor(context: InvisiblePluginContext) {
246
253
  super(context);
247
254
  WindowManager.displayer = context.displayer;
248
255
  (window as any).NETLESS_DEPS = __APP_DEPENDENCIES__;
256
+ this.emitter.on('mainViewScenePathChange', this.onMainViewScenePathChangeHandler)
249
257
  }
250
258
 
251
259
  public static onCreate(manager: WindowManager) {
@@ -277,6 +285,16 @@ export class WindowManager
277
285
  room.disableSerialization = false;
278
286
  }
279
287
  manager = await this.initManager(room);
288
+ if (manager) {
289
+ manager._roomLogger = (room as unknown as { logger: Logger }).logger;
290
+ if (WindowManager.registered.size > 0) {
291
+ manager._roomLogger.info(
292
+ `[WindowManager] registered apps: ${JSON.stringify(
293
+ Array.from(WindowManager.registered.keys())
294
+ )}`
295
+ );
296
+ }
297
+ }
280
298
  }
281
299
  if (WindowManager.isCreated) {
282
300
  throw new Error("[WindowManager]: Already created cannot be created again");
@@ -286,7 +304,13 @@ export class WindowManager
286
304
  if (this.debug) {
287
305
  setOptions({ verbose: true });
288
306
  }
289
- log("Already insert room", manager);
307
+ if (manager?._roomLogger) {
308
+ manager._roomLogger.info(
309
+ `[WindowManager] Already insert room version: ${manager.version}`
310
+ );
311
+ } else {
312
+ log("Already insert room", manager);
313
+ }
290
314
 
291
315
  if (isRoom(this.displayer)) {
292
316
  if (!manager) {
@@ -345,15 +369,46 @@ export class WindowManager
345
369
  replaceRoomFunction(room, manager);
346
370
  internalEmitter.emit("onCreated");
347
371
  WindowManager.isCreated = true;
372
+ if (
373
+ manager._roomLogger &&
374
+ manager.attributes.registered &&
375
+ Object.keys(manager.attributes.registered).length > 0
376
+ ) {
377
+ manager._roomLogger.info(
378
+ `[WindowManager] attributes registered apps: ${JSON.stringify(
379
+ Array.from(Object.keys(manager.attributes.registered))
380
+ )}`
381
+ );
382
+ }
348
383
  try {
349
384
  await initDb();
350
385
  } catch (error) {
386
+ manager._roomLogger?.warn(`[WindowManager] indexedDB open failed: ${error.message}`);
351
387
  console.warn("[WindowManager]: indexedDB open failed");
352
388
  console.log(error);
353
389
  }
390
+ manager.emitter.on('mainViewScenePathChange', manager.onMainViewScenePathChangeHandler)
354
391
  return manager;
355
392
  }
356
393
 
394
+ public onMainViewScenePathChangeHandler = (scenePath: string) => {
395
+ const mainViewElement = this.mainView.divElement;
396
+ if (mainViewElement) {
397
+ const backgroundImage = mainViewElement.querySelector('.background img');
398
+ if (backgroundImage) {
399
+ const backgroundImageRect = backgroundImage?.getBoundingClientRect();
400
+ const backgroundImageCSS = window.getComputedStyle(backgroundImage);
401
+ const backgroundImageVisible = backgroundImageRect?.width > 0 && backgroundImageRect?.height > 0 && backgroundImageCSS.display !== 'none';
402
+ const camera = this.mainView.camera;
403
+ console.log("[window-manager] backgroundImageVisible:" + backgroundImageVisible + " camera:" + JSON.stringify(camera));
404
+ return;
405
+ }
406
+ console.log("[window-manager] onMainViewScenePathChange scenePath:" + scenePath + ' backgroundImageVisible is not found');
407
+ return;
408
+ }
409
+ console.log("[window-manager] onMainViewScenePathChange scenePath:" + scenePath + ' mainViewElement is not found');
410
+ }
411
+
357
412
  private static initManager(room: Room): Promise<WindowManager | undefined> {
358
413
  return createInvisiblePlugin(room);
359
414
  }
@@ -975,7 +1030,6 @@ export class WindowManager
975
1030
  const mainViewCamera = { ...this.mainView.camera };
976
1031
  if (isEqual({ ...mainViewCamera, ...pureCamera }, mainViewCamera)) return;
977
1032
  this.mainView.moveCamera(camera);
978
- // this.appManager?.dispatchInternalEvent(Events.MoveCamera, camera);
979
1033
  setTimeout(() => {
980
1034
  this.appManager?.mainViewProxy.setCameraAndSize();
981
1035
  }, 500);
@@ -988,7 +1042,6 @@ export class WindowManager
988
1042
  }>
989
1043
  ): void {
990
1044
  this.mainView.moveCameraToContain(rectangle);
991
- // this.appManager?.dispatchInternalEvent(Events.MoveCameraToContain, rectangle);
992
1045
  setTimeout(() => {
993
1046
  this.appManager?.mainViewProxy.setCameraAndSize();
994
1047
  }, 500);
@@ -1023,6 +1076,7 @@ export class WindowManager
1023
1076
  WindowManager.playground.parentNode?.removeChild(WindowManager.playground);
1024
1077
  }
1025
1078
  WindowManager.params = undefined;
1079
+ this.emitter.off('mainViewScenePathChange', this.onMainViewScenePathChangeHandler);
1026
1080
  this._iframeBridge?.destroy();
1027
1081
  this._iframeBridge = undefined;
1028
1082
  log("Destroyed");
@@ -1052,12 +1106,14 @@ export class WindowManager
1052
1106
 
1053
1107
  public safeSetAttributes(attributes: any): void {
1054
1108
  if (this.canOperate) {
1109
+ this.Logger && this.Logger.info(`[WindowManager]: safeSetAttributes ${JSON.stringify(attributes)}`);
1055
1110
  this.setAttributes(attributes);
1056
1111
  }
1057
1112
  }
1058
1113
 
1059
1114
  public safeUpdateAttributes(keys: string[], value: any): void {
1060
1115
  if (this.canOperate) {
1116
+ this.Logger && this.Logger.info(`[WindowManager]: safeUpdateAttributes ${keys.join(", ")} ${value}`);
1061
1117
  this.updateAttributes(keys, value);
1062
1118
  }
1063
1119
  }
@@ -1068,6 +1124,7 @@ export class WindowManager
1068
1124
 
1069
1125
  public cleanCurrentScene(): void {
1070
1126
  log("clean current scene");
1127
+ this.Logger && this.Logger.info(`[WindowManager]: cleanCurrentScene ${this.focusedView?.focusScenePath}`);
1071
1128
  this.focusedView?.cleanCurrentScene();
1072
1129
  }
1073
1130
 
@@ -1080,6 +1137,7 @@ export class WindowManager
1080
1137
  }
1081
1138
 
1082
1139
  public delete(): void {
1140
+ this.Logger && this.Logger.info(`[WindowManager]: delete ${this.focusedView?.focusScenePath}`);
1083
1141
  this.focusedView?.delete();
1084
1142
  }
1085
1143