@netless/window-manager 0.4.36 → 0.4.39

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/dist/typings.d.ts CHANGED
@@ -62,7 +62,9 @@ export declare type RegisterEvents<SetupResult = any> = {
62
62
  };
63
63
  export declare type RegisterParams<AppOptions = any, SetupResult = any, Attributes = any> = {
64
64
  kind: string;
65
- src: NetlessApp<Attributes, SetupResult> | string | (() => Promise<NetlessApp<Attributes, SetupResult>>);
65
+ src: NetlessApp<Attributes, SetupResult> | string | (() => Promise<NetlessApp<Attributes, SetupResult>>) | (() => Promise<{
66
+ default: NetlessApp<Attributes, SetupResult>;
67
+ }>);
66
68
  appOptions?: AppOptions | (() => AppOptions);
67
69
  addHooks?: (emitter: Emittery<RegisterEvents<SetupResult>>) => void;
68
70
  /** dynamic load app package name */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/window-manager",
3
- "version": "0.4.36",
3
+ "version": "0.4.39",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.es.js",
package/src/BoxManager.ts CHANGED
@@ -108,6 +108,18 @@ export class BoxManager {
108
108
  callbacks.emit("prefersColorSchemeChange", colorScheme);
109
109
  });
110
110
 
111
+ // ppt 在最小化后刷新恢复正常大小,拿不到正确的宽高,需要手动触发一下窗口的 resize
112
+ this.teleBoxManager._minimized$.reaction(minimized => {
113
+ if (!minimized) {
114
+ setTimeout(() => {
115
+ const offset = 0.001 * (Math.random() > 0.5 ? 1 : -1);
116
+ this.teleBoxManager.boxes.forEach(box => {
117
+ box.resize(box.intrinsicWidth + offset, box.intrinsicHeight + offset, true);
118
+ });
119
+ }, 400);
120
+ }
121
+ });
122
+
111
123
  // events.on 的值则会根据 skipUpdate 来决定是否触发回调
112
124
  this.teleBoxManager.events.on("minimized", minimized => {
113
125
  this.context.safeSetAttributes({ minimized });
@@ -120,14 +132,6 @@ export class BoxManager {
120
132
  this.context.setAppFocus(topBox.id);
121
133
  this.focusBox({ appId: topBox.id }, false);
122
134
  }
123
- // ppt 在最小化后刷新恢复正常大小,拿不到正确的宽高,需要手动触发一下窗口的 resize
124
- setTimeout(() => {
125
- this.teleBoxManager.boxes.forEach(box => {
126
- const width = box.width;
127
- const height = box.height;
128
- box._size$.setValue({ width: width + 0.001, height: height + 0.001 }, true);
129
- });
130
- }, 100);
131
135
  }
132
136
  });
133
137
  this.teleBoxManager.events.on("maximized", maximized => {
@@ -31,12 +31,19 @@ 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
+ let srcOrAppOrFunction: () => Promise<NetlessApp>;
35
36
  let downloadApp: () => Promise<NetlessApp>;
36
37
 
37
- if (typeof srcOrAppOrFunction === "string") {
38
+ if (typeof paramSrc === "string") {
39
+ srcOrAppOrFunction = () => loadApp(paramSrc, params.kind, params.name);
40
+ if (this.syncRegisterApp) {
41
+ this.syncRegisterApp({ kind: params.kind, src: paramSrc, name: params.name });
42
+ }
43
+ }
44
+ if (typeof paramSrc === "function") {
38
45
  downloadApp = async () => {
39
- let appClass = (await loadApp(srcOrAppOrFunction, params.kind, params.name)) as any;
46
+ let appClass = await srcOrAppOrFunction() as any;
40
47
  if (appClass) {
41
48
  if (appClass.__esModule) {
42
49
  appClass = appClass.default;
@@ -48,15 +55,10 @@ class AppRegister {
48
55
  );
49
56
  }
50
57
  };
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
58
  }
59
-
59
+ if (typeof paramSrc === "object") {
60
+ downloadApp = async () => paramSrc;
61
+ }
60
62
  this.appClasses.set(params.kind, async () => {
61
63
  let app = this.appClassesCache.get(params.kind);
62
64
  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/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 */