@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/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,EAAiG,MAAM,UAAU,CAAA;AAItK,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,EAAE,MAAM,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAczG,eAAO,MAAM,gBAAgB,wBAQzB,CAAC;AAUL,eAAO,MAAM,MAAM,QAAS,WAAW,SAEtC,CAAA;AA4BD,qBAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/main/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,EAAmC,WAAW,EAAiG,MAAM,UAAU,CAAA;AAItK,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,EAAE,MAAM,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAczG,eAAO,MAAM,gBAAgB,wBAQzB,CAAC;AAUL,eAAO,MAAM,MAAM,QAAS,WAAW,SAEtC,CAAA;AA4BD,qBAAa,cAAe,SAAQ,YAAY;IAC9C,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,wBAAwB,CAAC,EAAE,w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AAI,aAAa,SAAQ,CAAC;AAEjC,eAAO,MAAM,UAAU,aAAc,MAAM,mBAAmB,MAAM,iBAAiB,MAAM,6BAA6B,wBAAwB,2BAA2B,MAAM,EAAE,KAAG,cA4RrL,CAAA"}
|
package/main/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const lodash = require('lodash');
|
|
2
|
+
const events = require('events');
|
|
2
3
|
const electron = require('electron');
|
|
3
4
|
const remote = require('@electron/remote/main');
|
|
4
5
|
const eIpc = require('@lynker-desktop/electron-ipc/main');
|
|
@@ -72,7 +73,7 @@ const initWebContentsVal = (win, preload) => {
|
|
|
72
73
|
// 忽略错误,webContents 可能已销毁
|
|
73
74
|
}
|
|
74
75
|
};
|
|
75
|
-
class WindowsManager {
|
|
76
|
+
class WindowsManager extends events.EventEmitter {
|
|
76
77
|
/**
|
|
77
78
|
* webview 域名白名单
|
|
78
79
|
* 传入格式示例:
|
|
@@ -90,6 +91,7 @@ class WindowsManager {
|
|
|
90
91
|
* - 'localhost'、'127.0.0.1'、'::1' 以及局域网 IP(如 192.168.x.x、10.x.x.x、172.16.x.x~172.31.x.x)都视为本地白名单。
|
|
91
92
|
*/
|
|
92
93
|
constructor(preload, loadingViewUrl, errorViewUrl, preloadWebContentsConfig, webviewDomainWhiteList) {
|
|
94
|
+
super();
|
|
93
95
|
// 按名称索引的 Map,用于加速查找
|
|
94
96
|
this.windowsByName = new Map();
|
|
95
97
|
// 预加载的窗口
|
|
@@ -114,7 +116,32 @@ class WindowsManager {
|
|
|
114
116
|
this._sortBrowserViews(window, view);
|
|
115
117
|
}, 50);
|
|
116
118
|
this.preload = preload;
|
|
117
|
-
|
|
119
|
+
// 使用 Proxy 监听 windows Map 的变化
|
|
120
|
+
const windowsMap = new Map();
|
|
121
|
+
this.windows = new Proxy(windowsMap, {
|
|
122
|
+
set: (target, prop, value) => {
|
|
123
|
+
const result = Reflect.set(target, prop, value);
|
|
124
|
+
this._emitDidAnyChange();
|
|
125
|
+
return result;
|
|
126
|
+
},
|
|
127
|
+
get: (target, prop) => {
|
|
128
|
+
const value = Reflect.get(target, prop);
|
|
129
|
+
// 如果是函数,需要绑定到原始 Map 实例
|
|
130
|
+
if (typeof value === 'function') {
|
|
131
|
+
// 拦截会修改 Map 的方法
|
|
132
|
+
if (prop === 'set' || prop === 'delete' || prop === 'clear') {
|
|
133
|
+
return (...args) => {
|
|
134
|
+
const result = value.apply(target, args);
|
|
135
|
+
this._emitDidAnyChange();
|
|
136
|
+
return result;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
// 其他方法(如 forEach, get, has 等)直接绑定到 target
|
|
140
|
+
return value.bind(target);
|
|
141
|
+
}
|
|
142
|
+
return value;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
118
145
|
this.loadingViewUrl = `${loadingViewUrl ?? ''}`;
|
|
119
146
|
this.errorViewUrl = `${errorViewUrl ?? ''}`;
|
|
120
147
|
this.preloadWebContentsConfig = preloadWebContentsConfig;
|
|
@@ -1038,6 +1065,28 @@ class WindowsManager {
|
|
|
1038
1065
|
});
|
|
1039
1066
|
toDelete.forEach(key => this.windows.delete(key));
|
|
1040
1067
|
}
|
|
1068
|
+
/**
|
|
1069
|
+
* 触发 didAnyChange 事件,返回最新的 windows(只包含核心数据)
|
|
1070
|
+
*/
|
|
1071
|
+
_emitDidAnyChange() {
|
|
1072
|
+
const windowsData = {};
|
|
1073
|
+
this.windows.forEach((win, key) => {
|
|
1074
|
+
if (!this._isWindowDestroyed(win)) {
|
|
1075
|
+
const webContentsId = this._getWebContentsId(win);
|
|
1076
|
+
if (webContentsId !== undefined) {
|
|
1077
|
+
windowsData[webContentsId] = {
|
|
1078
|
+
webContentsId,
|
|
1079
|
+
name: win._name || 'anonymous',
|
|
1080
|
+
type: win._type || 'BW',
|
|
1081
|
+
extraData: win._extraData,
|
|
1082
|
+
initUrl: win._initUrl,
|
|
1083
|
+
zIndex: win._zIndex,
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
this.emit('didAnyChange', windowsData);
|
|
1089
|
+
}
|
|
1041
1090
|
get(idOrName) {
|
|
1042
1091
|
log('log', 'get', idOrName);
|
|
1043
1092
|
let win;
|