@lynker-desktop/electron-window-manager 0.0.9-alpha.10 → 0.0.9-alpha.11
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/common/index.d.ts +15 -0
- package/common/index.d.ts.map +1 -1
- package/esm/common/index.d.ts +15 -0
- package/esm/common/index.d.ts.map +1 -1
- package/esm/main/index.d.ts +7 -7
- package/esm/main/index.d.ts.map +1 -1
- package/esm/main/index.js +84 -72
- package/esm/main/index.js.map +1 -1
- package/esm/renderer/index.d.ts +4 -4
- package/esm/renderer/index.d.ts.map +1 -1
- package/esm/renderer/index.js +6 -6
- package/esm/renderer/index.js.map +1 -1
- package/main/index.d.ts +7 -7
- package/main/index.d.ts.map +1 -1
- package/main/index.js +84 -72
- package/main/index.js.map +1 -1
- package/package.json +2 -2
- package/renderer/index.d.ts +4 -4
- package/renderer/index.d.ts.map +1 -1
- package/renderer/index.js +6 -6
- package/renderer/index.js.map +1 -1
package/main/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { WebContents } from 'electron';
|
|
2
|
-
import type { ElectronWindowsManagerOptions, BWItem, BVItem } from '../common';
|
|
2
|
+
import type { ElectronWindowsManagerOptions, BWItem, BVItem, PreloadWebContentsConfig } from '../common';
|
|
3
3
|
export declare const getCustomSession: () => Electron.Session;
|
|
4
4
|
export declare const enable: (win: WebContents) => void;
|
|
5
5
|
export declare class WindowsManager {
|
|
6
6
|
loadingViewUrl: string | undefined;
|
|
7
7
|
errorViewUrl: string | undefined;
|
|
8
8
|
preload?: string;
|
|
9
|
-
|
|
9
|
+
preloadWebContentsConfig?: PreloadWebContentsConfig;
|
|
10
10
|
windows: Map<number, BWItem | BVItem>;
|
|
11
11
|
preloadedBW: BWItem | null;
|
|
12
12
|
preloadedBW_FramelessWithButtons: BWItem | null;
|
|
@@ -32,12 +32,12 @@ export declare class WindowsManager {
|
|
|
32
32
|
* - 不带点的(如 example.com)只匹配主域名。
|
|
33
33
|
* - 'localhost'、'127.0.0.1'、'::1' 以及局域网 IP(如 192.168.x.x、10.x.x.x、172.16.x.x~172.31.x.x)都视为本地白名单。
|
|
34
34
|
*/
|
|
35
|
-
constructor(preload?: string, loadingViewUrl?: string, errorViewUrl?: string,
|
|
35
|
+
constructor(preload?: string, loadingViewUrl?: string, errorViewUrl?: string, preloadWebContentsConfig?: PreloadWebContentsConfig, webviewDomainWhiteList?: string[]);
|
|
36
36
|
/**
|
|
37
|
-
* 设置预加载的webContents
|
|
38
|
-
* @param
|
|
37
|
+
* 设置预加载的webContents配置
|
|
38
|
+
* @param preloadWebContentsConfig 预加载的webContents配置
|
|
39
39
|
*/
|
|
40
|
-
|
|
40
|
+
setPreloadWebContentsConfig(preloadWebContentsConfig: PreloadWebContentsConfig): void;
|
|
41
41
|
/**
|
|
42
42
|
* 预加载实例
|
|
43
43
|
*/
|
|
@@ -83,5 +83,5 @@ export declare class WindowsManager {
|
|
|
83
83
|
createPreloadWebContents(url: string): Promise<unknown>;
|
|
84
84
|
}
|
|
85
85
|
export declare let isInitialized: boolean;
|
|
86
|
-
export declare const initialize: (preload?: string, loadingViewUrl?: string, errorViewUrl?: string,
|
|
86
|
+
export declare const initialize: (preload?: string, loadingViewUrl?: string, errorViewUrl?: string, preloadWebContentsConfig?: PreloadWebContentsConfig, webviewDomainWhiteList?: string[]) => WindowsManager;
|
|
87
87
|
//# sourceMappingURL=index.d.ts.map
|
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,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/main/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC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/main/index.js
CHANGED
|
@@ -69,7 +69,7 @@ class WindowsManager {
|
|
|
69
69
|
* - 不带点的(如 example.com)只匹配主域名。
|
|
70
70
|
* - 'localhost'、'127.0.0.1'、'::1' 以及局域网 IP(如 192.168.x.x、10.x.x.x、172.16.x.x~172.31.x.x)都视为本地白名单。
|
|
71
71
|
*/
|
|
72
|
-
constructor(preload, loadingViewUrl, errorViewUrl,
|
|
72
|
+
constructor(preload, loadingViewUrl, errorViewUrl, preloadWebContentsConfig, webviewDomainWhiteList) {
|
|
73
73
|
// 预加载的窗口
|
|
74
74
|
this.preloadedBW = null;
|
|
75
75
|
// 预加载的窗口(无边框,有按钮)
|
|
@@ -87,25 +87,25 @@ class WindowsManager {
|
|
|
87
87
|
this.windows = new Map();
|
|
88
88
|
this.loadingViewUrl = `${loadingViewUrl ?? ''}`;
|
|
89
89
|
this.errorViewUrl = `${errorViewUrl ?? ''}`;
|
|
90
|
-
this.
|
|
90
|
+
this.preloadWebContentsConfig = preloadWebContentsConfig;
|
|
91
91
|
this.webviewDomainWhiteList = webviewDomainWhiteList || [];
|
|
92
|
-
log('log', '
|
|
93
|
-
if (this.
|
|
92
|
+
log('log', 'preloadWebContentsConfig: ', this.preloadWebContentsConfig);
|
|
93
|
+
if (this.preloadWebContentsConfig) {
|
|
94
94
|
electron.app.on('ready', () => {
|
|
95
|
-
if (this.
|
|
96
|
-
this.
|
|
95
|
+
if (this.preloadWebContentsConfig) {
|
|
96
|
+
this.setPreloadWebContentsConfig(this.preloadWebContentsConfig);
|
|
97
97
|
}
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
|
-
* 设置预加载的webContents
|
|
103
|
-
* @param
|
|
102
|
+
* 设置预加载的webContents配置
|
|
103
|
+
* @param preloadWebContentsConfig 预加载的webContents配置
|
|
104
104
|
*/
|
|
105
|
-
|
|
105
|
+
setPreloadWebContentsConfig(preloadWebContentsConfig) {
|
|
106
106
|
try {
|
|
107
|
-
this.
|
|
108
|
-
if (this.
|
|
107
|
+
this.preloadWebContentsConfig = preloadWebContentsConfig;
|
|
108
|
+
if (this.preloadWebContentsConfig) {
|
|
109
109
|
this._preloadInstances();
|
|
110
110
|
}
|
|
111
111
|
else {
|
|
@@ -116,7 +116,7 @@ class WindowsManager {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
catch (error) {
|
|
119
|
-
log('error', '
|
|
119
|
+
log('error', 'setPreloadWebContentsConfig error:', error);
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
@@ -127,23 +127,31 @@ class WindowsManager {
|
|
|
127
127
|
return;
|
|
128
128
|
this.preloading = true;
|
|
129
129
|
try {
|
|
130
|
-
if (this.
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
130
|
+
if (this.preloadWebContentsConfig) {
|
|
131
|
+
// 根据配置决定是否预加载普通窗口
|
|
132
|
+
if (this.preloadWebContentsConfig.enableBW !== false) {
|
|
133
|
+
this.preloadedBW = this.preloadedBW || await this._createPreloadBW({});
|
|
134
|
+
}
|
|
135
|
+
// 根据配置决定是否预加载无边框有按钮的窗口
|
|
136
|
+
if (this.preloadWebContentsConfig.enableBW_FramelessWithButtons !== false) {
|
|
137
|
+
this.preloadedBW_FramelessWithButtons = this.preloadedBW_FramelessWithButtons || await this._createPreloadBW({
|
|
138
|
+
frame: false,
|
|
139
|
+
transparent: true,
|
|
140
|
+
titleBarStyle: 'hidden',
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
// 根据配置决定是否预加载无边框无按钮的窗口
|
|
144
|
+
if (this.preloadWebContentsConfig.enableBW_FramelessNoButtons !== false) {
|
|
145
|
+
this.preloadedBW_FramelessNoButtons = this.preloadedBW_FramelessNoButtons || await this._createPreloadBW({
|
|
146
|
+
frame: false,
|
|
147
|
+
transparent: true,
|
|
148
|
+
titleBarStyle: 'customButtonsOnHover',
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
// 根据配置决定是否预加载浏览器视图
|
|
152
|
+
if (this.preloadWebContentsConfig.enableBV !== false) {
|
|
153
|
+
this.preloadedBV = this.preloadedBV || await this._createPreloadBV();
|
|
154
|
+
}
|
|
147
155
|
}
|
|
148
156
|
}
|
|
149
157
|
catch (e) {
|
|
@@ -159,8 +167,8 @@ class WindowsManager {
|
|
|
159
167
|
_createPreloadBW(options = {}) {
|
|
160
168
|
return new Promise((resolve) => {
|
|
161
169
|
const preload = this.preload;
|
|
162
|
-
const url = this.
|
|
163
|
-
if (this.
|
|
170
|
+
const url = this.preloadWebContentsConfig?.url;
|
|
171
|
+
if (this.preloadWebContentsConfig?.url) {
|
|
164
172
|
const webPreferences = (options.webPreferences || {});
|
|
165
173
|
const instance = new electron.BrowserWindow({
|
|
166
174
|
...options,
|
|
@@ -191,7 +199,7 @@ class WindowsManager {
|
|
|
191
199
|
log('error', '预加载 BW 设置 _id 失败', error);
|
|
192
200
|
}
|
|
193
201
|
// @ts-ignore
|
|
194
|
-
log('log', '创建预BW: ', instance._id, this.
|
|
202
|
+
log('log', '创建预BW: ', instance._id, this.preloadWebContentsConfig?.url);
|
|
195
203
|
// instance.webContents.once('did-finish-load', () => {
|
|
196
204
|
// resolve(instance as BWItem);
|
|
197
205
|
// });
|
|
@@ -210,8 +218,8 @@ class WindowsManager {
|
|
|
210
218
|
_createPreloadBV(options = {}) {
|
|
211
219
|
return new Promise((resolve) => {
|
|
212
220
|
const preload = this.preload;
|
|
213
|
-
const url = this.
|
|
214
|
-
if (this.
|
|
221
|
+
const url = this.preloadWebContentsConfig?.url;
|
|
222
|
+
if (this.preloadWebContentsConfig?.url) {
|
|
215
223
|
const webPreferences = (options.webPreferences || {});
|
|
216
224
|
const instance = new electron.BrowserView({
|
|
217
225
|
webPreferences: {
|
|
@@ -239,7 +247,7 @@ class WindowsManager {
|
|
|
239
247
|
log('error', '预加载 BV 设置 _id 失败', error);
|
|
240
248
|
}
|
|
241
249
|
// @ts-ignore
|
|
242
|
-
log('log', '创建预BV: ', instance._id, this.
|
|
250
|
+
log('log', '创建预BV: ', instance._id, this.preloadWebContentsConfig?.url);
|
|
243
251
|
// instance.webContents.once('did-finish-load', () => {
|
|
244
252
|
// resolve(instance as BVItem);
|
|
245
253
|
// });
|
|
@@ -291,51 +299,55 @@ class WindowsManager {
|
|
|
291
299
|
options.type = type;
|
|
292
300
|
// 优先复用预创建实例
|
|
293
301
|
let preloadWin = null;
|
|
294
|
-
if (type === 'BW' && usePreload && this.
|
|
302
|
+
if (type === 'BW' && usePreload && this.preloadWebContentsConfig?.url) {
|
|
295
303
|
const bwOptions = browserWindowOptions || {};
|
|
296
304
|
if (bwOptions.frame === false) {
|
|
297
305
|
if (bwOptions.titleBarStyle === 'customButtonsOnHover') {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
306
|
+
if (this.preloadWebContentsConfig.enableBW_FramelessNoButtons !== false) {
|
|
307
|
+
preloadWin = this.preloadedBW_FramelessNoButtons;
|
|
308
|
+
this.preloadedBW_FramelessNoButtons = await this._createPreloadBW({
|
|
309
|
+
frame: false,
|
|
310
|
+
transparent: true,
|
|
311
|
+
titleBarStyle: 'customButtonsOnHover',
|
|
312
|
+
webPreferences: {
|
|
313
|
+
preload: bwOptions?.webPreferences?.preload || this.preload,
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
}
|
|
307
317
|
}
|
|
308
318
|
else {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
319
|
+
if (this.preloadWebContentsConfig.enableBW_FramelessWithButtons !== false) {
|
|
320
|
+
preloadWin = this.preloadedBW_FramelessWithButtons;
|
|
321
|
+
this.preloadedBW_FramelessWithButtons = await this._createPreloadBW({
|
|
322
|
+
frame: false,
|
|
323
|
+
transparent: true,
|
|
324
|
+
titleBarStyle: 'hidden',
|
|
325
|
+
webPreferences: {
|
|
326
|
+
preload: this.preload,
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
if (this.preloadWebContentsConfig.enableBW !== false) {
|
|
334
|
+
preloadWin = this.preloadedBW;
|
|
335
|
+
this.preloadedBW = await this._createPreloadBW({
|
|
314
336
|
webPreferences: {
|
|
315
|
-
preload: this.preload,
|
|
337
|
+
preload: bwOptions?.webPreferences?.preload || this.preload,
|
|
316
338
|
}
|
|
317
339
|
});
|
|
318
340
|
}
|
|
319
341
|
}
|
|
320
|
-
else {
|
|
321
|
-
preloadWin = this.preloadedBW;
|
|
322
|
-
this.preloadedBW = await this._createPreloadBW({
|
|
323
|
-
webPreferences: {
|
|
324
|
-
preload: bwOptions?.webPreferences?.preload || this.preload,
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
342
|
}
|
|
329
|
-
if (type === 'BV' && usePreload && this.
|
|
343
|
+
if (type === 'BV' && usePreload && this.preloadWebContentsConfig?.url) {
|
|
330
344
|
const bvOptions = browserWindowOptions || {};
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
});
|
|
338
|
-
}
|
|
345
|
+
preloadWin = this.preloadedBV;
|
|
346
|
+
this.preloadedBV = await this._createPreloadBV({
|
|
347
|
+
webPreferences: {
|
|
348
|
+
preload: bvOptions?.webPreferences?.preload || this.preload,
|
|
349
|
+
}
|
|
350
|
+
});
|
|
339
351
|
}
|
|
340
352
|
if (preloadWin) {
|
|
341
353
|
const win = preloadWin;
|
|
@@ -993,7 +1005,7 @@ class WindowsManager {
|
|
|
993
1005
|
// @ts-ignore
|
|
994
1006
|
global['__ELECTRON_WINDOWS_MANAGER__'] = undefined;
|
|
995
1007
|
exports.isInitialized = false;
|
|
996
|
-
const initialize = (preload, loadingViewUrl, errorViewUrl,
|
|
1008
|
+
const initialize = (preload, loadingViewUrl, errorViewUrl, preloadWebContentsConfig, webviewDomainWhiteList) => {
|
|
997
1009
|
// @ts-ignore
|
|
998
1010
|
if (exports.isInitialized && global['__ELECTRON_WINDOWS_MANAGER__']) {
|
|
999
1011
|
// @ts-ignore
|
|
@@ -1001,7 +1013,7 @@ const initialize = (preload, loadingViewUrl, errorViewUrl, preloadWebContentsUrl
|
|
|
1001
1013
|
}
|
|
1002
1014
|
exports.isInitialized = true;
|
|
1003
1015
|
// @ts-ignore
|
|
1004
|
-
const wm = global['__ELECTRON_WINDOWS_MANAGER__'] = new WindowsManager(preload, loadingViewUrl, errorViewUrl,
|
|
1016
|
+
const wm = global['__ELECTRON_WINDOWS_MANAGER__'] = new WindowsManager(preload, loadingViewUrl, errorViewUrl, preloadWebContentsConfig, webviewDomainWhiteList);
|
|
1005
1017
|
eIpc.mainIPC.handleRenderer('__ELECTRON_WINDOW_MANAGER_IPC_CHANNEL__', async (data) => {
|
|
1006
1018
|
if (data?.type === 'create') {
|
|
1007
1019
|
const opt = data;
|
|
@@ -1161,9 +1173,9 @@ const initialize = (preload, loadingViewUrl, errorViewUrl, preloadWebContentsUrl
|
|
|
1161
1173
|
return undefined;
|
|
1162
1174
|
}
|
|
1163
1175
|
// 是否开启预加载窗口
|
|
1164
|
-
if (data?.type === '
|
|
1176
|
+
if (data?.type === 'setPreloadWebContentsConfig') {
|
|
1165
1177
|
const opt = data;
|
|
1166
|
-
wm.
|
|
1178
|
+
wm.setPreloadWebContentsConfig(opt.data);
|
|
1167
1179
|
}
|
|
1168
1180
|
if (data?.type === 'createPreloadWebContents') {
|
|
1169
1181
|
const opt = data;
|