@netless/window-manager 0.4.37 → 0.4.40

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.
@@ -188,6 +188,7 @@ export class AppProxy implements PageRemoveService {
188
188
  this.setViewFocusScenePath();
189
189
  setTimeout(async () => {
190
190
  // 延迟执行 setup, 防止初始化的属性没有更新成功
191
+ console.log("setup app", app);
191
192
  const result = await app.setup(context);
192
193
  this.appResult = result;
193
194
  appRegister.notifyApp(this.kind, "created", { appId, result });
@@ -31,12 +31,24 @@ class AppRegister {
31
31
  this.appClassesCache.delete(params.kind);
32
32
  this.registered.set(params.kind, params);
33
33
 
34
- const srcOrAppOrFunction = params.src;
34
+ const paramSrc = params.src;
35
35
  let downloadApp: () => Promise<NetlessApp>;
36
36
 
37
- if (typeof srcOrAppOrFunction === "string") {
37
+ if (typeof paramSrc === "string") {
38
38
  downloadApp = async () => {
39
- let appClass = (await loadApp(srcOrAppOrFunction, params.kind, params.name)) as any;
39
+ const result = await loadApp(paramSrc, params.kind, params.name) as any;
40
+ if (result.__esModule) {
41
+ return result.default;
42
+ }
43
+ return result;
44
+ };
45
+ if (this.syncRegisterApp) {
46
+ this.syncRegisterApp({ kind: params.kind, src: paramSrc, name: params.name });
47
+ }
48
+ }
49
+ if (typeof paramSrc === "function") {
50
+ downloadApp = async () => {
51
+ let appClass = await paramSrc() as any;
40
52
  if (appClass) {
41
53
  if (appClass.__esModule) {
42
54
  appClass = appClass.default;
@@ -44,19 +56,14 @@ class AppRegister {
44
56
  return appClass;
45
57
  } else {
46
58
  throw new Error(
47
- `[WindowManager]: load remote script failed, ${srcOrAppOrFunction}`
59
+ `[WindowManager]: load remote script failed, ${paramSrc}`
48
60
  );
49
61
  }
50
62
  };
51
- if (this.syncRegisterApp) {
52
- this.syncRegisterApp({ kind: params.kind, src: srcOrAppOrFunction, name: params.name });
53
- }
54
- } else if (typeof srcOrAppOrFunction === "function") {
55
- downloadApp = srcOrAppOrFunction;
56
- } else {
57
- downloadApp = async () => srcOrAppOrFunction;
58
63
  }
59
-
64
+ if (typeof paramSrc === "object") {
65
+ downloadApp = async () => paramSrc;
66
+ }
60
67
  this.appClasses.set(params.kind, async () => {
61
68
  let app = this.appClassesCache.get(params.kind);
62
69
  if (!app) {
@@ -28,41 +28,45 @@ export const executeScript = (text: string, appName: string): NetlessApp => {
28
28
  return result;
29
29
  };
30
30
 
31
- export const loadApp = async (
32
- url: string,
33
- key: string,
34
- name?: string
35
- ): Promise<NetlessApp | undefined> => {
31
+ export const loadApp = async (url: string, key: string, name?: string): Promise<NetlessApp> => {
36
32
  const appName = name || Prefix + key;
37
33
  callbacks.emit("loadApp", { kind: key, status: "start" });
34
+
35
+ let text: string;
38
36
  try {
39
- const text = await getScript(url);
37
+ text = await getScript(url);
40
38
  if (!text || text.length === 0) {
41
39
  callbacks.emit("loadApp", { kind: key, status: "failed", reason: "script is empty." });
42
- return;
40
+ throw new Error("[WindowManager]: script is empty.");
43
41
  }
44
- try {
42
+ } catch (error) {
43
+ callbacks.emit("loadApp", { kind: key, status: "failed", reason: error.message });
44
+ throw error;
45
+ }
46
+ return getResult(text, appName, key);
47
+ };
48
+
49
+ const getResult = (text: string, appName: string, key: string): NetlessApp => {
50
+ try {
51
+ const result = executeScript(text, appName);
52
+ callbacks.emit("loadApp", { kind: key, status: "success" });
53
+ return result;
54
+ } catch (error: any) {
55
+ if (error.message.includes("Can only have one anonymous define call per script file")) {
56
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
57
+ // @ts-ignore
58
+ const define = window.define;
59
+ if ("function" == typeof define && define.amd) {
60
+ delete define.amd;
61
+ }
45
62
  const result = executeScript(text, appName);
46
63
  callbacks.emit("loadApp", { kind: key, status: "success" });
47
64
  return result;
48
- } catch (error: any) {
49
- if (error.message.includes("Can only have one anonymous define call per script file")) {
50
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
51
- // @ts-ignore
52
- const define = window.define;
53
- if ("function" == typeof define && define.amd) {
54
- delete define.amd;
55
- }
56
- const result = executeScript(text, appName);
57
- callbacks.emit("loadApp", { kind: key, status: "success" });
58
- return result;
59
- }
60
- callbacks.emit("loadApp", { kind: key, status: "failed", reason: error.message });
61
65
  }
62
- } catch (error: any) {
63
66
  callbacks.emit("loadApp", { kind: key, status: "failed", reason: error.message });
67
+ throw error;
64
68
  }
65
- };
69
+ }
66
70
 
67
71
  async function fetchWithTimeout(resource: string, options: RequestInit & { timeout: number }) {
68
72
  const { timeout = 10000 } = options;
@@ -39,7 +39,9 @@ export class MainViewProxy {
39
39
  });
40
40
  this.sideEffectManager.add(() => {
41
41
  return emitter.on("startReconnect", () => {
42
- this.mainView.release();
42
+ if (!this.didRelease) {
43
+ this.mainView.release();
44
+ }
43
45
  });
44
46
  });
45
47
  }
@@ -119,9 +121,6 @@ export class MainViewProxy {
119
121
  public onUpdateContainerSizeRatio = () => {
120
122
  const size = this.store.getMainViewSize();
121
123
  this.sizeChangeHandler(size);
122
- if (size.id === this.manager.uid) {
123
- this.setCameraAndSize();
124
- }
125
124
  }
126
125
 
127
126
  public get view(): View {
package/src/index.ts CHANGED
@@ -142,7 +142,7 @@ export type MountParams = {
142
142
 
143
143
  export const reconnectRefresher = new ReconnectRefresher({ emitter });
144
144
 
145
- export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> implements PageController {
145
+ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any> implements PageController {
146
146
  public static kind = "WindowManager";
147
147
  public static displayer: Displayer;
148
148
  public static wrapper?: HTMLElement;
@@ -218,7 +218,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
218
218
  throw new Error();
219
219
  }
220
220
  },
221
- { retries: 10 }
221
+ { retries: 10 } as any,
222
222
  );
223
223
  }
224
224
 
package/src/typings.ts CHANGED
@@ -67,7 +67,11 @@ export type RegisterEvents<SetupResult = any> = {
67
67
 
68
68
  export type RegisterParams<AppOptions = any, SetupResult = any, Attributes = any> = {
69
69
  kind: string;
70
- src: NetlessApp<Attributes, SetupResult> | string | (() => Promise<NetlessApp<Attributes, SetupResult>>);
70
+ src:
71
+ | NetlessApp<Attributes, SetupResult>
72
+ | string
73
+ | (() => Promise<NetlessApp<Attributes, SetupResult>>)
74
+ | (() => Promise<{ default: NetlessApp<Attributes, SetupResult> }>);
71
75
  appOptions?: AppOptions | (() => AppOptions);
72
76
  addHooks?: (emitter: Emittery<RegisterEvents<SetupResult>>) => void;
73
77
  /** dynamic load app package name */