nexfep 0.3.0 → 0.3.2
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/package.json +1 -1
- package/src/WindowManager.js +105 -101
package/package.json
CHANGED
package/src/WindowManager.js
CHANGED
|
@@ -284,114 +284,118 @@ class WindowPool {
|
|
|
284
284
|
await this.__injectCode(windowObj, INJECT_CODE);
|
|
285
285
|
}
|
|
286
286
|
async __createNewWindowObj() {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
const handlers = this.handlers.get(dataObj.event) || [];
|
|
337
|
-
handlers.forEach(async (handler) => {
|
|
338
|
-
const result = await handler(dataObj.data);
|
|
339
|
-
if (result) {
|
|
340
|
-
webview.evaluateScript(`
|
|
341
|
-
window.dispatchEvent(new CustomEvent('nexfep-invoke-result-${dataObj.eventId[0]}-${dataObj.eventId[1]}', { detail: ${JSON.stringify(result)} }));
|
|
342
|
-
`);
|
|
287
|
+
return await new Promise((resolve, reject) => {
|
|
288
|
+
setImmediate(() => {
|
|
289
|
+
const window = this.app.createBrowserWindow({ title: "Nexfep" });
|
|
290
|
+
window.hide();
|
|
291
|
+
this.freeWindowCount++;
|
|
292
|
+
const webview = window.createWebview();
|
|
293
|
+
const windowObj = new Window(window, webview, ++this.windowCount, this);
|
|
294
|
+
this.windows.push(windowObj);
|
|
295
|
+
webview.onIpcMessage((data) => {
|
|
296
|
+
const dataText = data.body.toString();
|
|
297
|
+
const dataObj = JSON.parse(dataText);
|
|
298
|
+
if (dataObj.type == 'NexfepBeforeUnload') {
|
|
299
|
+
webview.evaluateScript(`if(window?.isNexfepLoadDone){
|
|
300
|
+
const MessageBody = { type: 'NexfepBeforeUnload' }
|
|
301
|
+
window.ipc.postMessage(JSON.stringify(MessageBody));
|
|
302
|
+
}else{
|
|
303
|
+
const MessageBody = { type: 'NexfepLoadFalse' }
|
|
304
|
+
window.ipc.postMessage(JSON.stringify(MessageBody));
|
|
305
|
+
}`);
|
|
306
|
+
}
|
|
307
|
+
else if (dataObj.type == 'NexfepLoadFalse') {
|
|
308
|
+
this.__injectControlFunctions(windowObj);
|
|
309
|
+
}
|
|
310
|
+
else if (dataObj.type == 'NexfepCloseWindow') {
|
|
311
|
+
this.closeWindow(windowObj);
|
|
312
|
+
}
|
|
313
|
+
else if (dataObj.type == 'NexfepMinimizeWindow') {
|
|
314
|
+
window.setMinimized(true);
|
|
315
|
+
}
|
|
316
|
+
else if (dataObj.type == 'NexfepUnMinimizeWindow') {
|
|
317
|
+
window.setMinimized(false);
|
|
318
|
+
}
|
|
319
|
+
else if (dataObj.type == 'NexfepMaximizeWindow') {
|
|
320
|
+
window.setMaximized(true);
|
|
321
|
+
}
|
|
322
|
+
else if (dataObj.type == 'NexfepUnMaximizeWindow') {
|
|
323
|
+
window.setMaximized(false);
|
|
324
|
+
}
|
|
325
|
+
else if (dataObj.type == 'NexfepSetTitle') {
|
|
326
|
+
window.setTitle(dataObj.title);
|
|
327
|
+
}
|
|
328
|
+
else if (dataObj.type == 'NexfepOpenDevTools') {
|
|
329
|
+
webview.openDevtools();
|
|
330
|
+
}
|
|
331
|
+
else if (dataObj.type == 'NexfepCloseDevTools') {
|
|
332
|
+
webview.closeDevtools();
|
|
333
|
+
}
|
|
334
|
+
else if (dataObj.type == 'CustomMessage') {
|
|
335
|
+
this.onCustomMessage(windowObj, dataObj.data);
|
|
343
336
|
}
|
|
344
|
-
else {
|
|
337
|
+
else if (dataObj.type == 'NexfepInvoke') {
|
|
338
|
+
const handlers = this.handlers.get(dataObj.event) || [];
|
|
339
|
+
handlers.forEach(async (handler) => {
|
|
340
|
+
const result = await handler(dataObj.data);
|
|
341
|
+
if (result) {
|
|
342
|
+
webview.evaluateScript(`
|
|
343
|
+
window.dispatchEvent(new CustomEvent('nexfep-invoke-result-${dataObj.eventId[0]}-${dataObj.eventId[1]}', { detail: ${JSON.stringify(result)} }));
|
|
344
|
+
`);
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
webview.evaluateScript(`
|
|
348
|
+
window.dispatchEvent(new CustomEvent('nexfep-invoke-result-${dataObj.eventId[0]}-${dataObj.eventId[1]}', { detail: undefined }));
|
|
349
|
+
`);
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
else if (dataObj.type == 'NexfepSetGlobal') {
|
|
354
|
+
this.global.set(dataObj.name, dataObj.value);
|
|
355
|
+
}
|
|
356
|
+
else if (dataObj.type == 'NexfepGetGlobal') {
|
|
357
|
+
const value = this.global.get(dataObj.name);
|
|
345
358
|
webview.evaluateScript(`
|
|
346
|
-
window.dispatchEvent(new CustomEvent('nexfep-
|
|
359
|
+
window.dispatchEvent(new CustomEvent('nexfep-get-global-result-${dataObj.eventId[0]}-${dataObj.eventId[1]}', { detail: ${JSON.stringify(value)} }));
|
|
347
360
|
`);
|
|
348
361
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
window.dispatchEvent(new CustomEvent('nexfep-get-global-result-${dataObj.eventId[0]}-${dataObj.eventId[1]}', { detail: ${JSON.stringify(value)} }));
|
|
358
|
-
`);
|
|
359
|
-
}
|
|
360
|
-
else if (dataObj.type == 'NexfepBroadcast') {
|
|
361
|
-
this.windows.forEach(async (w) => {
|
|
362
|
-
if (w != windowObj && w.isOpen) {
|
|
363
|
-
w.webview.evaluateScript(`
|
|
364
|
-
window.dispatchEvent(new CustomEvent('${dataObj.name}', { detail: ${JSON.stringify(dataObj.data)} }));
|
|
365
|
-
`);
|
|
362
|
+
else if (dataObj.type == 'NexfepBroadcast') {
|
|
363
|
+
this.windows.forEach(async (w) => {
|
|
364
|
+
if (w != windowObj && w.isOpen) {
|
|
365
|
+
w.webview.evaluateScript(`
|
|
366
|
+
window.dispatchEvent(new CustomEvent('${dataObj.name}', { detail: ${JSON.stringify(dataObj.data)} }));
|
|
367
|
+
`);
|
|
368
|
+
}
|
|
369
|
+
});
|
|
366
370
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
371
|
+
else if (dataObj.type == 'NexfepTell') {
|
|
372
|
+
this.windows.forEach(async (w) => {
|
|
373
|
+
if (w.id == dataObj.to) {
|
|
374
|
+
w.webview.evaluateScript(`
|
|
375
|
+
window.dispatchEvent(new CustomEvent('${dataObj.message}', { detail: ${JSON.stringify(dataObj.data)} }));
|
|
376
|
+
`);
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
else if (dataObj.type == 'NexfepConsoleLog') {
|
|
381
|
+
this.logger.__printLog(windowObj.id, 'Log', dataObj.message);
|
|
382
|
+
}
|
|
383
|
+
else if (dataObj.type == 'NexfepConsoleError') {
|
|
384
|
+
this.logger.__printLog(windowObj.id, 'Error', dataObj.message, '\x1b[31m', '\x1b[0m');
|
|
385
|
+
}
|
|
386
|
+
else if (dataObj.type == 'NexfepConsoleInfo') {
|
|
387
|
+
this.logger.__printLog(windowObj.id, 'Info', dataObj.message, '\x1b[34m', '\x1b[0m');
|
|
388
|
+
}
|
|
389
|
+
else if (dataObj.type == 'NexfepConsoleWarn') {
|
|
390
|
+
this.logger.__printLog(windowObj.id, 'Warn', dataObj.message, '\x1b[33m', '\x1b[0m');
|
|
391
|
+
}
|
|
392
|
+
else if (dataObj.type == 'NexfepConsoleDebug') {
|
|
393
|
+
this.logger.__printLog(windowObj.id, 'Debug', dataObj.message, '\x1b[90m', '\x1b[0m');
|
|
375
394
|
}
|
|
376
395
|
});
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
this.logger.__printLog(windowObj.id, 'Log', dataObj.message);
|
|
380
|
-
}
|
|
381
|
-
else if (dataObj.type == 'NexfepConsoleError') {
|
|
382
|
-
this.logger.__printLog(windowObj.id, 'Error', dataObj.message, '\x1b[31m', '\x1b[0m');
|
|
383
|
-
}
|
|
384
|
-
else if (dataObj.type == 'NexfepConsoleInfo') {
|
|
385
|
-
this.logger.__printLog(windowObj.id, 'Info', dataObj.message, '\x1b[34m', '\x1b[0m');
|
|
386
|
-
}
|
|
387
|
-
else if (dataObj.type == 'NexfepConsoleWarn') {
|
|
388
|
-
this.logger.__printLog(windowObj.id, 'Warn', dataObj.message, '\x1b[33m', '\x1b[0m');
|
|
389
|
-
}
|
|
390
|
-
else if (dataObj.type == 'NexfepConsoleDebug') {
|
|
391
|
-
this.logger.__printLog(windowObj.id, 'Debug', dataObj.message, '\x1b[90m', '\x1b[0m');
|
|
392
|
-
}
|
|
396
|
+
resolve(windowObj);
|
|
397
|
+
});
|
|
393
398
|
});
|
|
394
|
-
return windowObj;
|
|
395
399
|
}
|
|
396
400
|
async createWindow(isShow = true, isDecorated = true) {
|
|
397
401
|
const window = this.windows.find(w => w.isOpen === false) || await this.__createNewWindowObj();
|
|
@@ -405,7 +409,7 @@ class WindowPool {
|
|
|
405
409
|
}
|
|
406
410
|
}
|
|
407
411
|
if (this.freeWindowCount == 0) {
|
|
408
|
-
|
|
412
|
+
this.__createNewWindowObj();
|
|
409
413
|
}
|
|
410
414
|
return window;
|
|
411
415
|
}
|