@lvce-editor/main-process 6.37.0 → 6.37.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/dist/mainProcessMain.js +60 -8
- package/package.json +1 -1
package/dist/mainProcessMain.js
CHANGED
|
@@ -6459,6 +6459,7 @@ const ElectronBrowserViewEventListenerLogin = {
|
|
|
6459
6459
|
key: key$4
|
|
6460
6460
|
};
|
|
6461
6461
|
|
|
6462
|
+
const maxFaviconBytes = 1024 * 1024;
|
|
6462
6463
|
const key$3 = PageFaviconUpdated;
|
|
6463
6464
|
const attach$5 = (webContents, listener) => {
|
|
6464
6465
|
webContents.on(PageFaviconUpdated, listener);
|
|
@@ -6466,9 +6467,47 @@ const attach$5 = (webContents, listener) => {
|
|
|
6466
6467
|
const detach$3 = (webContents, listener) => {
|
|
6467
6468
|
webContents.off(PageFaviconUpdated, listener);
|
|
6468
6469
|
};
|
|
6469
|
-
const
|
|
6470
|
+
const getFaviconDataUrl = async (event, favicon) => {
|
|
6471
|
+
if (favicon.startsWith('data:')) {
|
|
6472
|
+
return favicon;
|
|
6473
|
+
}
|
|
6474
|
+
try {
|
|
6475
|
+
const response = await event.sender.session.fetch(favicon);
|
|
6476
|
+
if (!response.ok) {
|
|
6477
|
+
return '';
|
|
6478
|
+
}
|
|
6479
|
+
const contentLength = Number(response.headers.get('content-length'));
|
|
6480
|
+
if (contentLength > maxFaviconBytes) {
|
|
6481
|
+
return '';
|
|
6482
|
+
}
|
|
6483
|
+
const bytes = Buffer.from(await response.arrayBuffer());
|
|
6484
|
+
if (bytes.byteLength > maxFaviconBytes) {
|
|
6485
|
+
return '';
|
|
6486
|
+
}
|
|
6487
|
+
const contentType = response.headers.get('content-type') || 'image/x-icon';
|
|
6488
|
+
const mimeType = contentType.split(';', 1)[0].trim();
|
|
6489
|
+
if (!mimeType.startsWith('image/') && mimeType !== 'application/octet-stream') {
|
|
6490
|
+
return '';
|
|
6491
|
+
}
|
|
6492
|
+
return `data:${mimeType};base64,${bytes.toString('base64')}`;
|
|
6493
|
+
} catch {
|
|
6494
|
+
return '';
|
|
6495
|
+
}
|
|
6496
|
+
};
|
|
6497
|
+
const resolveFavicon = async (event, favicons) => {
|
|
6498
|
+
for (const favicon of favicons) {
|
|
6499
|
+
const dataUrl = await getFaviconDataUrl(event, favicon);
|
|
6500
|
+
if (dataUrl) {
|
|
6501
|
+
return [dataUrl];
|
|
6502
|
+
}
|
|
6503
|
+
}
|
|
6504
|
+
return favicons;
|
|
6505
|
+
};
|
|
6506
|
+
const handler$3 = async (event, favicons) => {
|
|
6507
|
+
const pageUrl = event.sender.getURL();
|
|
6508
|
+
const resolvedFavicons = await resolveFavicon(event, favicons);
|
|
6470
6509
|
return {
|
|
6471
|
-
messages: [['handlePageFaviconUpdated',
|
|
6510
|
+
messages: event.sender.getURL() === pageUrl ? [['handlePageFaviconUpdated', resolvedFavicons]] : [],
|
|
6472
6511
|
result: undefined
|
|
6473
6512
|
};
|
|
6474
6513
|
};
|
|
@@ -6786,18 +6825,31 @@ const attachEventListenersToWebContents = (webContentsId, webContents, browserWi
|
|
|
6786
6825
|
attach(webContents);
|
|
6787
6826
|
const values = Object.values(ElectronBrowserViewEventListeners);
|
|
6788
6827
|
for (const value of values) {
|
|
6789
|
-
const
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
result
|
|
6794
|
-
} = value.handler(...args, webContentsId);
|
|
6828
|
+
const handleResult = ({
|
|
6829
|
+
messages,
|
|
6830
|
+
result
|
|
6831
|
+
}) => {
|
|
6795
6832
|
for (const message of messages) {
|
|
6796
6833
|
const [key, ...rest] = message;
|
|
6797
6834
|
send(`ElectronWebContents.${key}`, webContentsId, ...rest);
|
|
6798
6835
|
}
|
|
6799
6836
|
return result;
|
|
6800
6837
|
};
|
|
6838
|
+
const handleAsyncResult = async handlerResult => {
|
|
6839
|
+
try {
|
|
6840
|
+
return handleResult(await handlerResult);
|
|
6841
|
+
} catch (error) {
|
|
6842
|
+
console.error(error);
|
|
6843
|
+
}
|
|
6844
|
+
};
|
|
6845
|
+
const wrappedListener = (...args) => {
|
|
6846
|
+
// @ts-ignore
|
|
6847
|
+
const handlerResult = value.handler(...args, webContentsId);
|
|
6848
|
+
if (handlerResult instanceof Promise) {
|
|
6849
|
+
return handleAsyncResult(handlerResult);
|
|
6850
|
+
}
|
|
6851
|
+
return handleResult(handlerResult);
|
|
6852
|
+
};
|
|
6801
6853
|
value.attach(webContents, wrappedListener);
|
|
6802
6854
|
}
|
|
6803
6855
|
webContentsWithEventListeners.add(webContents);
|