@lynker-desktop/electron-window-manager 0.0.9-alpha.3 → 0.0.9-alpha.5
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 +29 -3
- package/esm/main/index.d.ts.map +1 -1
- package/esm/main/index.js +123 -27
- package/esm/main/index.js.map +1 -1
- package/main/index.d.ts +29 -3
- package/main/index.d.ts.map +1 -1
- package/main/index.js +123 -27
- package/main/index.js.map +1 -1
- package/package.json +2 -2
package/esm/main/index.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export declare class WindowsManager {
|
|
|
14
14
|
preloadedBV: BVItem | null;
|
|
15
15
|
preloading: boolean;
|
|
16
16
|
webviewDomainWhiteList: string[];
|
|
17
|
+
private createQueue;
|
|
18
|
+
private isCreating;
|
|
17
19
|
/**
|
|
18
20
|
* webview 域名白名单
|
|
19
21
|
* 传入格式示例:
|
|
@@ -31,17 +33,41 @@ export declare class WindowsManager {
|
|
|
31
33
|
* - 'localhost'、'127.0.0.1'、'::1' 以及局域网 IP(如 192.168.x.x、10.x.x.x、172.16.x.x~172.31.x.x)都视为本地白名单。
|
|
32
34
|
*/
|
|
33
35
|
constructor(preload?: string, loadingViewUrl?: string, errorViewUrl?: string, preloadWebContentsUrl?: string, webviewDomainWhiteList?: string[]);
|
|
36
|
+
/**
|
|
37
|
+
* 设置预加载的webContents的url
|
|
38
|
+
* @param preloadWebContentsUrl 预加载的webContents的url
|
|
39
|
+
*/
|
|
34
40
|
setPreloadWebContentsUrl(preloadWebContentsUrl: string): void;
|
|
41
|
+
/**
|
|
42
|
+
* 预加载实例
|
|
43
|
+
*/
|
|
35
44
|
private _preloadInstances;
|
|
45
|
+
/**
|
|
46
|
+
* 创建预加载的窗口
|
|
47
|
+
* @param options 窗口选项
|
|
48
|
+
* @returns 预加载的窗口
|
|
49
|
+
*/
|
|
36
50
|
private _createPreloadBW;
|
|
51
|
+
/**
|
|
52
|
+
* 创建预加载的浏览器视图
|
|
53
|
+
* @returns 预加载的浏览器视图
|
|
54
|
+
*/
|
|
37
55
|
private _createPreloadBV;
|
|
38
56
|
create(options: Omit<ElectronWindowsManagerOptions, 'type'> & {
|
|
39
57
|
type?: 'BW';
|
|
40
|
-
}): BWItem
|
|
58
|
+
}): Promise<BWItem>;
|
|
41
59
|
create(options: ElectronWindowsManagerOptions & {
|
|
42
60
|
type: 'BV';
|
|
43
|
-
}): BVItem
|
|
44
|
-
create(options: ElectronWindowsManagerOptions):
|
|
61
|
+
}): Promise<BVItem>;
|
|
62
|
+
create(options: ElectronWindowsManagerOptions): Promise<BVItem | BWItem>;
|
|
63
|
+
/**
|
|
64
|
+
* 处理创建队列
|
|
65
|
+
*/
|
|
66
|
+
private processCreateQueue;
|
|
67
|
+
/**
|
|
68
|
+
* 实际的窗口创建逻辑
|
|
69
|
+
*/
|
|
70
|
+
private _createWindow;
|
|
45
71
|
_setLoadingView(window: BWItem, createOptions: ElectronWindowsManagerOptions): void;
|
|
46
72
|
get(idOrName: string | number): BWItem | BVItem | undefined;
|
|
47
73
|
getAll(type: 'BW'): Map<number, BWItem>;
|
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,EAAkE,MAAM,UAAU,CAAA;AAIvI,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAE/E,eAAO,MAAM,gBAAgB,wBAQzB,CAAC;AAUL,eAAO,MAAM,MAAM,QAAS,WAAW,SAEtC,CAAA;AAoBD,qBAAa,cAAc;IACzB,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,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AAQ,CAAC;AAEjC,eAAO,MAAM,UAAU,aAAc,MAAM,mBAAmB,MAAM,iBAAiB,MAAM,0BAA0B,MAAM,2BAA2B,MAAM,EAAE,KAAG,cA4QhK,CAAA"}
|
package/esm/main/index.js
CHANGED
|
@@ -57,12 +57,19 @@ class WindowsManager {
|
|
|
57
57
|
* - 'localhost'、'127.0.0.1'、'::1' 以及局域网 IP(如 192.168.x.x、10.x.x.x、172.16.x.x~172.31.x.x)都视为本地白名单。
|
|
58
58
|
*/
|
|
59
59
|
constructor(preload, loadingViewUrl, errorViewUrl, preloadWebContentsUrl, webviewDomainWhiteList) {
|
|
60
|
+
// 预加载的窗口
|
|
60
61
|
this.preloadedBW = null;
|
|
62
|
+
// 预加载的窗口(无边框,有按钮)
|
|
61
63
|
this.preloadedBW_FramelessWithButtons = null;
|
|
64
|
+
// 预加载的窗口(无边框,无按钮)
|
|
62
65
|
this.preloadedBW_FramelessNoButtons = null;
|
|
66
|
+
// 预加载的浏览器视图
|
|
63
67
|
this.preloadedBV = null;
|
|
64
68
|
this.preloading = false;
|
|
65
69
|
this.webviewDomainWhiteList = [];
|
|
70
|
+
// 创建队列相关属性
|
|
71
|
+
this.createQueue = [];
|
|
72
|
+
this.isCreating = false;
|
|
66
73
|
this.preload = preload;
|
|
67
74
|
this.windows = new Map();
|
|
68
75
|
this.loadingViewUrl = `${loadingViewUrl ?? ''}`;
|
|
@@ -72,10 +79,16 @@ class WindowsManager {
|
|
|
72
79
|
log('log', 'preloadWebContentsUrl: ', this.preloadWebContentsUrl);
|
|
73
80
|
if (this.preloadWebContentsUrl) {
|
|
74
81
|
app.on('ready', () => {
|
|
75
|
-
this.
|
|
82
|
+
if (this.preloadWebContentsUrl) {
|
|
83
|
+
this.setPreloadWebContentsUrl(this.preloadWebContentsUrl);
|
|
84
|
+
}
|
|
76
85
|
});
|
|
77
86
|
}
|
|
78
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* 设置预加载的webContents的url
|
|
90
|
+
* @param preloadWebContentsUrl 预加载的webContents的url
|
|
91
|
+
*/
|
|
79
92
|
setPreloadWebContentsUrl(preloadWebContentsUrl) {
|
|
80
93
|
try {
|
|
81
94
|
this.preloadWebContentsUrl = preloadWebContentsUrl;
|
|
@@ -93,23 +106,30 @@ class WindowsManager {
|
|
|
93
106
|
log('error', 'setPreloadWebContentsUrl error:', error);
|
|
94
107
|
}
|
|
95
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* 预加载实例
|
|
111
|
+
*/
|
|
96
112
|
async _preloadInstances() {
|
|
97
113
|
if (this.preloading)
|
|
98
114
|
return;
|
|
99
115
|
this.preloading = true;
|
|
100
116
|
try {
|
|
101
117
|
if (this.preloadWebContentsUrl) {
|
|
118
|
+
// 预加载的窗口
|
|
102
119
|
this.preloadedBW = this.preloadedBW || await this._createPreloadBW({});
|
|
120
|
+
// 预加载的窗口(无边框,有按钮)
|
|
103
121
|
this.preloadedBW_FramelessWithButtons = this.preloadedBW_FramelessWithButtons || await this._createPreloadBW({
|
|
104
122
|
frame: false,
|
|
105
123
|
transparent: true,
|
|
106
124
|
titleBarStyle: 'hidden',
|
|
107
125
|
});
|
|
126
|
+
// 预加载的窗口(无边框,无按钮)
|
|
108
127
|
this.preloadedBW_FramelessNoButtons = this.preloadedBW_FramelessNoButtons || await this._createPreloadBW({
|
|
109
128
|
frame: false,
|
|
110
129
|
transparent: true,
|
|
111
130
|
titleBarStyle: 'customButtonsOnHover',
|
|
112
131
|
});
|
|
132
|
+
// 预加载的BV
|
|
113
133
|
this.preloadedBV = this.preloadedBV || await this._createPreloadBV();
|
|
114
134
|
}
|
|
115
135
|
}
|
|
@@ -118,15 +138,21 @@ class WindowsManager {
|
|
|
118
138
|
}
|
|
119
139
|
this.preloading = false;
|
|
120
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* 创建预加载的窗口
|
|
143
|
+
* @param options 窗口选项
|
|
144
|
+
* @returns 预加载的窗口
|
|
145
|
+
*/
|
|
121
146
|
_createPreloadBW(options = {}) {
|
|
122
147
|
return new Promise((resolve) => {
|
|
123
148
|
const preload = this.preload;
|
|
124
149
|
const url = this.preloadWebContentsUrl;
|
|
125
150
|
if (this.preloadWebContentsUrl) {
|
|
126
151
|
const instance = new BrowserWindow({
|
|
127
|
-
show: false,
|
|
128
152
|
...options,
|
|
153
|
+
show: false,
|
|
129
154
|
webPreferences: {
|
|
155
|
+
...(options.webPreferences || {}),
|
|
130
156
|
webviewTag: true,
|
|
131
157
|
plugins: true,
|
|
132
158
|
nodeIntegration: true,
|
|
@@ -134,7 +160,6 @@ class WindowsManager {
|
|
|
134
160
|
backgroundThrottling: false,
|
|
135
161
|
webSecurity: false,
|
|
136
162
|
preload: preload,
|
|
137
|
-
...(options.webPreferences || {}),
|
|
138
163
|
}
|
|
139
164
|
});
|
|
140
165
|
try {
|
|
@@ -158,10 +183,14 @@ class WindowsManager {
|
|
|
158
183
|
instance.webContents.once('did-fail-load', () => {
|
|
159
184
|
resolve(instance);
|
|
160
185
|
});
|
|
161
|
-
instance.loadURL(url
|
|
186
|
+
instance.loadURL(url ? `${url}` : 'about:blank');
|
|
162
187
|
}
|
|
163
188
|
});
|
|
164
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* 创建预加载的浏览器视图
|
|
192
|
+
* @returns 预加载的浏览器视图
|
|
193
|
+
*/
|
|
165
194
|
_createPreloadBV() {
|
|
166
195
|
return new Promise((resolve) => {
|
|
167
196
|
const preload = this.preload;
|
|
@@ -204,6 +233,40 @@ class WindowsManager {
|
|
|
204
233
|
});
|
|
205
234
|
}
|
|
206
235
|
create(options) {
|
|
236
|
+
return new Promise((resolve, reject) => {
|
|
237
|
+
// 将创建请求添加到队列
|
|
238
|
+
this.createQueue.push({ options, resolve, reject });
|
|
239
|
+
// 如果当前没有在创建,则开始处理队列
|
|
240
|
+
if (!this.isCreating) {
|
|
241
|
+
this.processCreateQueue();
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* 处理创建队列
|
|
247
|
+
*/
|
|
248
|
+
async processCreateQueue() {
|
|
249
|
+
if (this.isCreating || this.createQueue.length === 0) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
this.isCreating = true;
|
|
253
|
+
while (this.createQueue.length > 0) {
|
|
254
|
+
const { options, resolve, reject } = this.createQueue.shift();
|
|
255
|
+
try {
|
|
256
|
+
const window = await this._createWindow(options);
|
|
257
|
+
resolve(window);
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
log('error', 'create window failed:', error);
|
|
261
|
+
reject(error);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
this.isCreating = false;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* 实际的窗口创建逻辑
|
|
268
|
+
*/
|
|
269
|
+
async _createWindow(options) {
|
|
207
270
|
let window;
|
|
208
271
|
const { usePreload = true, type = 'BW', name = 'anonymous', url, loadingView = { url: undefined }, errorView = { url: undefined }, browserWindow: browserWindowOptions, openDevTools = false, preventOriginClose = false, } = options;
|
|
209
272
|
options.type = type;
|
|
@@ -211,37 +274,46 @@ class WindowsManager {
|
|
|
211
274
|
let preloadWin = null;
|
|
212
275
|
if (type === 'BW' && usePreload && this.preloadWebContentsUrl) {
|
|
213
276
|
const bwOptions = browserWindowOptions || {};
|
|
277
|
+
console.log(11111, bwOptions);
|
|
214
278
|
if (bwOptions.frame === false && bwOptions.titleBarStyle === 'hidden') {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
279
|
+
if (this.preloadedBW_FramelessWithButtons) {
|
|
280
|
+
preloadWin = this.preloadedBW_FramelessWithButtons;
|
|
281
|
+
this.preloadedBW_FramelessWithButtons = null;
|
|
282
|
+
setTimeout(async () => this.preloadedBW_FramelessWithButtons = await this._createPreloadBW({ frame: false, transparent: true, titleBarStyle: 'hidden' }), 0);
|
|
283
|
+
}
|
|
218
284
|
}
|
|
219
285
|
else if (bwOptions.frame === false && bwOptions.titleBarStyle === 'customButtonsOnHover') {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
286
|
+
if (this.preloadedBW_FramelessNoButtons) {
|
|
287
|
+
preloadWin = this.preloadedBW_FramelessNoButtons;
|
|
288
|
+
this.preloadedBW_FramelessNoButtons = null;
|
|
289
|
+
setTimeout(async () => this.preloadedBW_FramelessNoButtons = await this._createPreloadBW({ frame: false, transparent: true, titleBarStyle: 'customButtonsOnHover' }), 0);
|
|
290
|
+
}
|
|
223
291
|
}
|
|
224
292
|
else {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
293
|
+
if (this.preloadedBW) {
|
|
294
|
+
preloadWin = this.preloadedBW;
|
|
295
|
+
this.preloadedBW = null;
|
|
296
|
+
setTimeout(async () => this.preloadedBW = await this._createPreloadBW({}), 0);
|
|
297
|
+
}
|
|
228
298
|
}
|
|
229
299
|
}
|
|
230
300
|
if (type === 'BV' && usePreload && this.preloadWebContentsUrl) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
301
|
+
if (this.preloadedBV) {
|
|
302
|
+
preloadWin = this.preloadedBV;
|
|
303
|
+
this.preloadedBV = null;
|
|
304
|
+
setTimeout(async () => this.preloadedBV = await this._createPreloadBV(), 0);
|
|
305
|
+
}
|
|
234
306
|
}
|
|
235
307
|
if (preloadWin) {
|
|
236
308
|
const win = preloadWin;
|
|
237
|
-
log('log', `${name}
|
|
309
|
+
log('log', `${name} 使用预加载窗口(${type})`, win._id);
|
|
238
310
|
win._type = 'BW';
|
|
239
311
|
win._name = options.name || 'anonymous';
|
|
240
312
|
win._extraData = `${options?.extraData || ''}`;
|
|
241
313
|
win._initUrl = `${options?.url || ''}`;
|
|
242
314
|
// @ts-ignore
|
|
243
|
-
win?.removeAllListeners && win?.removeAllListeners?.();
|
|
244
|
-
win.webContents.removeAllListeners && win.webContents.removeAllListeners();
|
|
315
|
+
// win?.removeAllListeners && win?.removeAllListeners?.();
|
|
316
|
+
// win.webContents.removeAllListeners && win.webContents.removeAllListeners();
|
|
245
317
|
if (type === 'BW') {
|
|
246
318
|
// @ts-ignore
|
|
247
319
|
this._applyBrowserWindowOptions(win, options);
|
|
@@ -351,7 +423,7 @@ class WindowsManager {
|
|
|
351
423
|
if (errorView?.url) {
|
|
352
424
|
if (type === 'BW') {
|
|
353
425
|
const showErrorView = lodash.debounce(() => {
|
|
354
|
-
const _url = window
|
|
426
|
+
const _url = window._initUrl;
|
|
355
427
|
/**
|
|
356
428
|
* 判断是否是错误视图
|
|
357
429
|
*/
|
|
@@ -365,16 +437,37 @@ class WindowsManager {
|
|
|
365
437
|
sessionStorage.setItem(key, "${_url}");
|
|
366
438
|
`);
|
|
367
439
|
}
|
|
368
|
-
},
|
|
440
|
+
}, 1000);
|
|
369
441
|
// @ts-ignore
|
|
370
442
|
window.webContents.on('did-fail-load', (event, errorCode, errorDescription, validatedURL, isMainFrame) => {
|
|
371
443
|
if (isMainFrame) {
|
|
372
444
|
showErrorView();
|
|
373
445
|
}
|
|
374
446
|
});
|
|
447
|
+
// 当开始加载时取消错误视图
|
|
375
448
|
window.webContents.on('did-start-loading', () => {
|
|
376
449
|
showErrorView.cancel();
|
|
377
450
|
});
|
|
451
|
+
// 当导航开始时取消错误视图
|
|
452
|
+
window.webContents.on('did-start-navigation', () => {
|
|
453
|
+
showErrorView.cancel();
|
|
454
|
+
});
|
|
455
|
+
// 当页面重新加载时取消错误视图
|
|
456
|
+
window.webContents.on('did-navigate', () => {
|
|
457
|
+
showErrorView.cancel();
|
|
458
|
+
});
|
|
459
|
+
// 当页面完成加载时取消错误视图
|
|
460
|
+
window.webContents.on('did-finish-load', () => {
|
|
461
|
+
showErrorView.cancel();
|
|
462
|
+
});
|
|
463
|
+
// 当窗口关闭时取消错误视图
|
|
464
|
+
window.webContents.on('close', () => {
|
|
465
|
+
showErrorView.cancel();
|
|
466
|
+
});
|
|
467
|
+
// 当窗口销毁时取消错误视图
|
|
468
|
+
window.webContents.on('destroyed', () => {
|
|
469
|
+
showErrorView.cancel();
|
|
470
|
+
});
|
|
378
471
|
}
|
|
379
472
|
}
|
|
380
473
|
window.webContents.on('did-attach-webview', (_event, webContents) => {
|
|
@@ -456,10 +549,6 @@ class WindowsManager {
|
|
|
456
549
|
parentWin?.addBrowserView(window);
|
|
457
550
|
log('log', 'create - addBrowserView');
|
|
458
551
|
}
|
|
459
|
-
// @ts-ignore
|
|
460
|
-
window.loadURL ? window.loadURL(options.url) : window.webContents.loadURL(options.url);
|
|
461
|
-
// @ts-ignore
|
|
462
|
-
window.focus ? window.focus() : window.webContents.focus();
|
|
463
552
|
this.windows.set(window.id || window._id || window.webContents.id, window);
|
|
464
553
|
log('log', 'create', this.windows.keys());
|
|
465
554
|
// 初始化值
|
|
@@ -552,6 +641,13 @@ class WindowsManager {
|
|
|
552
641
|
log('error', 'focus', error);
|
|
553
642
|
}
|
|
554
643
|
}
|
|
644
|
+
console.log('message xxxx', options.url);
|
|
645
|
+
if (options.url) {
|
|
646
|
+
// @ts-ignore
|
|
647
|
+
window.loadURL ? window.loadURL(options.url) : window.webContents.loadURL(options.url);
|
|
648
|
+
// @ts-ignore
|
|
649
|
+
window.focus ? window.focus() : window.webContents.focus();
|
|
650
|
+
}
|
|
555
651
|
}
|
|
556
652
|
catch (error) {
|
|
557
653
|
log('error', 'create', error);
|
|
@@ -835,7 +931,7 @@ class WindowsManager {
|
|
|
835
931
|
// 生成一个bv 做为预加载资源窗口,加载完成后销毁
|
|
836
932
|
async createPreloadWebContents(url) {
|
|
837
933
|
return new Promise(async (resolve, reject) => {
|
|
838
|
-
let bv = this.create({
|
|
934
|
+
let bv = await this.create({
|
|
839
935
|
type: 'BV',
|
|
840
936
|
url,
|
|
841
937
|
name: `preload-web-contents-${md5(url)}`,
|
|
@@ -890,7 +986,7 @@ const initialize = (preload, loadingViewUrl, errorViewUrl, preloadWebContentsUrl
|
|
|
890
986
|
winInitUrl: `${findWin?._initUrl || ''}`,
|
|
891
987
|
};
|
|
892
988
|
}
|
|
893
|
-
const res = wm.create(opt.data);
|
|
989
|
+
const res = await wm.create(opt.data);
|
|
894
990
|
return {
|
|
895
991
|
winId: Number(`${res.id || res._id || -1}`),
|
|
896
992
|
winName: `${res?._name || ''}`,
|