@lynker-desktop/electron-window-manager 0.0.9-alpha.77 → 0.0.9-alpha.79
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/esm/main/index.d.ts +6 -1
- package/esm/main/index.d.ts.map +1 -1
- package/esm/main/index.js +51 -2
- package/esm/main/index.js.map +1 -1
- package/main/index.d.ts +6 -1
- package/main/index.d.ts.map +1 -1
- package/main/index.js +51 -2
- package/main/index.js.map +1 -1
- package/package.json +2 -2
package/esm/main/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
1
2
|
import { WebContents } from 'electron';
|
|
2
3
|
import type { ElectronWindowsManagerOptions, BWItem, BVItem, PreloadWebContentsConfig } from '../common';
|
|
3
4
|
export declare const getCustomSession: () => Electron.Session;
|
|
4
5
|
export declare const enable: (win: WebContents) => void;
|
|
5
|
-
export declare class WindowsManager {
|
|
6
|
+
export declare class WindowsManager extends EventEmitter {
|
|
6
7
|
loadingViewUrl: string | undefined;
|
|
7
8
|
errorViewUrl: string | undefined;
|
|
8
9
|
preload?: string;
|
|
@@ -89,6 +90,10 @@ export declare class WindowsManager {
|
|
|
89
90
|
* 清理已销毁的窗口(延迟执行,避免频繁检查)
|
|
90
91
|
*/
|
|
91
92
|
private _cleanupDestroyedWindows;
|
|
93
|
+
/**
|
|
94
|
+
* 触发 didAnyChange 事件,返回最新的 windows(只包含核心数据)
|
|
95
|
+
*/
|
|
96
|
+
private _emitDidAnyChange;
|
|
92
97
|
get(idOrName: string | number): BWItem | BVItem | undefined;
|
|
93
98
|
getAll(type: 'BW'): Map<number, BWItem>;
|
|
94
99
|
getAll(type: 'BV'): Map<number, BVItem>;
|
package/esm/main/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,WAAW,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AC;IACvC,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IACvC,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IA8BtC,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IA2C/B,QAAQ;IAwCR,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM;IAgCjD,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS;IAa9E,UAAU;IAKV,OAAO,CAAC,0BAA0B;IAqGlC,OAAO,CAAC,wBAAwB;IA+B1B,wBAAwB,CAAC,GAAG,EAAE,MAAM;IA0CpC,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAwB1E;;;OAGG;IACI,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAOjD;;;OAGG;IACH,OAAO,CAAC,yBAAyB,CAE1B;IAEP;;;OAGG;IACH,OAAO,CAAC,iBAAiB;CAsE1B;AAID,eAAO,IAAI,aAAa,SAAQ,CAAC;AAEjC,eAAO,MAAM,UAAU,aAAc,MAAM,mBAAmB,MAAM,iBAAiB,MAAM,6BAA6B,wBAAwB,2BAA2B,MAAM,EAAE,KAAG,cA4RrL,CAAA"}
|
package/esm/main/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import lodash from 'lodash';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
2
3
|
import { app, session, BrowserWindow, BrowserView, webContents } from 'electron';
|
|
3
4
|
import * as remote from '@electron/remote/main';
|
|
4
5
|
import eIpc from '@lynker-desktop/electron-ipc/main';
|
|
@@ -59,7 +60,7 @@ const initWebContentsVal = (win, preload) => {
|
|
|
59
60
|
// 忽略错误,webContents 可能已销毁
|
|
60
61
|
}
|
|
61
62
|
};
|
|
62
|
-
class WindowsManager {
|
|
63
|
+
class WindowsManager extends EventEmitter {
|
|
63
64
|
/**
|
|
64
65
|
* webview 域名白名单
|
|
65
66
|
* 传入格式示例:
|
|
@@ -77,6 +78,7 @@ class WindowsManager {
|
|
|
77
78
|
* - 'localhost'、'127.0.0.1'、'::1' 以及局域网 IP(如 192.168.x.x、10.x.x.x、172.16.x.x~172.31.x.x)都视为本地白名单。
|
|
78
79
|
*/
|
|
79
80
|
constructor(preload, loadingViewUrl, errorViewUrl, preloadWebContentsConfig, webviewDomainWhiteList) {
|
|
81
|
+
super();
|
|
80
82
|
// 按名称索引的 Map,用于加速查找
|
|
81
83
|
this.windowsByName = new Map();
|
|
82
84
|
// 预加载的窗口
|
|
@@ -101,7 +103,32 @@ class WindowsManager {
|
|
|
101
103
|
this._sortBrowserViews(window, view);
|
|
102
104
|
}, 50);
|
|
103
105
|
this.preload = preload;
|
|
104
|
-
|
|
106
|
+
// 使用 Proxy 监听 windows Map 的变化
|
|
107
|
+
const windowsMap = new Map();
|
|
108
|
+
this.windows = new Proxy(windowsMap, {
|
|
109
|
+
set: (target, prop, value) => {
|
|
110
|
+
const result = Reflect.set(target, prop, value);
|
|
111
|
+
this._emitDidAnyChange();
|
|
112
|
+
return result;
|
|
113
|
+
},
|
|
114
|
+
get: (target, prop) => {
|
|
115
|
+
const value = Reflect.get(target, prop);
|
|
116
|
+
// 如果是函数,需要绑定到原始 Map 实例
|
|
117
|
+
if (typeof value === 'function') {
|
|
118
|
+
// 拦截会修改 Map 的方法
|
|
119
|
+
if (prop === 'set' || prop === 'delete' || prop === 'clear') {
|
|
120
|
+
return (...args) => {
|
|
121
|
+
const result = value.apply(target, args);
|
|
122
|
+
this._emitDidAnyChange();
|
|
123
|
+
return result;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
// 其他方法(如 forEach, get, has 等)直接绑定到 target
|
|
127
|
+
return value.bind(target);
|
|
128
|
+
}
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
105
132
|
this.loadingViewUrl = `${loadingViewUrl ?? ''}`;
|
|
106
133
|
this.errorViewUrl = `${errorViewUrl ?? ''}`;
|
|
107
134
|
this.preloadWebContentsConfig = preloadWebContentsConfig;
|
|
@@ -1025,6 +1052,28 @@ class WindowsManager {
|
|
|
1025
1052
|
});
|
|
1026
1053
|
toDelete.forEach(key => this.windows.delete(key));
|
|
1027
1054
|
}
|
|
1055
|
+
/**
|
|
1056
|
+
* 触发 didAnyChange 事件,返回最新的 windows(只包含核心数据)
|
|
1057
|
+
*/
|
|
1058
|
+
_emitDidAnyChange() {
|
|
1059
|
+
const windowsData = {};
|
|
1060
|
+
this.windows.forEach((win, key) => {
|
|
1061
|
+
if (!this._isWindowDestroyed(win)) {
|
|
1062
|
+
const webContentsId = this._getWebContentsId(win);
|
|
1063
|
+
if (webContentsId !== undefined) {
|
|
1064
|
+
windowsData[webContentsId] = {
|
|
1065
|
+
webContentsId,
|
|
1066
|
+
name: win._name || 'anonymous',
|
|
1067
|
+
type: win._type || 'BW',
|
|
1068
|
+
extraData: win._extraData,
|
|
1069
|
+
initUrl: win._initUrl,
|
|
1070
|
+
zIndex: win._zIndex,
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
});
|
|
1075
|
+
this.emit('didAnyChange', windowsData);
|
|
1076
|
+
}
|
|
1028
1077
|
get(idOrName) {
|
|
1029
1078
|
log('log', 'get', idOrName);
|
|
1030
1079
|
let win;
|