@lynker-desktop/electron-window-manager 0.0.9-alpha.50 → 0.0.9-alpha.51
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 +5 -0
- package/esm/main/index.d.ts.map +1 -1
- package/esm/main/index.js +116 -70
- package/esm/main/index.js.map +1 -1
- package/esm/renderer/index.d.ts.map +1 -1
- package/esm/renderer/index.js +43 -15
- package/esm/renderer/index.js.map +1 -1
- package/main/index.d.ts +5 -0
- package/main/index.d.ts.map +1 -1
- package/main/index.js +123 -77
- package/main/index.js.map +1 -1
- package/package.json +2 -2
- package/renderer/index.d.ts.map +1 -1
- package/renderer/index.js +43 -15
- package/renderer/index.js.map +1 -1
package/esm/main/index.d.ts
CHANGED
|
@@ -76,6 +76,11 @@ export declare class WindowsManager {
|
|
|
76
76
|
* 检查窗口是否已销毁
|
|
77
77
|
*/
|
|
78
78
|
private _isWindowDestroyed;
|
|
79
|
+
/**
|
|
80
|
+
* 安全地获取窗口的 webContents.id
|
|
81
|
+
* 如果 webContents 已销毁,返回 undefined
|
|
82
|
+
*/
|
|
83
|
+
_getWebContentsId(win: BWItem | BVItem | null | undefined): number | undefined;
|
|
79
84
|
/**
|
|
80
85
|
* 判断是否本地/内网IP
|
|
81
86
|
*/
|
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,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;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/main/index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M,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
|
@@ -34,21 +34,30 @@ const enable = (win) => {
|
|
|
34
34
|
remote.enable(win);
|
|
35
35
|
};
|
|
36
36
|
const initWebContentsVal = (win, preload) => {
|
|
37
|
-
win.webContents.executeJavaScript(`
|
|
38
37
|
try {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
38
|
+
if (!win?.webContents || win.webContents.isDestroyed()) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const webContentsId = win.webContents.id;
|
|
42
|
+
win.webContents.executeJavaScript(`
|
|
43
|
+
try {
|
|
44
|
+
const data = {
|
|
45
|
+
__ELECTRON_WINDOW_MANAGER_WEB_CONTENTS_ID__: ${JSON.stringify(webContentsId)},
|
|
46
|
+
__ELECTRON_WINDOW_MANAGER_TYPE__: ${JSON.stringify(win._type)},
|
|
47
|
+
__ELECTRON_WINDOW_MANAGER_NAME__: ${JSON.stringify(win._name)},
|
|
48
|
+
__ELECTRON_WINDOW_MANAGER_EXTRA_DATA__: ${JSON.stringify(win._extraData || '')},
|
|
49
|
+
__ELECTRON_WINDOW_MANAGER_PRELOAD__: ${JSON.stringify(preload)},
|
|
50
|
+
__ELECTRON_WINDOW_MANAGER_INIT_URL__: ${JSON.stringify(win._initUrl || '')}
|
|
51
|
+
};
|
|
52
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
53
|
+
window[key] = value;
|
|
54
|
+
});
|
|
55
|
+
} catch (error) {}
|
|
56
|
+
`);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
// 忽略错误,webContents 可能已销毁
|
|
60
|
+
}
|
|
52
61
|
};
|
|
53
62
|
class WindowsManager {
|
|
54
63
|
/**
|
|
@@ -259,14 +268,18 @@ class WindowsManager {
|
|
|
259
268
|
log('error', '预加载 BW 设置 remote 失败', error);
|
|
260
269
|
}
|
|
261
270
|
try {
|
|
262
|
-
|
|
263
|
-
|
|
271
|
+
const webContentsId = instance.webContents?.id;
|
|
272
|
+
if (webContentsId !== undefined) {
|
|
273
|
+
// @ts-ignore
|
|
274
|
+
instance._id = webContentsId;
|
|
275
|
+
}
|
|
264
276
|
}
|
|
265
277
|
catch (error) {
|
|
266
278
|
log('error', '预加载 BW 设置 _id 失败', error);
|
|
267
279
|
}
|
|
268
280
|
// @ts-ignore
|
|
269
|
-
|
|
281
|
+
const webContentsId = instance.webContents?.id;
|
|
282
|
+
log('log', '创建预BW: ', webContentsId, this.preloadWebContentsConfig?.url);
|
|
270
283
|
// instance.webContents.once('did-finish-load', () => {
|
|
271
284
|
// resolve(instance as BWItem);
|
|
272
285
|
// });
|
|
@@ -313,8 +326,11 @@ class WindowsManager {
|
|
|
313
326
|
log('error', '预加载 BV 设置 remote 失败', error);
|
|
314
327
|
}
|
|
315
328
|
try {
|
|
316
|
-
|
|
317
|
-
|
|
329
|
+
const webContentsId = instance.webContents?.id;
|
|
330
|
+
if (webContentsId !== undefined) {
|
|
331
|
+
// @ts-ignore
|
|
332
|
+
instance._id = webContentsId;
|
|
333
|
+
}
|
|
318
334
|
// 设置默认zIndex层级
|
|
319
335
|
instance._zIndex = 0;
|
|
320
336
|
}
|
|
@@ -322,7 +338,8 @@ class WindowsManager {
|
|
|
322
338
|
log('error', '预加载 BV 设置 _id 失败', error);
|
|
323
339
|
}
|
|
324
340
|
// @ts-ignore
|
|
325
|
-
|
|
341
|
+
const webContentsId = instance.webContents?.id;
|
|
342
|
+
log('log', '创建预BV: ', webContentsId, this.preloadWebContentsConfig?.url);
|
|
326
343
|
// instance.webContents.once('did-finish-load', () => {
|
|
327
344
|
// resolve(instance as BVItem);
|
|
328
345
|
// });
|
|
@@ -418,7 +435,7 @@ class WindowsManager {
|
|
|
418
435
|
}
|
|
419
436
|
if (preloadWin) {
|
|
420
437
|
const win = preloadWin;
|
|
421
|
-
log('log', `${name} 使用预加载窗口(${type})`, win
|
|
438
|
+
log('log', `${name} 使用预加载窗口(${type})`, this._getWebContentsId(win));
|
|
422
439
|
win._type = type;
|
|
423
440
|
win._name = options.name || 'anonymous';
|
|
424
441
|
win._extraData = `${options?.extraData || ''}`;
|
|
@@ -588,15 +605,12 @@ class WindowsManager {
|
|
|
588
605
|
// 停止加载
|
|
589
606
|
// window.webContents?.stop?.();
|
|
590
607
|
// @ts-ignore
|
|
591
|
-
try {
|
|
592
|
-
window.id = Number(`${window.id || window.webContents.id}`);
|
|
593
|
-
}
|
|
594
|
-
catch (error) {
|
|
595
|
-
// log('error', 'set id: ', error)
|
|
596
|
-
}
|
|
597
608
|
// @ts-ignore
|
|
598
609
|
try {
|
|
599
|
-
|
|
610
|
+
const webContentsId = this._getWebContentsId(window);
|
|
611
|
+
if (webContentsId !== undefined) {
|
|
612
|
+
window._id = Number(`${webContentsId}`);
|
|
613
|
+
}
|
|
600
614
|
}
|
|
601
615
|
catch (error) {
|
|
602
616
|
// log('error', 'set id: ', error)
|
|
@@ -607,7 +621,7 @@ class WindowsManager {
|
|
|
607
621
|
window._initUrl = `${options?.url || ''}`;
|
|
608
622
|
// 设置zIndex层级
|
|
609
623
|
window._zIndex = options.zIndex ?? 0;
|
|
610
|
-
log('log', 'create 5: ',
|
|
624
|
+
log('log', 'create 5: ', this._getWebContentsId(window), window._name);
|
|
611
625
|
if (loadingView?.url && loadingView?.url !== 'about:blank') {
|
|
612
626
|
if (type === 'BW') {
|
|
613
627
|
// @ts-ignore
|
|
@@ -720,8 +734,10 @@ class WindowsManager {
|
|
|
720
734
|
// this.windows.delete(window.id || window._id)
|
|
721
735
|
// })
|
|
722
736
|
window.webContents.on('destroyed', () => {
|
|
723
|
-
const winId =
|
|
724
|
-
|
|
737
|
+
const winId = this._getWebContentsId(window);
|
|
738
|
+
if (winId !== undefined) {
|
|
739
|
+
this.windows.delete(winId);
|
|
740
|
+
}
|
|
725
741
|
// 同步清理名称索引
|
|
726
742
|
this.windowsByName.delete(window._name);
|
|
727
743
|
});
|
|
@@ -737,9 +753,11 @@ class WindowsManager {
|
|
|
737
753
|
}
|
|
738
754
|
// @ts-ignore
|
|
739
755
|
window.on('closed', () => {
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
756
|
+
const winId = this._getWebContentsId(window);
|
|
757
|
+
log('log', 'closed', winId, window._name);
|
|
758
|
+
if (winId !== undefined) {
|
|
759
|
+
this.windows.delete(winId);
|
|
760
|
+
}
|
|
743
761
|
// 同步清理名称索引
|
|
744
762
|
this.windowsByName.delete(window._name);
|
|
745
763
|
});
|
|
@@ -748,18 +766,20 @@ class WindowsManager {
|
|
|
748
766
|
parentWin?.addBrowserView(window);
|
|
749
767
|
log('log', 'create - addBrowserView');
|
|
750
768
|
}
|
|
751
|
-
const winId =
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
769
|
+
const winId = this._getWebContentsId(window);
|
|
770
|
+
if (winId !== undefined) {
|
|
771
|
+
this.windows.set(winId, window);
|
|
772
|
+
// 同步更新名称索引
|
|
773
|
+
this.windowsByName.set(window._name, winId);
|
|
774
|
+
}
|
|
755
775
|
log('log', 'create', this.windows.keys());
|
|
756
776
|
// 初始化值
|
|
757
777
|
window.webContents.on('did-finish-load', () => {
|
|
758
|
-
log('log', 'did-finish-load', window
|
|
778
|
+
log('log', 'did-finish-load', this._getWebContentsId(window));
|
|
759
779
|
initWebContentsVal(window, `${preload || ''}`);
|
|
760
780
|
});
|
|
761
781
|
window.webContents.on('did-start-loading', () => {
|
|
762
|
-
log('log', 'did-start-loading', window
|
|
782
|
+
log('log', 'did-start-loading', this._getWebContentsId(window));
|
|
763
783
|
initWebContentsVal(window, `${preload || ''}`);
|
|
764
784
|
});
|
|
765
785
|
if (type === 'BW') {
|
|
@@ -960,6 +980,24 @@ class WindowsManager {
|
|
|
960
980
|
return true;
|
|
961
981
|
}
|
|
962
982
|
}
|
|
983
|
+
/**
|
|
984
|
+
* 安全地获取窗口的 webContents.id
|
|
985
|
+
* 如果 webContents 已销毁,返回 undefined
|
|
986
|
+
*/
|
|
987
|
+
_getWebContentsId(win) {
|
|
988
|
+
try {
|
|
989
|
+
if (!win || !win.webContents) {
|
|
990
|
+
return undefined;
|
|
991
|
+
}
|
|
992
|
+
if (win.webContents.isDestroyed()) {
|
|
993
|
+
return undefined;
|
|
994
|
+
}
|
|
995
|
+
return win.webContents.id;
|
|
996
|
+
}
|
|
997
|
+
catch {
|
|
998
|
+
return undefined;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
963
1001
|
/**
|
|
964
1002
|
* 判断是否本地/内网IP
|
|
965
1003
|
*/
|
|
@@ -991,16 +1029,8 @@ class WindowsManager {
|
|
|
991
1029
|
log('log', 'get', idOrName);
|
|
992
1030
|
let win;
|
|
993
1031
|
if (typeof idOrName === 'number') {
|
|
994
|
-
// 按 ID 查找(O(1)
|
|
1032
|
+
// 按 ID 查找(O(1)),使用 webContents.id
|
|
995
1033
|
win = this.windows.get(idOrName);
|
|
996
|
-
// 如果找不到,尝试按 _id 查找
|
|
997
|
-
if (!win) {
|
|
998
|
-
this.windows.forEach(w => {
|
|
999
|
-
if (w._id === idOrName) {
|
|
1000
|
-
win = w;
|
|
1001
|
-
}
|
|
1002
|
-
});
|
|
1003
|
-
}
|
|
1004
1034
|
}
|
|
1005
1035
|
else if (typeof idOrName === 'string') {
|
|
1006
1036
|
// 按名称查找(O(1),使用索引)
|
|
@@ -1013,8 +1043,11 @@ class WindowsManager {
|
|
|
1013
1043
|
this.windows.forEach(w => {
|
|
1014
1044
|
if (w._name === idOrName) {
|
|
1015
1045
|
win = w;
|
|
1016
|
-
//
|
|
1017
|
-
this.
|
|
1046
|
+
// 更新索引,使用 webContents.id
|
|
1047
|
+
const webContentsId = this._getWebContentsId(w);
|
|
1048
|
+
if (webContentsId !== undefined) {
|
|
1049
|
+
this.windowsByName.set(idOrName, webContentsId);
|
|
1050
|
+
}
|
|
1018
1051
|
}
|
|
1019
1052
|
});
|
|
1020
1053
|
}
|
|
@@ -1025,7 +1058,7 @@ class WindowsManager {
|
|
|
1025
1058
|
}
|
|
1026
1059
|
// 窗口已销毁,触发清理
|
|
1027
1060
|
if (win) {
|
|
1028
|
-
const winId =
|
|
1061
|
+
const winId = this._getWebContentsId(win);
|
|
1029
1062
|
if (winId !== undefined) {
|
|
1030
1063
|
this.windows.delete(winId);
|
|
1031
1064
|
}
|
|
@@ -1068,8 +1101,10 @@ class WindowsManager {
|
|
|
1068
1101
|
if (!win) {
|
|
1069
1102
|
return false;
|
|
1070
1103
|
}
|
|
1071
|
-
const winId =
|
|
1072
|
-
|
|
1104
|
+
const winId = this._getWebContentsId(win);
|
|
1105
|
+
if (winId !== undefined) {
|
|
1106
|
+
this.windows.delete(winId);
|
|
1107
|
+
}
|
|
1073
1108
|
if (win._name) {
|
|
1074
1109
|
this.windowsByName.delete(win._name);
|
|
1075
1110
|
}
|
|
@@ -1155,9 +1190,11 @@ class WindowsManager {
|
|
|
1155
1190
|
}
|
|
1156
1191
|
// 更新名称索引
|
|
1157
1192
|
const oldName = win._name;
|
|
1158
|
-
const winId =
|
|
1159
|
-
|
|
1160
|
-
|
|
1193
|
+
const winId = this._getWebContentsId(win);
|
|
1194
|
+
if (winId !== undefined) {
|
|
1195
|
+
this.windowsByName.delete(oldName);
|
|
1196
|
+
this.windowsByName.set(newName, winId);
|
|
1197
|
+
}
|
|
1161
1198
|
// 修改名字并同步 webContents
|
|
1162
1199
|
win._name = newName;
|
|
1163
1200
|
initWebContentsVal(win, `${this.preload || ''}`);
|
|
@@ -1316,7 +1353,7 @@ class WindowsManager {
|
|
|
1316
1353
|
extraData: `${url}`
|
|
1317
1354
|
});
|
|
1318
1355
|
return new Promise((resolve, reject) => {
|
|
1319
|
-
const winId =
|
|
1356
|
+
const winId = this._getWebContentsId(bv);
|
|
1320
1357
|
if (!winId) {
|
|
1321
1358
|
reject(new Error('Failed to get window ID'));
|
|
1322
1359
|
return;
|
|
@@ -1340,7 +1377,7 @@ class WindowsManager {
|
|
|
1340
1377
|
}
|
|
1341
1378
|
catch (error) {
|
|
1342
1379
|
if (bv) {
|
|
1343
|
-
const winId =
|
|
1380
|
+
const winId = this._getWebContentsId(bv);
|
|
1344
1381
|
if (winId) {
|
|
1345
1382
|
this.close(winId);
|
|
1346
1383
|
}
|
|
@@ -1393,7 +1430,7 @@ class WindowsManager {
|
|
|
1393
1430
|
const views = window.getBrowserViews() || [];
|
|
1394
1431
|
if (views.length <= 1)
|
|
1395
1432
|
return;
|
|
1396
|
-
log('log', 'sortBrowserViews', views?.map(i => i
|
|
1433
|
+
log('log', 'sortBrowserViews', views?.map(i => this._getWebContentsId(i)));
|
|
1397
1434
|
// 创建排序后的视图数组(不修改原数组)
|
|
1398
1435
|
const sortedViews = [...views].sort((a, b) => {
|
|
1399
1436
|
const zIndexA = a._zIndex ?? 0;
|
|
@@ -1405,18 +1442,22 @@ class WindowsManager {
|
|
|
1405
1442
|
for (let i = 0; i < views.length; i++) {
|
|
1406
1443
|
const view = views[i];
|
|
1407
1444
|
const sortedView = sortedViews[i];
|
|
1408
|
-
|
|
1445
|
+
const viewId = this._getWebContentsId(view);
|
|
1446
|
+
const sortedViewId = this._getWebContentsId(sortedView);
|
|
1447
|
+
if (!view || !sortedView || viewId !== sortedViewId) {
|
|
1409
1448
|
needsReorder = true;
|
|
1410
1449
|
break;
|
|
1411
1450
|
}
|
|
1412
1451
|
}
|
|
1413
|
-
log('log', 'sortBrowserViews needsReorder', needsReorder, sortedViews?.map(i => i
|
|
1452
|
+
log('log', 'sortBrowserViews needsReorder', needsReorder, sortedViews?.map(i => this._getWebContentsId(i)));
|
|
1414
1453
|
// 如果已经按正确顺序排列,则不需要重新排序
|
|
1415
1454
|
if (!needsReorder)
|
|
1416
1455
|
return;
|
|
1417
1456
|
// 移除所有BrowserView(排除刚添加的视图,避免不必要的操作)
|
|
1457
|
+
const addViewId = this._getWebContentsId(addView);
|
|
1418
1458
|
views.forEach(view => {
|
|
1419
|
-
|
|
1459
|
+
const viewId = this._getWebContentsId(view);
|
|
1460
|
+
if (addViewId !== viewId) {
|
|
1420
1461
|
try {
|
|
1421
1462
|
// @ts-ignore
|
|
1422
1463
|
window.removeBrowserView(view, false);
|
|
@@ -1493,8 +1534,9 @@ const initialize = (preload, loadingViewUrl, errorViewUrl, preloadWebContentsCon
|
|
|
1493
1534
|
if (findWin?._type === 'BV' && opt.data.zIndex) {
|
|
1494
1535
|
findWin._zIndex = opt.data.zIndex;
|
|
1495
1536
|
}
|
|
1537
|
+
const winId = wm._getWebContentsId(findWin);
|
|
1496
1538
|
return {
|
|
1497
|
-
winId: Number(`${
|
|
1539
|
+
winId: Number(`${winId || -1}`),
|
|
1498
1540
|
winName: `${findWin?._name || ''}`,
|
|
1499
1541
|
winType: `${findWin?._type || ''}`,
|
|
1500
1542
|
winExtraData: `${findWin?._extraData || ''}`,
|
|
@@ -1503,8 +1545,9 @@ const initialize = (preload, loadingViewUrl, errorViewUrl, preloadWebContentsCon
|
|
|
1503
1545
|
};
|
|
1504
1546
|
}
|
|
1505
1547
|
const res = await wm.create(opt.data);
|
|
1548
|
+
const winId = wm._getWebContentsId(res);
|
|
1506
1549
|
return {
|
|
1507
|
-
winId: Number(`${
|
|
1550
|
+
winId: Number(`${winId || -1}`),
|
|
1508
1551
|
winName: `${res?._name || ''}`,
|
|
1509
1552
|
winType: `${res?._type || ''}`,
|
|
1510
1553
|
winExtraData: `${res?._extraData || ''}`,
|
|
@@ -1515,8 +1558,9 @@ const initialize = (preload, loadingViewUrl, errorViewUrl, preloadWebContentsCon
|
|
|
1515
1558
|
if (data?.type === 'get') {
|
|
1516
1559
|
const opt = data;
|
|
1517
1560
|
const res = wm.get(opt?.data);
|
|
1561
|
+
const winId = wm._getWebContentsId(res);
|
|
1518
1562
|
return {
|
|
1519
|
-
winId: Number(`${
|
|
1563
|
+
winId: Number(`${winId || -1}`),
|
|
1520
1564
|
winName: `${res?._name || ''}`,
|
|
1521
1565
|
winType: `${res?._type || ''}`,
|
|
1522
1566
|
winExtraData: `${res?._extraData || ''}`,
|
|
@@ -1528,7 +1572,7 @@ const initialize = (preload, loadingViewUrl, errorViewUrl, preloadWebContentsCon
|
|
|
1528
1572
|
const res = wm.getAll();
|
|
1529
1573
|
const obj = {};
|
|
1530
1574
|
res.forEach(i => {
|
|
1531
|
-
const winId =
|
|
1575
|
+
const winId = wm._getWebContentsId(i);
|
|
1532
1576
|
if (winId !== undefined) {
|
|
1533
1577
|
obj[winId] = {
|
|
1534
1578
|
winId: Number(`${winId}`),
|
|
@@ -1555,8 +1599,9 @@ const initialize = (preload, loadingViewUrl, errorViewUrl, preloadWebContentsCon
|
|
|
1555
1599
|
const opt = data;
|
|
1556
1600
|
const res = wm.rename(opt.data.idOrName, opt.data.newName);
|
|
1557
1601
|
if (res) {
|
|
1602
|
+
const winId = wm._getWebContentsId(res);
|
|
1558
1603
|
return {
|
|
1559
|
-
winId: Number(`${
|
|
1604
|
+
winId: Number(`${winId || -1}`),
|
|
1560
1605
|
winName: `${res?._name || ''}`,
|
|
1561
1606
|
winType: `${res?._type || ''}`,
|
|
1562
1607
|
winExtraData: `${res?._extraData || ''}`,
|
|
@@ -1570,8 +1615,9 @@ const initialize = (preload, loadingViewUrl, errorViewUrl, preloadWebContentsCon
|
|
|
1570
1615
|
const opt = data;
|
|
1571
1616
|
const res = wm.reInitUrl(opt.data.idOrName, opt.data.url);
|
|
1572
1617
|
if (res) {
|
|
1618
|
+
const winId = wm._getWebContentsId(res);
|
|
1573
1619
|
return {
|
|
1574
|
-
winId: Number(`${
|
|
1620
|
+
winId: Number(`${winId || -1}`),
|
|
1575
1621
|
winName: `${res?._name || ''}`,
|
|
1576
1622
|
winType: `${res?._type || ''}`,
|
|
1577
1623
|
winExtraData: `${res?._extraData || ''}`,
|
|
@@ -1585,7 +1631,7 @@ const initialize = (preload, loadingViewUrl, errorViewUrl, preloadWebContentsCon
|
|
|
1585
1631
|
const opt = data;
|
|
1586
1632
|
const res = await wm.getWindowForWebContentsId(opt.data);
|
|
1587
1633
|
if (res) {
|
|
1588
|
-
return res
|
|
1634
|
+
return wm._getWebContentsId(res);
|
|
1589
1635
|
}
|
|
1590
1636
|
return undefined;
|
|
1591
1637
|
}
|