@lynker-desktop/electron-window-manager 0.0.9-alpha.48 → 0.0.9-alpha.49
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.map +1 -1
- package/esm/main/index.js +32 -5
- package/esm/main/index.js.map +1 -1
- package/main/index.d.ts.map +1 -1
- package/main/index.js +32 -5
- package/main/index.js.map +1 -1
- package/package.json +2 -2
package/main/index.js
CHANGED
|
@@ -365,6 +365,15 @@ class WindowsManager {
|
|
|
365
365
|
async _createWindow(options) {
|
|
366
366
|
let window;
|
|
367
367
|
const { usePreload = true, type = 'BW', name = 'anonymous', url, loadingView = { url: undefined }, errorView = { url: undefined }, browserWindow: browserWindowOptions, openDevTools = false, preventOriginClose = false, zIndex = 0, } = options;
|
|
368
|
+
const existingWinId = this.windowsByName.get(options.name);
|
|
369
|
+
if (existingWinId) {
|
|
370
|
+
window = this.windows.get(existingWinId);
|
|
371
|
+
if (window) {
|
|
372
|
+
return window;
|
|
373
|
+
}
|
|
374
|
+
// 清理无效的引用
|
|
375
|
+
this.windowsByName.delete(options.name);
|
|
376
|
+
}
|
|
368
377
|
options.type = type;
|
|
369
378
|
// 优先复用预创建实例
|
|
370
379
|
let preloadWin = null;
|
|
@@ -423,7 +432,7 @@ class WindowsManager {
|
|
|
423
432
|
if (preloadWin) {
|
|
424
433
|
const win = preloadWin;
|
|
425
434
|
log('log', `${name} 使用预加载窗口(${type})`, win._id);
|
|
426
|
-
win._type =
|
|
435
|
+
win._type = type;
|
|
427
436
|
win._name = options.name || 'anonymous';
|
|
428
437
|
win._extraData = `${options?.extraData || ''}`;
|
|
429
438
|
win._initUrl = `${options?.url || ''}`;
|
|
@@ -447,7 +456,14 @@ class WindowsManager {
|
|
|
447
456
|
return new Promise(async (resolve, reject) => {
|
|
448
457
|
if (useNativeLoadURL) {
|
|
449
458
|
console.error('useNativeLoadURL win.loadURL');
|
|
450
|
-
|
|
459
|
+
try {
|
|
460
|
+
await originLoadURL.call(win, url);
|
|
461
|
+
resolve(undefined);
|
|
462
|
+
}
|
|
463
|
+
catch (error) {
|
|
464
|
+
reject(error);
|
|
465
|
+
}
|
|
466
|
+
return;
|
|
451
467
|
}
|
|
452
468
|
try {
|
|
453
469
|
console.error('customLoadURL win.loadURL');
|
|
@@ -473,7 +489,14 @@ class WindowsManager {
|
|
|
473
489
|
return new Promise(async (resolve, reject) => {
|
|
474
490
|
if (useNativeLoadURL) {
|
|
475
491
|
console.error('useNativeLoadURL win.webContents.loadURL');
|
|
476
|
-
|
|
492
|
+
try {
|
|
493
|
+
await originWebContentsLoadURL.call(win.webContents, url);
|
|
494
|
+
resolve(undefined);
|
|
495
|
+
}
|
|
496
|
+
catch (error) {
|
|
497
|
+
reject(error);
|
|
498
|
+
}
|
|
499
|
+
return;
|
|
477
500
|
}
|
|
478
501
|
try {
|
|
479
502
|
console.error('customLoadURL win.webContents.loadURL');
|
|
@@ -832,8 +855,8 @@ class WindowsManager {
|
|
|
832
855
|
const _setBrowserView = window.setBrowserView;
|
|
833
856
|
window.setBrowserView = (view, isSort = false) => {
|
|
834
857
|
const views = window.getBrowserViews() || [];
|
|
835
|
-
for (const
|
|
836
|
-
handleBrowserViewBlur(
|
|
858
|
+
for (const existingView of views) {
|
|
859
|
+
handleBrowserViewBlur(existingView);
|
|
837
860
|
}
|
|
838
861
|
_setBrowserView.call(window, view);
|
|
839
862
|
handleBrowserViewFocus(view);
|
|
@@ -858,6 +881,10 @@ class WindowsManager {
|
|
|
858
881
|
}
|
|
859
882
|
catch (error) {
|
|
860
883
|
log('error', 'create', error);
|
|
884
|
+
throw error;
|
|
885
|
+
}
|
|
886
|
+
if (!window) {
|
|
887
|
+
throw new Error(`Failed to create window: ${name}`);
|
|
861
888
|
}
|
|
862
889
|
return window;
|
|
863
890
|
}
|