@lynker-desktop/electron-window-manager 0.0.9-alpha.4 → 0.0.9-alpha.6
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 +13 -3
- package/esm/main/index.d.ts.map +1 -1
- package/esm/main/index.js +83 -37
- package/esm/main/index.js.map +1 -1
- package/main/index.d.ts +13 -3
- package/main/index.d.ts.map +1 -1
- package/main/index.js +83 -37
- 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
|
* 传入格式示例:
|
|
@@ -53,11 +55,19 @@ export declare class WindowsManager {
|
|
|
53
55
|
private _createPreloadBV;
|
|
54
56
|
create(options: Omit<ElectronWindowsManagerOptions, 'type'> & {
|
|
55
57
|
type?: 'BW';
|
|
56
|
-
}): BWItem
|
|
58
|
+
}): Promise<BWItem>;
|
|
57
59
|
create(options: ElectronWindowsManagerOptions & {
|
|
58
60
|
type: 'BV';
|
|
59
|
-
}): BVItem
|
|
60
|
-
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;
|
|
61
71
|
_setLoadingView(window: BWItem, createOptions: ElectronWindowsManagerOptions): void;
|
|
62
72
|
get(idOrName: string | number): BWItem | BVItem | undefined;
|
|
63
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,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IAEtC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAQ;IAElC,gCAAgC,EAAE,MAAM,GAAG,IAAI,CAAQ;IAEvD,8BAA8B,EAAE,MAAM,GAAG,IAAI,CAAQ;IAErD,WAAW,EAAE,MAAM,GAAG,IAAI,CAAQ;IAClC,UAAU,EAAE,OAAO,CAAS;IAC5B,sBAAsB,EAAE,MAAM,EAAE,CAAM;
|
|
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,SA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W,kBAAkB;IAsBhC;;OAEG;YACW,aAAa;IAgZ3B,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,6BAA6B;IAmF5E,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS;IA6B3D,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IACvC,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IACvC,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAyBtC,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAqC/B,QAAQ;IA0BR,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM;IAqCjD,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS;IAgB9E,UAAU;IAKV,OAAO,CAAC,0BAA0B;IAoBlC,OAAO,CAAC,wBAAwB;IAiB1B,wBAAwB,CAAC,GAAG,EAAE,MAAM;CAqB3C;AAID,eAAO,IAAI,aAAa,SAAQ,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
|
@@ -67,6 +67,9 @@ class WindowsManager {
|
|
|
67
67
|
this.preloadedBV = null;
|
|
68
68
|
this.preloading = false;
|
|
69
69
|
this.webviewDomainWhiteList = [];
|
|
70
|
+
// 创建队列相关属性
|
|
71
|
+
this.createQueue = [];
|
|
72
|
+
this.isCreating = false;
|
|
70
73
|
this.preload = preload;
|
|
71
74
|
this.windows = new Map();
|
|
72
75
|
this.loadingViewUrl = `${loadingViewUrl ?? ''}`;
|
|
@@ -146,9 +149,10 @@ class WindowsManager {
|
|
|
146
149
|
const url = this.preloadWebContentsUrl;
|
|
147
150
|
if (this.preloadWebContentsUrl) {
|
|
148
151
|
const instance = new BrowserWindow({
|
|
149
|
-
show: false,
|
|
150
152
|
...options,
|
|
153
|
+
show: false,
|
|
151
154
|
webPreferences: {
|
|
155
|
+
...(options.webPreferences || {}),
|
|
152
156
|
webviewTag: true,
|
|
153
157
|
plugins: true,
|
|
154
158
|
nodeIntegration: true,
|
|
@@ -156,7 +160,6 @@ class WindowsManager {
|
|
|
156
160
|
backgroundThrottling: false,
|
|
157
161
|
webSecurity: false,
|
|
158
162
|
preload: preload,
|
|
159
|
-
...(options.webPreferences || {}),
|
|
160
163
|
}
|
|
161
164
|
});
|
|
162
165
|
try {
|
|
@@ -174,13 +177,14 @@ class WindowsManager {
|
|
|
174
177
|
}
|
|
175
178
|
// @ts-ignore
|
|
176
179
|
log('log', '创建预BW: ', instance._id, this.preloadWebContentsUrl);
|
|
177
|
-
instance.webContents.once('did-finish-load', () => {
|
|
178
|
-
|
|
179
|
-
});
|
|
180
|
-
instance.webContents.once('did-fail-load', () => {
|
|
181
|
-
|
|
182
|
-
});
|
|
183
|
-
instance.loadURL(url
|
|
180
|
+
// instance.webContents.once('did-finish-load', () => {
|
|
181
|
+
// resolve(instance as BWItem);
|
|
182
|
+
// });
|
|
183
|
+
// instance.webContents.once('did-fail-load', () => {
|
|
184
|
+
// resolve(instance as BWItem);
|
|
185
|
+
// });
|
|
186
|
+
instance.loadURL(url ? `${url}` : 'about:blank');
|
|
187
|
+
resolve(instance);
|
|
184
188
|
}
|
|
185
189
|
});
|
|
186
190
|
}
|
|
@@ -219,17 +223,52 @@ class WindowsManager {
|
|
|
219
223
|
}
|
|
220
224
|
// @ts-ignore
|
|
221
225
|
log('log', '创建预BV: ', instance._id, this.preloadWebContentsUrl);
|
|
222
|
-
instance.webContents.once('did-finish-load', () => {
|
|
223
|
-
|
|
224
|
-
});
|
|
225
|
-
instance.webContents.once('did-fail-load', () => {
|
|
226
|
-
|
|
227
|
-
});
|
|
226
|
+
// instance.webContents.once('did-finish-load', () => {
|
|
227
|
+
// resolve(instance as BVItem);
|
|
228
|
+
// });
|
|
229
|
+
// instance.webContents.once('did-fail-load', () => {
|
|
230
|
+
// resolve(instance as BVItem);
|
|
231
|
+
// });
|
|
228
232
|
instance.webContents.loadURL(url || 'about:blank');
|
|
233
|
+
resolve(instance);
|
|
229
234
|
}
|
|
230
235
|
});
|
|
231
236
|
}
|
|
232
237
|
create(options) {
|
|
238
|
+
return new Promise((resolve, reject) => {
|
|
239
|
+
// 将创建请求添加到队列
|
|
240
|
+
this.createQueue.push({ options, resolve, reject });
|
|
241
|
+
// 如果当前没有在创建,则开始处理队列
|
|
242
|
+
if (!this.isCreating) {
|
|
243
|
+
this.processCreateQueue();
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* 处理创建队列
|
|
249
|
+
*/
|
|
250
|
+
async processCreateQueue() {
|
|
251
|
+
if (this.isCreating || this.createQueue.length === 0) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
this.isCreating = true;
|
|
255
|
+
while (this.createQueue.length > 0) {
|
|
256
|
+
const { options, resolve, reject } = this.createQueue.shift();
|
|
257
|
+
try {
|
|
258
|
+
const window = await this._createWindow(options);
|
|
259
|
+
resolve(window);
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
log('error', 'create window failed:', error);
|
|
263
|
+
reject(error);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
this.isCreating = false;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* 实际的窗口创建逻辑
|
|
270
|
+
*/
|
|
271
|
+
async _createWindow(options) {
|
|
233
272
|
let window;
|
|
234
273
|
const { usePreload = true, type = 'BW', name = 'anonymous', url, loadingView = { url: undefined }, errorView = { url: undefined }, browserWindow: browserWindowOptions, openDevTools = false, preventOriginClose = false, } = options;
|
|
235
274
|
options.type = type;
|
|
@@ -237,37 +276,41 @@ class WindowsManager {
|
|
|
237
276
|
let preloadWin = null;
|
|
238
277
|
if (type === 'BW' && usePreload && this.preloadWebContentsUrl) {
|
|
239
278
|
const bwOptions = browserWindowOptions || {};
|
|
240
|
-
if (bwOptions.frame === false
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
279
|
+
if (bwOptions.frame === false) {
|
|
280
|
+
if (bwOptions.titleBarStyle === 'customButtonsOnHover') {
|
|
281
|
+
preloadWin = this.preloadedBW_FramelessNoButtons;
|
|
282
|
+
this.preloadedBW_FramelessNoButtons = null;
|
|
283
|
+
setTimeout(async () => this.preloadedBW_FramelessNoButtons = await this._createPreloadBW({ frame: false, transparent: true, titleBarStyle: 'customButtonsOnHover' }), 0);
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
preloadWin = this.preloadedBW_FramelessWithButtons;
|
|
287
|
+
this.preloadedBW_FramelessWithButtons = null;
|
|
288
|
+
setTimeout(async () => this.preloadedBW_FramelessWithButtons = await this._createPreloadBW({ frame: false, transparent: true, titleBarStyle: 'hidden' }), 0);
|
|
289
|
+
}
|
|
249
290
|
}
|
|
250
291
|
else {
|
|
251
292
|
preloadWin = this.preloadedBW;
|
|
252
293
|
this.preloadedBW = null;
|
|
253
|
-
setTimeout(() => this._createPreloadBW({}), 0);
|
|
294
|
+
setTimeout(async () => this.preloadedBW = await this._createPreloadBW({}), 0);
|
|
254
295
|
}
|
|
255
296
|
}
|
|
256
297
|
if (type === 'BV' && usePreload && this.preloadWebContentsUrl) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
298
|
+
if (this.preloadedBV) {
|
|
299
|
+
preloadWin = this.preloadedBV;
|
|
300
|
+
this.preloadedBV = null;
|
|
301
|
+
setTimeout(async () => this.preloadedBV = await this._createPreloadBV(), 0);
|
|
302
|
+
}
|
|
260
303
|
}
|
|
261
304
|
if (preloadWin) {
|
|
262
305
|
const win = preloadWin;
|
|
263
|
-
log('log', `${name}
|
|
306
|
+
log('log', `${name} 使用预加载窗口(${type})`, win._id);
|
|
264
307
|
win._type = 'BW';
|
|
265
308
|
win._name = options.name || 'anonymous';
|
|
266
309
|
win._extraData = `${options?.extraData || ''}`;
|
|
267
310
|
win._initUrl = `${options?.url || ''}`;
|
|
268
311
|
// @ts-ignore
|
|
269
|
-
win?.removeAllListeners && win?.removeAllListeners?.();
|
|
270
|
-
win.webContents.removeAllListeners && win.webContents.removeAllListeners();
|
|
312
|
+
// win?.removeAllListeners && win?.removeAllListeners?.();
|
|
313
|
+
// win.webContents.removeAllListeners && win.webContents.removeAllListeners();
|
|
271
314
|
if (type === 'BW') {
|
|
272
315
|
// @ts-ignore
|
|
273
316
|
this._applyBrowserWindowOptions(win, options);
|
|
@@ -503,10 +546,6 @@ class WindowsManager {
|
|
|
503
546
|
parentWin?.addBrowserView(window);
|
|
504
547
|
log('log', 'create - addBrowserView');
|
|
505
548
|
}
|
|
506
|
-
// @ts-ignore
|
|
507
|
-
window.loadURL ? window.loadURL(options.url) : window.webContents.loadURL(options.url);
|
|
508
|
-
// @ts-ignore
|
|
509
|
-
window.focus ? window.focus() : window.webContents.focus();
|
|
510
549
|
this.windows.set(window.id || window._id || window.webContents.id, window);
|
|
511
550
|
log('log', 'create', this.windows.keys());
|
|
512
551
|
// 初始化值
|
|
@@ -599,6 +638,13 @@ class WindowsManager {
|
|
|
599
638
|
log('error', 'focus', error);
|
|
600
639
|
}
|
|
601
640
|
}
|
|
641
|
+
console.log('message xxxx', options.url);
|
|
642
|
+
if (options.url) {
|
|
643
|
+
// @ts-ignore
|
|
644
|
+
window.loadURL ? window.loadURL(options.url) : window.webContents.loadURL(options.url);
|
|
645
|
+
// @ts-ignore
|
|
646
|
+
window.focus ? window.focus() : window.webContents.focus();
|
|
647
|
+
}
|
|
602
648
|
}
|
|
603
649
|
catch (error) {
|
|
604
650
|
log('error', 'create', error);
|
|
@@ -882,7 +928,7 @@ class WindowsManager {
|
|
|
882
928
|
// 生成一个bv 做为预加载资源窗口,加载完成后销毁
|
|
883
929
|
async createPreloadWebContents(url) {
|
|
884
930
|
return new Promise(async (resolve, reject) => {
|
|
885
|
-
let bv = this.create({
|
|
931
|
+
let bv = await this.create({
|
|
886
932
|
type: 'BV',
|
|
887
933
|
url,
|
|
888
934
|
name: `preload-web-contents-${md5(url)}`,
|
|
@@ -937,7 +983,7 @@ const initialize = (preload, loadingViewUrl, errorViewUrl, preloadWebContentsUrl
|
|
|
937
983
|
winInitUrl: `${findWin?._initUrl || ''}`,
|
|
938
984
|
};
|
|
939
985
|
}
|
|
940
|
-
const res = wm.create(opt.data);
|
|
986
|
+
const res = await wm.create(opt.data);
|
|
941
987
|
return {
|
|
942
988
|
winId: Number(`${res.id || res._id || -1}`),
|
|
943
989
|
winName: `${res?._name || ''}`,
|