@lvce-editor/main-process 5.1.0 → 6.0.0
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 +2321 -1886
- package/package.json +2 -2
package/dist/mainProcessMain.js
CHANGED
|
@@ -1063,54 +1063,54 @@ var hasRequiredLib$1;
|
|
|
1063
1063
|
function requireLib$1 () {
|
|
1064
1064
|
if (hasRequiredLib$1) return lib;
|
|
1065
1065
|
hasRequiredLib$1 = 1;
|
|
1066
|
-
(function (exports
|
|
1066
|
+
(function (exports) {
|
|
1067
1067
|
|
|
1068
|
-
Object.defineProperty(exports
|
|
1068
|
+
Object.defineProperty(exports, "__esModule", {
|
|
1069
1069
|
value: true
|
|
1070
1070
|
});
|
|
1071
|
-
Object.defineProperty(exports
|
|
1071
|
+
Object.defineProperty(exports, "isIdentifierChar", {
|
|
1072
1072
|
enumerable: true,
|
|
1073
1073
|
get: function () {
|
|
1074
1074
|
return _identifier.isIdentifierChar;
|
|
1075
1075
|
}
|
|
1076
1076
|
});
|
|
1077
|
-
Object.defineProperty(exports
|
|
1077
|
+
Object.defineProperty(exports, "isIdentifierName", {
|
|
1078
1078
|
enumerable: true,
|
|
1079
1079
|
get: function () {
|
|
1080
1080
|
return _identifier.isIdentifierName;
|
|
1081
1081
|
}
|
|
1082
1082
|
});
|
|
1083
|
-
Object.defineProperty(exports
|
|
1083
|
+
Object.defineProperty(exports, "isIdentifierStart", {
|
|
1084
1084
|
enumerable: true,
|
|
1085
1085
|
get: function () {
|
|
1086
1086
|
return _identifier.isIdentifierStart;
|
|
1087
1087
|
}
|
|
1088
1088
|
});
|
|
1089
|
-
Object.defineProperty(exports
|
|
1089
|
+
Object.defineProperty(exports, "isKeyword", {
|
|
1090
1090
|
enumerable: true,
|
|
1091
1091
|
get: function () {
|
|
1092
1092
|
return _keyword.isKeyword;
|
|
1093
1093
|
}
|
|
1094
1094
|
});
|
|
1095
|
-
Object.defineProperty(exports
|
|
1095
|
+
Object.defineProperty(exports, "isReservedWord", {
|
|
1096
1096
|
enumerable: true,
|
|
1097
1097
|
get: function () {
|
|
1098
1098
|
return _keyword.isReservedWord;
|
|
1099
1099
|
}
|
|
1100
1100
|
});
|
|
1101
|
-
Object.defineProperty(exports
|
|
1101
|
+
Object.defineProperty(exports, "isStrictBindOnlyReservedWord", {
|
|
1102
1102
|
enumerable: true,
|
|
1103
1103
|
get: function () {
|
|
1104
1104
|
return _keyword.isStrictBindOnlyReservedWord;
|
|
1105
1105
|
}
|
|
1106
1106
|
});
|
|
1107
|
-
Object.defineProperty(exports
|
|
1107
|
+
Object.defineProperty(exports, "isStrictBindReservedWord", {
|
|
1108
1108
|
enumerable: true,
|
|
1109
1109
|
get: function () {
|
|
1110
1110
|
return _keyword.isStrictBindReservedWord;
|
|
1111
1111
|
}
|
|
1112
1112
|
});
|
|
1113
|
-
Object.defineProperty(exports
|
|
1113
|
+
Object.defineProperty(exports, "isStrictReservedWord", {
|
|
1114
1114
|
enumerable: true,
|
|
1115
1115
|
get: function () {
|
|
1116
1116
|
return _keyword.isStrictReservedWord;
|
|
@@ -1343,12 +1343,12 @@ function requireLib () {
|
|
|
1343
1343
|
|
|
1344
1344
|
var libExports = requireLib();
|
|
1345
1345
|
|
|
1346
|
-
const NewLine$
|
|
1347
|
-
const splitLines$
|
|
1348
|
-
return lines.split(NewLine$
|
|
1346
|
+
const NewLine$4 = '\n';
|
|
1347
|
+
const splitLines$3 = lines => {
|
|
1348
|
+
return lines.split(NewLine$4);
|
|
1349
1349
|
};
|
|
1350
|
-
const RE_AT$
|
|
1351
|
-
const RE_AT_PROMISE_INDEX$
|
|
1350
|
+
const RE_AT$2 = /^\s+at/;
|
|
1351
|
+
const RE_AT_PROMISE_INDEX$2 = /^\s*at async Promise.all \(index \d+\)$/;
|
|
1352
1352
|
const RE_OBJECT_AS = /^\s*at (async )?Object\.\w+ \[as ([\w\.]+)\]/;
|
|
1353
1353
|
const RE_GET_RESPONSE = /^\s*at async getResponse/;
|
|
1354
1354
|
const RE_WEBSOCKET_HANDLE_MESSAGE = /^\s*at async WebSocket.handleMessage/;
|
|
@@ -1356,7 +1356,7 @@ const RE_EXECUTE_COMMAND_ASYNC = /^\s*at executeCommandAsync/;
|
|
|
1356
1356
|
const RE_HANDLE_OTHER_MESSAGES_FROM_MESSAGE_PORT = /^\s*at async MessagePort\.handleOtherMessagesFromMessagePort/;
|
|
1357
1357
|
const RE_ASSERT = /^\s*at .*\/Assert\.js/;
|
|
1358
1358
|
const isInternalLine = line => {
|
|
1359
|
-
return line.includes('node:') || RE_AT_PROMISE_INDEX$
|
|
1359
|
+
return line.includes('node:') || RE_AT_PROMISE_INDEX$2.test(line) || line.includes('node_modules/ws');
|
|
1360
1360
|
};
|
|
1361
1361
|
const isRelevantLine = line => {
|
|
1362
1362
|
return !isInternalLine(line);
|
|
@@ -1382,8 +1382,8 @@ const isApplicationUsefulLine = (line, index) => {
|
|
|
1382
1382
|
}
|
|
1383
1383
|
return true;
|
|
1384
1384
|
};
|
|
1385
|
-
const isNormalStackLine$
|
|
1386
|
-
return RE_AT$
|
|
1385
|
+
const isNormalStackLine$2 = line => {
|
|
1386
|
+
return RE_AT$2.test(line) && !RE_AT_PROMISE_INDEX$2.test(line);
|
|
1387
1387
|
};
|
|
1388
1388
|
const cleanLine = line => {
|
|
1389
1389
|
if (line.startsWith(' at exports.')) {
|
|
@@ -1408,8 +1408,8 @@ const cleanLine = line => {
|
|
|
1408
1408
|
}
|
|
1409
1409
|
return line;
|
|
1410
1410
|
};
|
|
1411
|
-
const getDetails$
|
|
1412
|
-
const index = lines.findIndex(isNormalStackLine$
|
|
1411
|
+
const getDetails$2 = lines => {
|
|
1412
|
+
const index = lines.findIndex(isNormalStackLine$2);
|
|
1413
1413
|
return {
|
|
1414
1414
|
custom: lines.slice(0, index),
|
|
1415
1415
|
actualStack: lines.slice(index).map(cleanLine)
|
|
@@ -1427,25 +1427,25 @@ const mergeCustom = (custom, relevantStack) => {
|
|
|
1427
1427
|
return relevantStack;
|
|
1428
1428
|
};
|
|
1429
1429
|
const cleanStack = stack => {
|
|
1430
|
-
const lines = splitLines$
|
|
1430
|
+
const lines = splitLines$3(stack);
|
|
1431
1431
|
const {
|
|
1432
1432
|
custom,
|
|
1433
1433
|
actualStack
|
|
1434
|
-
} = getDetails$
|
|
1434
|
+
} = getDetails$2(lines);
|
|
1435
1435
|
const relevantStack = actualStack.filter(isRelevantLine).filter(isApplicationUsefulLine);
|
|
1436
1436
|
const merged = mergeCustom(custom, relevantStack);
|
|
1437
1437
|
return merged;
|
|
1438
1438
|
};
|
|
1439
1439
|
const Utf8 = 'utf8';
|
|
1440
|
-
const ERR_MODULE_NOT_FOUND$
|
|
1440
|
+
const ERR_MODULE_NOT_FOUND$2 = 'ERR_MODULE_NOT_FOUND';
|
|
1441
1441
|
const getActualPath$1 = fileUri => {
|
|
1442
1442
|
if (fileUri.startsWith('file://')) {
|
|
1443
1443
|
return fileURLToPath(fileUri);
|
|
1444
1444
|
}
|
|
1445
1445
|
return fileUri;
|
|
1446
1446
|
};
|
|
1447
|
-
const joinLines$
|
|
1448
|
-
return lines.join(NewLine$
|
|
1447
|
+
const joinLines$3 = lines => {
|
|
1448
|
+
return lines.join(NewLine$4);
|
|
1449
1449
|
};
|
|
1450
1450
|
const warn$1 = (...args) => {
|
|
1451
1451
|
console.warn(...args);
|
|
@@ -1468,7 +1468,7 @@ const prepareModuleNotFoundError = error => {
|
|
|
1468
1468
|
const rawLines = readFileSync(importedFrom, Utf8);
|
|
1469
1469
|
let line = 0;
|
|
1470
1470
|
let column = 0;
|
|
1471
|
-
const splittedLines = splitLines$
|
|
1471
|
+
const splittedLines = splitLines$3(rawLines);
|
|
1472
1472
|
for (let i = 0; i < splittedLines.length; i++) {
|
|
1473
1473
|
const splittedLine = splittedLines[i];
|
|
1474
1474
|
const index = splittedLine.indexOf(notFoundModule);
|
|
@@ -1485,9 +1485,9 @@ const prepareModuleNotFoundError = error => {
|
|
|
1485
1485
|
}
|
|
1486
1486
|
};
|
|
1487
1487
|
const codeFrame = libExports.codeFrameColumns(rawLines, location);
|
|
1488
|
-
const stackLines = splitLines$
|
|
1488
|
+
const stackLines = splitLines$3(error.stack);
|
|
1489
1489
|
const newStackLines = [stackLines[0], ` at ${importedFrom}:${line}:${column}`, ...stackLines.slice(1)];
|
|
1490
|
-
const newStack = joinLines$
|
|
1490
|
+
const newStack = joinLines$3(newStackLines);
|
|
1491
1491
|
return {
|
|
1492
1492
|
message,
|
|
1493
1493
|
stack: newStack,
|
|
@@ -1496,7 +1496,7 @@ const prepareModuleNotFoundError = error => {
|
|
|
1496
1496
|
};
|
|
1497
1497
|
const prepare = error => {
|
|
1498
1498
|
try {
|
|
1499
|
-
if (error && error.code === ERR_MODULE_NOT_FOUND$
|
|
1499
|
+
if (error && error.code === ERR_MODULE_NOT_FOUND$2) {
|
|
1500
1500
|
return prepareModuleNotFoundError(error);
|
|
1501
1501
|
}
|
|
1502
1502
|
const {
|
|
@@ -1531,7 +1531,7 @@ const prepare = error => {
|
|
|
1531
1531
|
codeFrame = libExports.codeFrameColumns(rawLines, location);
|
|
1532
1532
|
}
|
|
1533
1533
|
}
|
|
1534
|
-
const relevantStack = joinLines$
|
|
1534
|
+
const relevantStack = joinLines$3(lines);
|
|
1535
1535
|
return {
|
|
1536
1536
|
message,
|
|
1537
1537
|
stack: relevantStack,
|
|
@@ -1708,9 +1708,9 @@ const getCombinedMessage = (error, message) => {
|
|
|
1708
1708
|
}
|
|
1709
1709
|
return stringifiedError;
|
|
1710
1710
|
};
|
|
1711
|
-
const NewLine$
|
|
1711
|
+
const NewLine$3 = '\n';
|
|
1712
1712
|
const getNewLineIndex$1 = (string, startIndex = undefined) => {
|
|
1713
|
-
return string.indexOf(NewLine$
|
|
1713
|
+
return string.indexOf(NewLine$3, startIndex);
|
|
1714
1714
|
};
|
|
1715
1715
|
const mergeStacks = (parent, child) => {
|
|
1716
1716
|
if (!child) {
|
|
@@ -1748,31 +1748,31 @@ class VError extends Error {
|
|
|
1748
1748
|
}
|
|
1749
1749
|
}
|
|
1750
1750
|
|
|
1751
|
-
const isMessagePort = value => {
|
|
1751
|
+
const isMessagePort$1 = value => {
|
|
1752
1752
|
return value && value instanceof MessagePort;
|
|
1753
1753
|
};
|
|
1754
|
-
const isMessagePortMain = value => {
|
|
1754
|
+
const isMessagePortMain$1 = value => {
|
|
1755
1755
|
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
1756
1756
|
};
|
|
1757
|
-
const isOffscreenCanvas = value => {
|
|
1757
|
+
const isOffscreenCanvas$1 = value => {
|
|
1758
1758
|
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
1759
1759
|
};
|
|
1760
|
-
const isInstanceOf = (value, constructorName) => {
|
|
1760
|
+
const isInstanceOf$1 = (value, constructorName) => {
|
|
1761
1761
|
return value?.constructor?.name === constructorName;
|
|
1762
1762
|
};
|
|
1763
|
-
const isSocket = value => {
|
|
1764
|
-
return isInstanceOf(value, 'Socket');
|
|
1763
|
+
const isSocket$1 = value => {
|
|
1764
|
+
return isInstanceOf$1(value, 'Socket');
|
|
1765
1765
|
};
|
|
1766
|
-
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
1767
|
-
const isTransferrable = value => {
|
|
1768
|
-
for (const fn of transferrables) {
|
|
1766
|
+
const transferrables$1 = [isMessagePort$1, isMessagePortMain$1, isOffscreenCanvas$1, isSocket$1];
|
|
1767
|
+
const isTransferrable$1 = value => {
|
|
1768
|
+
for (const fn of transferrables$1) {
|
|
1769
1769
|
if (fn(value)) {
|
|
1770
1770
|
return true;
|
|
1771
1771
|
}
|
|
1772
1772
|
}
|
|
1773
1773
|
return false;
|
|
1774
1774
|
};
|
|
1775
|
-
const walkValue = (value, transferrables, isTransferrable) => {
|
|
1775
|
+
const walkValue$1 = (value, transferrables, isTransferrable) => {
|
|
1776
1776
|
if (!value) {
|
|
1777
1777
|
return;
|
|
1778
1778
|
}
|
|
@@ -1782,23 +1782,23 @@ const walkValue = (value, transferrables, isTransferrable) => {
|
|
|
1782
1782
|
}
|
|
1783
1783
|
if (Array.isArray(value)) {
|
|
1784
1784
|
for (const item of value) {
|
|
1785
|
-
walkValue(item, transferrables, isTransferrable);
|
|
1785
|
+
walkValue$1(item, transferrables, isTransferrable);
|
|
1786
1786
|
}
|
|
1787
1787
|
return;
|
|
1788
1788
|
}
|
|
1789
1789
|
if (typeof value === 'object') {
|
|
1790
1790
|
for (const property of Object.values(value)) {
|
|
1791
|
-
walkValue(property, transferrables, isTransferrable);
|
|
1791
|
+
walkValue$1(property, transferrables, isTransferrable);
|
|
1792
1792
|
}
|
|
1793
1793
|
return;
|
|
1794
1794
|
}
|
|
1795
1795
|
};
|
|
1796
|
-
const getTransferrables = value => {
|
|
1796
|
+
const getTransferrables$1 = value => {
|
|
1797
1797
|
const transferrables = [];
|
|
1798
|
-
walkValue(value, transferrables, isTransferrable);
|
|
1798
|
+
walkValue$1(value, transferrables, isTransferrable$1);
|
|
1799
1799
|
return transferrables;
|
|
1800
1800
|
};
|
|
1801
|
-
const removeValues = (value, toRemove) => {
|
|
1801
|
+
const removeValues$1 = (value, toRemove) => {
|
|
1802
1802
|
if (!value) {
|
|
1803
1803
|
return value;
|
|
1804
1804
|
}
|
|
@@ -1806,7 +1806,7 @@ const removeValues = (value, toRemove) => {
|
|
|
1806
1806
|
const newItems = [];
|
|
1807
1807
|
for (const item of value) {
|
|
1808
1808
|
if (!toRemove.includes(item)) {
|
|
1809
|
-
newItems.push(removeValues(item, toRemove));
|
|
1809
|
+
newItems.push(removeValues$1(item, toRemove));
|
|
1810
1810
|
}
|
|
1811
1811
|
}
|
|
1812
1812
|
return newItems;
|
|
@@ -1815,7 +1815,7 @@ const removeValues = (value, toRemove) => {
|
|
|
1815
1815
|
const newObject = Object.create(null);
|
|
1816
1816
|
for (const [key, property] of Object.entries(value)) {
|
|
1817
1817
|
if (!toRemove.includes(property)) {
|
|
1818
|
-
newObject[key] = removeValues(property, toRemove);
|
|
1818
|
+
newObject[key] = removeValues$1(property, toRemove);
|
|
1819
1819
|
}
|
|
1820
1820
|
}
|
|
1821
1821
|
return newObject;
|
|
@@ -1826,15 +1826,15 @@ const removeValues = (value, toRemove) => {
|
|
|
1826
1826
|
// workaround for electron not supporting transferrable objects
|
|
1827
1827
|
// as parameters. If the transferrable object is a parameter, in electron
|
|
1828
1828
|
// only an empty objected is received in the main process
|
|
1829
|
-
const fixElectronParameters = value => {
|
|
1830
|
-
const transfer = getTransferrables(value);
|
|
1831
|
-
const newValue = removeValues(value, transfer);
|
|
1829
|
+
const fixElectronParameters$1 = value => {
|
|
1830
|
+
const transfer = getTransferrables$1(value);
|
|
1831
|
+
const newValue = removeValues$1(value, transfer);
|
|
1832
1832
|
return {
|
|
1833
1833
|
newValue,
|
|
1834
1834
|
transfer
|
|
1835
1835
|
};
|
|
1836
1836
|
};
|
|
1837
|
-
const getActualDataElectron = event => {
|
|
1837
|
+
const getActualDataElectron$1 = event => {
|
|
1838
1838
|
const {
|
|
1839
1839
|
data,
|
|
1840
1840
|
ports
|
|
@@ -1847,7 +1847,7 @@ const getActualDataElectron = event => {
|
|
|
1847
1847
|
params: [...ports, ...data.params]
|
|
1848
1848
|
};
|
|
1849
1849
|
};
|
|
1850
|
-
const attachEvents = that => {
|
|
1850
|
+
const attachEvents$1 = that => {
|
|
1851
1851
|
const handleMessage = (...args) => {
|
|
1852
1852
|
const data = that.getData(...args);
|
|
1853
1853
|
that.dispatchEvent(new MessageEvent('message', {
|
|
@@ -1860,36 +1860,36 @@ const attachEvents = that => {
|
|
|
1860
1860
|
};
|
|
1861
1861
|
that.onClose(handleClose);
|
|
1862
1862
|
};
|
|
1863
|
-
class Ipc extends EventTarget {
|
|
1863
|
+
let Ipc$1 = class Ipc extends EventTarget {
|
|
1864
1864
|
constructor(rawIpc) {
|
|
1865
1865
|
super();
|
|
1866
1866
|
this._rawIpc = rawIpc;
|
|
1867
|
-
attachEvents(this);
|
|
1867
|
+
attachEvents$1(this);
|
|
1868
1868
|
}
|
|
1869
|
-
}
|
|
1870
|
-
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
1871
|
-
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
1872
|
-
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
1873
|
-
const NewLine$1 = '\n';
|
|
1874
|
-
const joinLines$1 = lines => {
|
|
1875
|
-
return lines.join(NewLine$1);
|
|
1876
1869
|
};
|
|
1877
|
-
const
|
|
1878
|
-
const
|
|
1879
|
-
const
|
|
1880
|
-
|
|
1870
|
+
const E_INCOMPATIBLE_NATIVE_MODULE$1 = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
1871
|
+
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON$1 = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
1872
|
+
const ERR_MODULE_NOT_FOUND$1 = 'ERR_MODULE_NOT_FOUND';
|
|
1873
|
+
const NewLine$2 = '\n';
|
|
1874
|
+
const joinLines$2 = lines => {
|
|
1875
|
+
return lines.join(NewLine$2);
|
|
1881
1876
|
};
|
|
1882
|
-
const
|
|
1883
|
-
|
|
1877
|
+
const RE_AT$1 = /^\s+at/;
|
|
1878
|
+
const RE_AT_PROMISE_INDEX$1 = /^\s*at async Promise.all \(index \d+\)$/;
|
|
1879
|
+
const isNormalStackLine$1 = line => {
|
|
1880
|
+
return RE_AT$1.test(line) && !RE_AT_PROMISE_INDEX$1.test(line);
|
|
1881
|
+
};
|
|
1882
|
+
const getDetails$1 = lines => {
|
|
1883
|
+
const index = lines.findIndex(isNormalStackLine$1);
|
|
1884
1884
|
if (index === -1) {
|
|
1885
1885
|
return {
|
|
1886
|
-
actualMessage: joinLines$
|
|
1886
|
+
actualMessage: joinLines$2(lines),
|
|
1887
1887
|
rest: []
|
|
1888
1888
|
};
|
|
1889
1889
|
}
|
|
1890
1890
|
let lastIndex = index - 1;
|
|
1891
1891
|
while (++lastIndex < lines.length) {
|
|
1892
|
-
if (!isNormalStackLine(lines[lastIndex])) {
|
|
1892
|
+
if (!isNormalStackLine$1(lines[lastIndex])) {
|
|
1893
1893
|
break;
|
|
1894
1894
|
}
|
|
1895
1895
|
}
|
|
@@ -1898,89 +1898,89 @@ const getDetails = lines => {
|
|
|
1898
1898
|
rest: lines.slice(index, lastIndex)
|
|
1899
1899
|
};
|
|
1900
1900
|
};
|
|
1901
|
-
const splitLines$
|
|
1902
|
-
return lines.split(NewLine$
|
|
1901
|
+
const splitLines$2 = lines => {
|
|
1902
|
+
return lines.split(NewLine$2);
|
|
1903
1903
|
};
|
|
1904
|
-
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
|
|
1905
|
-
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
|
|
1906
|
-
const isMessageCodeBlockStartIndex = line => {
|
|
1907
|
-
return RE_MESSAGE_CODE_BLOCK_START.test(line);
|
|
1904
|
+
const RE_MESSAGE_CODE_BLOCK_START$1 = /^Error: The module '.*'$/;
|
|
1905
|
+
const RE_MESSAGE_CODE_BLOCK_END$1 = /^\s* at/;
|
|
1906
|
+
const isMessageCodeBlockStartIndex$1 = line => {
|
|
1907
|
+
return RE_MESSAGE_CODE_BLOCK_START$1.test(line);
|
|
1908
1908
|
};
|
|
1909
|
-
const isMessageCodeBlockEndIndex = line => {
|
|
1910
|
-
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
1909
|
+
const isMessageCodeBlockEndIndex$1 = line => {
|
|
1910
|
+
return RE_MESSAGE_CODE_BLOCK_END$1.test(line);
|
|
1911
1911
|
};
|
|
1912
|
-
const getMessageCodeBlock = stderr => {
|
|
1913
|
-
const lines = splitLines$
|
|
1914
|
-
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
|
|
1915
|
-
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
1912
|
+
const getMessageCodeBlock$1 = stderr => {
|
|
1913
|
+
const lines = splitLines$2(stderr);
|
|
1914
|
+
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex$1);
|
|
1915
|
+
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex$1, startIndex);
|
|
1916
1916
|
const relevantLines = lines.slice(startIndex, endIndex);
|
|
1917
1917
|
const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
|
|
1918
1918
|
return relevantMessage;
|
|
1919
1919
|
};
|
|
1920
|
-
const isModuleNotFoundMessage = line => {
|
|
1920
|
+
const isModuleNotFoundMessage$1 = line => {
|
|
1921
1921
|
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
1922
1922
|
};
|
|
1923
|
-
const getModuleNotFoundError = stderr => {
|
|
1924
|
-
const lines = splitLines$
|
|
1925
|
-
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
1923
|
+
const getModuleNotFoundError$1 = stderr => {
|
|
1924
|
+
const lines = splitLines$2(stderr);
|
|
1925
|
+
const messageIndex = lines.findIndex(isModuleNotFoundMessage$1);
|
|
1926
1926
|
const message = lines[messageIndex];
|
|
1927
1927
|
return {
|
|
1928
|
-
code: ERR_MODULE_NOT_FOUND,
|
|
1928
|
+
code: ERR_MODULE_NOT_FOUND$1,
|
|
1929
1929
|
message
|
|
1930
1930
|
};
|
|
1931
1931
|
};
|
|
1932
|
-
const isModuleNotFoundError = stderr => {
|
|
1932
|
+
const isModuleNotFoundError$1 = stderr => {
|
|
1933
1933
|
if (!stderr) {
|
|
1934
1934
|
return false;
|
|
1935
1935
|
}
|
|
1936
1936
|
return stderr.includes('ERR_MODULE_NOT_FOUND');
|
|
1937
1937
|
};
|
|
1938
|
-
const isModulesSyntaxError = stderr => {
|
|
1938
|
+
const isModulesSyntaxError$1 = stderr => {
|
|
1939
1939
|
if (!stderr) {
|
|
1940
1940
|
return false;
|
|
1941
1941
|
}
|
|
1942
1942
|
return stderr.includes('SyntaxError: Cannot use import statement outside a module');
|
|
1943
1943
|
};
|
|
1944
|
-
const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
|
|
1945
|
-
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
|
|
1946
|
-
const isUnhelpfulNativeModuleError = stderr => {
|
|
1947
|
-
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
|
1944
|
+
const RE_NATIVE_MODULE_ERROR$1 = /^innerError Error: Cannot find module '.*.node'/;
|
|
1945
|
+
const RE_NATIVE_MODULE_ERROR_2$1 = /was compiled against a different Node.js version/;
|
|
1946
|
+
const isUnhelpfulNativeModuleError$1 = stderr => {
|
|
1947
|
+
return RE_NATIVE_MODULE_ERROR$1.test(stderr) && RE_NATIVE_MODULE_ERROR_2$1.test(stderr);
|
|
1948
1948
|
};
|
|
1949
|
-
const getNativeModuleErrorMessage = stderr => {
|
|
1950
|
-
const message = getMessageCodeBlock(stderr);
|
|
1949
|
+
const getNativeModuleErrorMessage$1 = stderr => {
|
|
1950
|
+
const message = getMessageCodeBlock$1(stderr);
|
|
1951
1951
|
return {
|
|
1952
|
-
code: E_INCOMPATIBLE_NATIVE_MODULE,
|
|
1952
|
+
code: E_INCOMPATIBLE_NATIVE_MODULE$1,
|
|
1953
1953
|
message: `Incompatible native node module: ${message}`
|
|
1954
1954
|
};
|
|
1955
1955
|
};
|
|
1956
|
-
const getModuleSyntaxError = () => {
|
|
1956
|
+
const getModuleSyntaxError$1 = () => {
|
|
1957
1957
|
return {
|
|
1958
|
-
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
|
|
1958
|
+
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON$1,
|
|
1959
1959
|
message: `ES Modules are not supported in electron`
|
|
1960
1960
|
};
|
|
1961
1961
|
};
|
|
1962
|
-
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
1963
|
-
if (isUnhelpfulNativeModuleError(stderr)) {
|
|
1964
|
-
return getNativeModuleErrorMessage(stderr);
|
|
1962
|
+
const getHelpfulChildProcessError$1 = (stdout, stderr) => {
|
|
1963
|
+
if (isUnhelpfulNativeModuleError$1(stderr)) {
|
|
1964
|
+
return getNativeModuleErrorMessage$1(stderr);
|
|
1965
1965
|
}
|
|
1966
|
-
if (isModulesSyntaxError(stderr)) {
|
|
1967
|
-
return getModuleSyntaxError();
|
|
1966
|
+
if (isModulesSyntaxError$1(stderr)) {
|
|
1967
|
+
return getModuleSyntaxError$1();
|
|
1968
1968
|
}
|
|
1969
|
-
if (isModuleNotFoundError(stderr)) {
|
|
1970
|
-
return getModuleNotFoundError(stderr);
|
|
1969
|
+
if (isModuleNotFoundError$1(stderr)) {
|
|
1970
|
+
return getModuleNotFoundError$1(stderr);
|
|
1971
1971
|
}
|
|
1972
|
-
const lines = splitLines$
|
|
1972
|
+
const lines = splitLines$2(stderr);
|
|
1973
1973
|
const {
|
|
1974
1974
|
actualMessage,
|
|
1975
1975
|
rest
|
|
1976
|
-
} = getDetails(lines);
|
|
1976
|
+
} = getDetails$1(lines);
|
|
1977
1977
|
return {
|
|
1978
1978
|
code: '',
|
|
1979
1979
|
message: actualMessage,
|
|
1980
1980
|
stack: rest
|
|
1981
1981
|
};
|
|
1982
1982
|
};
|
|
1983
|
-
class IpcError extends VError {
|
|
1983
|
+
let IpcError$1 = class IpcError extends VError {
|
|
1984
1984
|
// @ts-ignore
|
|
1985
1985
|
constructor(betterMessage, stdout = '', stderr = '') {
|
|
1986
1986
|
if (stdout || stderr) {
|
|
@@ -1989,7 +1989,7 @@ class IpcError extends VError {
|
|
|
1989
1989
|
code,
|
|
1990
1990
|
message,
|
|
1991
1991
|
stack
|
|
1992
|
-
} = getHelpfulChildProcessError(stdout, stderr);
|
|
1992
|
+
} = getHelpfulChildProcessError$1(stdout, stderr);
|
|
1993
1993
|
const cause = new Error(message);
|
|
1994
1994
|
// @ts-ignore
|
|
1995
1995
|
cause.code = code;
|
|
@@ -2005,20 +2005,20 @@ class IpcError extends VError {
|
|
|
2005
2005
|
// @ts-ignore
|
|
2006
2006
|
this.stderr = stderr;
|
|
2007
2007
|
}
|
|
2008
|
-
}
|
|
2009
|
-
const listen$b = ({
|
|
2008
|
+
};
|
|
2009
|
+
const listen$b$1 = ({
|
|
2010
2010
|
messagePort
|
|
2011
2011
|
}) => {
|
|
2012
|
-
if (!isMessagePortMain(messagePort)) {
|
|
2013
|
-
throw new IpcError('port must be of type MessagePortMain');
|
|
2012
|
+
if (!isMessagePortMain$1(messagePort)) {
|
|
2013
|
+
throw new IpcError$1('port must be of type MessagePortMain');
|
|
2014
2014
|
}
|
|
2015
2015
|
return messagePort;
|
|
2016
2016
|
};
|
|
2017
|
-
const signal$c = messagePort => {
|
|
2017
|
+
const signal$c$1 = messagePort => {
|
|
2018
2018
|
messagePort.start();
|
|
2019
2019
|
};
|
|
2020
|
-
class IpcChildWithElectronMessagePort extends Ipc {
|
|
2021
|
-
getData = getActualDataElectron;
|
|
2020
|
+
let IpcChildWithElectronMessagePort$2 = class IpcChildWithElectronMessagePort extends Ipc$1 {
|
|
2021
|
+
getData = getActualDataElectron$1;
|
|
2022
2022
|
send(message) {
|
|
2023
2023
|
this._rawIpc.postMessage(message);
|
|
2024
2024
|
}
|
|
@@ -2026,7 +2026,7 @@ class IpcChildWithElectronMessagePort extends Ipc {
|
|
|
2026
2026
|
const {
|
|
2027
2027
|
newValue,
|
|
2028
2028
|
transfer
|
|
2029
|
-
} = fixElectronParameters(message);
|
|
2029
|
+
} = fixElectronParameters$1(message);
|
|
2030
2030
|
this._rawIpc.postMessage(newValue, transfer);
|
|
2031
2031
|
}
|
|
2032
2032
|
dispose() {
|
|
@@ -2038,48 +2038,161 @@ class IpcChildWithElectronMessagePort extends Ipc {
|
|
|
2038
2038
|
onClose(callback) {
|
|
2039
2039
|
this._rawIpc.on('close', callback);
|
|
2040
2040
|
}
|
|
2041
|
-
}
|
|
2042
|
-
const wrap$j = messagePort => {
|
|
2043
|
-
return new IpcChildWithElectronMessagePort(messagePort);
|
|
2044
2041
|
};
|
|
2045
|
-
const
|
|
2042
|
+
const wrap$j$1 = messagePort => {
|
|
2043
|
+
return new IpcChildWithElectronMessagePort$2(messagePort);
|
|
2044
|
+
};
|
|
2045
|
+
const IpcChildWithElectronMessagePort$1$1 = {
|
|
2046
2046
|
__proto__: null,
|
|
2047
|
-
listen: listen$b,
|
|
2048
|
-
signal: signal$c,
|
|
2049
|
-
wrap: wrap$j
|
|
2047
|
+
listen: listen$b$1,
|
|
2048
|
+
signal: signal$c$1,
|
|
2049
|
+
wrap: wrap$j$1
|
|
2050
2050
|
};
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2051
|
+
const preloadChannelType$1 = 'port';
|
|
2052
|
+
const listen$2$1 = ({
|
|
2053
|
+
webContents
|
|
2054
|
+
}) => {
|
|
2055
|
+
return webContents;
|
|
2056
|
+
};
|
|
2057
|
+
const getData$1$1 = (event, message) => {
|
|
2054
2058
|
const {
|
|
2055
|
-
|
|
2056
|
-
|
|
2059
|
+
ports,
|
|
2060
|
+
sender
|
|
2057
2061
|
} = event;
|
|
2058
|
-
|
|
2059
|
-
|
|
2062
|
+
const data = {
|
|
2063
|
+
...message,
|
|
2064
|
+
params: [...message.params, ...ports, sender.id]
|
|
2065
|
+
};
|
|
2066
|
+
return data;
|
|
2067
|
+
};
|
|
2068
|
+
let IpcChildWithRendererProcess2$2 = class IpcChildWithRendererProcess2 extends Ipc$1 {
|
|
2069
|
+
getData(event, message) {
|
|
2070
|
+
return getData$1$1(event, message);
|
|
2071
|
+
}
|
|
2072
|
+
send(message) {
|
|
2073
|
+
this._rawIpc.postMessage(preloadChannelType$1, message);
|
|
2074
|
+
}
|
|
2075
|
+
sendAndTransfer(message) {
|
|
2076
|
+
const transfer = getTransferrables$1(message);
|
|
2077
|
+
this._rawIpc.postMessage(preloadChannelType$1, message, transfer);
|
|
2078
|
+
}
|
|
2079
|
+
dispose() {
|
|
2080
|
+
// ignore
|
|
2081
|
+
}
|
|
2082
|
+
onMessage(callback) {
|
|
2083
|
+
this._rawIpc.ipc.on(preloadChannelType$1, callback);
|
|
2084
|
+
}
|
|
2085
|
+
onClose(callback) {
|
|
2086
|
+
this._rawIpc.on('destroyed', callback);
|
|
2060
2087
|
}
|
|
2088
|
+
};
|
|
2089
|
+
const wrap$a$1 = webContents => {
|
|
2090
|
+
return new IpcChildWithRendererProcess2$2(webContents);
|
|
2091
|
+
};
|
|
2092
|
+
const IpcChildWithRendererProcess2$1$1 = {
|
|
2093
|
+
__proto__: null,
|
|
2094
|
+
listen: listen$2$1,
|
|
2095
|
+
wrap: wrap$a$1
|
|
2096
|
+
};
|
|
2097
|
+
const Exit$1 = 1;
|
|
2098
|
+
const Message$1$1 = 3;
|
|
2099
|
+
const getFirstUtilityProcessEvent$1 = async utilityProcess => {
|
|
2100
|
+
const {
|
|
2101
|
+
promise,
|
|
2102
|
+
resolve
|
|
2103
|
+
} = Promise.withResolvers();
|
|
2104
|
+
let stdout = '';
|
|
2105
|
+
let stderr = '';
|
|
2106
|
+
const cleanup = value => {
|
|
2107
|
+
// @ts-ignore
|
|
2108
|
+
utilityProcess.stderr.off('data', handleStdErrData);
|
|
2109
|
+
// @ts-ignore
|
|
2110
|
+
utilityProcess.stdout.off('data', handleStdoutData);
|
|
2111
|
+
utilityProcess.off('message', handleMessage);
|
|
2112
|
+
utilityProcess.off('exit', handleExit);
|
|
2113
|
+
resolve(value);
|
|
2114
|
+
};
|
|
2115
|
+
const handleStdErrData = data => {
|
|
2116
|
+
stderr += data;
|
|
2117
|
+
};
|
|
2118
|
+
const handleStdoutData = data => {
|
|
2119
|
+
stdout += data;
|
|
2120
|
+
};
|
|
2121
|
+
const handleMessage = event => {
|
|
2122
|
+
cleanup({
|
|
2123
|
+
event,
|
|
2124
|
+
stderr,
|
|
2125
|
+
stdout,
|
|
2126
|
+
type: Message$1$1
|
|
2127
|
+
});
|
|
2128
|
+
};
|
|
2129
|
+
const handleExit = event => {
|
|
2130
|
+
cleanup({
|
|
2131
|
+
event,
|
|
2132
|
+
stderr,
|
|
2133
|
+
stdout,
|
|
2134
|
+
type: Exit$1
|
|
2135
|
+
});
|
|
2136
|
+
};
|
|
2137
|
+
// @ts-ignore
|
|
2138
|
+
utilityProcess.stderr.on('data', handleStdErrData);
|
|
2139
|
+
// @ts-ignore
|
|
2140
|
+
utilityProcess.stdout.on('data', handleStdoutData);
|
|
2141
|
+
utilityProcess.on('message', handleMessage);
|
|
2142
|
+
utilityProcess.on('exit', handleExit);
|
|
2143
|
+
const {
|
|
2144
|
+
event,
|
|
2145
|
+
type
|
|
2146
|
+
} = await promise;
|
|
2061
2147
|
return {
|
|
2062
|
-
|
|
2063
|
-
|
|
2148
|
+
event,
|
|
2149
|
+
stderr,
|
|
2150
|
+
stdout,
|
|
2151
|
+
type
|
|
2064
2152
|
};
|
|
2065
2153
|
};
|
|
2066
|
-
const
|
|
2067
|
-
|
|
2154
|
+
const create$6$1 = async ({
|
|
2155
|
+
argv = [],
|
|
2156
|
+
env = process.env,
|
|
2157
|
+
execArgv = [],
|
|
2158
|
+
name,
|
|
2159
|
+
path
|
|
2160
|
+
}) => {
|
|
2161
|
+
string(path);
|
|
2162
|
+
const actualArgv = ['--ipc-type=electron-utility-process', ...argv];
|
|
2163
|
+
const {
|
|
2164
|
+
utilityProcess
|
|
2165
|
+
} = await import('electron');
|
|
2166
|
+
const childProcess = utilityProcess.fork(path, actualArgv, {
|
|
2167
|
+
env,
|
|
2168
|
+
execArgv,
|
|
2169
|
+
serviceName: name,
|
|
2170
|
+
stdio: 'pipe'
|
|
2171
|
+
});
|
|
2172
|
+
const handleExit = () => {
|
|
2173
|
+
// @ts-ignore
|
|
2174
|
+
childProcess.stdout.unpipe(process.stdout);
|
|
2175
|
+
// @ts-ignore
|
|
2176
|
+
childProcess.stderr.unpipe(process.stderr);
|
|
2177
|
+
};
|
|
2178
|
+
childProcess.once('exit', handleExit);
|
|
2068
2179
|
// @ts-ignore
|
|
2180
|
+
childProcess.stdout.pipe(process.stdout);
|
|
2069
2181
|
const {
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2182
|
+
stderr,
|
|
2183
|
+
stdout,
|
|
2184
|
+
type
|
|
2185
|
+
} = await getFirstUtilityProcessEvent$1(childProcess);
|
|
2186
|
+
if (type === Exit$1) {
|
|
2187
|
+
throw new IpcError$1(`Utility process exited before ipc connection was established`, stdout, stderr);
|
|
2074
2188
|
}
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
parentPort.postMessage(readyMessage);
|
|
2189
|
+
// @ts-ignore
|
|
2190
|
+
childProcess.stderr.pipe(process.stderr);
|
|
2191
|
+
return childProcess;
|
|
2079
2192
|
};
|
|
2080
|
-
class
|
|
2081
|
-
getData(
|
|
2082
|
-
return
|
|
2193
|
+
let IpcParentWithElectronUtilityProcess$2 = class IpcParentWithElectronUtilityProcess extends Ipc$1 {
|
|
2194
|
+
getData(data) {
|
|
2195
|
+
return data;
|
|
2083
2196
|
}
|
|
2084
2197
|
send(message) {
|
|
2085
2198
|
this._rawIpc.postMessage(message);
|
|
@@ -2088,1574 +2201,950 @@ class IpcChildWithElectronUtilityProcess extends Ipc {
|
|
|
2088
2201
|
const {
|
|
2089
2202
|
newValue,
|
|
2090
2203
|
transfer
|
|
2091
|
-
} = fixElectronParameters(message);
|
|
2204
|
+
} = fixElectronParameters$1(message);
|
|
2092
2205
|
this._rawIpc.postMessage(newValue, transfer);
|
|
2093
2206
|
}
|
|
2094
2207
|
dispose() {
|
|
2095
|
-
this._rawIpc.
|
|
2208
|
+
this._rawIpc.kill();
|
|
2096
2209
|
}
|
|
2097
2210
|
onClose(callback) {
|
|
2098
|
-
this._rawIpc.on('
|
|
2211
|
+
this._rawIpc.on('exit', callback);
|
|
2099
2212
|
}
|
|
2100
2213
|
onMessage(callback) {
|
|
2101
2214
|
this._rawIpc.on('message', callback);
|
|
2102
2215
|
}
|
|
2103
|
-
}
|
|
2104
|
-
const wrap$i = parentPort => {
|
|
2105
|
-
return new IpcChildWithElectronUtilityProcess(parentPort);
|
|
2106
|
-
};
|
|
2107
|
-
const IpcChildWithElectronUtilityProcess$1 = {
|
|
2108
|
-
__proto__: null,
|
|
2109
|
-
listen: listen$a,
|
|
2110
|
-
signal: signal$b,
|
|
2111
|
-
wrap: wrap$i
|
|
2112
|
-
};
|
|
2113
|
-
const getActualData = (message, handle) => {
|
|
2114
|
-
if (handle) {
|
|
2115
|
-
return {
|
|
2116
|
-
...message,
|
|
2117
|
-
params: [handle, ...message.params]
|
|
2118
|
-
};
|
|
2119
|
-
}
|
|
2120
|
-
return message;
|
|
2121
|
-
};
|
|
2122
|
-
const getTransferrablesNode = value => {
|
|
2123
|
-
const transferrables = getTransferrables(value);
|
|
2124
|
-
if (transferrables.length === 0) {
|
|
2125
|
-
throw new Error(`no transferrables found`);
|
|
2126
|
-
}
|
|
2127
|
-
return transferrables[0];
|
|
2128
2216
|
};
|
|
2129
|
-
const
|
|
2130
|
-
|
|
2131
|
-
throw new IpcError('process.send must be defined');
|
|
2132
|
-
}
|
|
2133
|
-
return process;
|
|
2217
|
+
const wrap$6$1 = process => {
|
|
2218
|
+
return new IpcParentWithElectronUtilityProcess$2(process);
|
|
2134
2219
|
};
|
|
2135
|
-
const
|
|
2136
|
-
|
|
2220
|
+
const IpcParentWithElectronUtilityProcess$1$2 = {
|
|
2221
|
+
__proto__: null,
|
|
2222
|
+
create: create$6$1,
|
|
2223
|
+
wrap: wrap$6$1
|
|
2137
2224
|
};
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
this._rawIpc.on('close', callback);
|
|
2144
|
-
}
|
|
2145
|
-
send(message) {
|
|
2146
|
-
this._rawIpc.send(message);
|
|
2147
|
-
}
|
|
2148
|
-
onMessage(callback) {
|
|
2149
|
-
this._rawIpc.on('message', callback);
|
|
2150
|
-
}
|
|
2151
|
-
sendAndTransfer(message) {
|
|
2152
|
-
const transfer = getTransferrablesNode(message);
|
|
2153
|
-
this._rawIpc.send(message, transfer);
|
|
2154
|
-
}
|
|
2155
|
-
dispose() {
|
|
2156
|
-
// ignore
|
|
2225
|
+
|
|
2226
|
+
class CommandNotFoundError extends Error {
|
|
2227
|
+
constructor(command) {
|
|
2228
|
+
super(`Command not found ${command}`);
|
|
2229
|
+
this.name = 'CommandNotFoundError';
|
|
2157
2230
|
}
|
|
2158
2231
|
}
|
|
2159
|
-
const
|
|
2160
|
-
|
|
2232
|
+
const commands = Object.create(null);
|
|
2233
|
+
const register = commandMap => {
|
|
2234
|
+
Object.assign(commands, commandMap);
|
|
2161
2235
|
};
|
|
2162
|
-
const
|
|
2163
|
-
|
|
2164
|
-
listen: listen$5,
|
|
2165
|
-
signal: signal$7,
|
|
2166
|
-
wrap: wrap$d
|
|
2236
|
+
const getCommand = key => {
|
|
2237
|
+
return commands[key];
|
|
2167
2238
|
};
|
|
2168
|
-
const
|
|
2169
|
-
const
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
if (!parentPort) {
|
|
2173
|
-
throw new IpcError('parentPort is required for node worker threads ipc');
|
|
2239
|
+
const execute$1 = (command, ...args) => {
|
|
2240
|
+
const fn = getCommand(command);
|
|
2241
|
+
if (!fn) {
|
|
2242
|
+
throw new CommandNotFoundError(command);
|
|
2174
2243
|
}
|
|
2175
|
-
return
|
|
2244
|
+
return fn(...args);
|
|
2176
2245
|
};
|
|
2177
|
-
|
|
2178
|
-
|
|
2246
|
+
|
|
2247
|
+
const Two$1 = '2.0';
|
|
2248
|
+
const callbacks = Object.create(null);
|
|
2249
|
+
const set$2 = (id, fn) => {
|
|
2250
|
+
callbacks[id] = fn;
|
|
2179
2251
|
};
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
return data;
|
|
2183
|
-
}
|
|
2184
|
-
onClose(callback) {
|
|
2185
|
-
this._rawIpc.on('close', callback);
|
|
2186
|
-
}
|
|
2187
|
-
send(message) {
|
|
2188
|
-
this._rawIpc.postMessage(message);
|
|
2189
|
-
}
|
|
2190
|
-
onMessage(callback) {
|
|
2191
|
-
this._rawIpc.on('message', callback);
|
|
2192
|
-
}
|
|
2193
|
-
sendAndTransfer(message) {
|
|
2194
|
-
const transfer = getTransferrablesNode(message);
|
|
2195
|
-
this._rawIpc.postMessage(message, transfer);
|
|
2196
|
-
}
|
|
2197
|
-
dispose() {
|
|
2198
|
-
this._rawIpc.close();
|
|
2199
|
-
}
|
|
2200
|
-
}
|
|
2201
|
-
const wrap$b = parentPort => {
|
|
2202
|
-
return new IpcChildWithNodeWorker(parentPort);
|
|
2252
|
+
const get$4 = id => {
|
|
2253
|
+
return callbacks[id];
|
|
2203
2254
|
};
|
|
2204
|
-
const
|
|
2205
|
-
|
|
2206
|
-
listen: listen$3,
|
|
2207
|
-
signal: signal$5,
|
|
2208
|
-
wrap: wrap$b
|
|
2255
|
+
const remove$2 = id => {
|
|
2256
|
+
delete callbacks[id];
|
|
2209
2257
|
};
|
|
2210
|
-
|
|
2211
|
-
const
|
|
2212
|
-
|
|
2213
|
-
}) => {
|
|
2214
|
-
return webContents;
|
|
2258
|
+
let id$1 = 0;
|
|
2259
|
+
const create$3$1 = () => {
|
|
2260
|
+
return ++id$1;
|
|
2215
2261
|
};
|
|
2216
|
-
const
|
|
2262
|
+
const registerPromise$1 = () => {
|
|
2263
|
+
const id = create$3$1();
|
|
2217
2264
|
const {
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
} =
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2265
|
+
promise,
|
|
2266
|
+
resolve
|
|
2267
|
+
} = Promise.withResolvers();
|
|
2268
|
+
set$2(id, resolve);
|
|
2269
|
+
return {
|
|
2270
|
+
id,
|
|
2271
|
+
promise
|
|
2224
2272
|
};
|
|
2225
|
-
return data;
|
|
2226
2273
|
};
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2274
|
+
const create$2$1 = (method, params) => {
|
|
2275
|
+
const {
|
|
2276
|
+
id,
|
|
2277
|
+
promise
|
|
2278
|
+
} = registerPromise$1();
|
|
2279
|
+
const message = {
|
|
2280
|
+
id,
|
|
2281
|
+
jsonrpc: Two$1,
|
|
2282
|
+
method,
|
|
2283
|
+
params
|
|
2284
|
+
};
|
|
2285
|
+
return {
|
|
2286
|
+
message,
|
|
2287
|
+
promise
|
|
2288
|
+
};
|
|
2289
|
+
};
|
|
2290
|
+
class JsonRpcError extends Error {
|
|
2291
|
+
constructor(message) {
|
|
2292
|
+
super(message);
|
|
2293
|
+
this.name = 'JsonRpcError';
|
|
2230
2294
|
}
|
|
2231
|
-
|
|
2232
|
-
|
|
2295
|
+
}
|
|
2296
|
+
const NewLine$1 = '\n';
|
|
2297
|
+
const DomException = 'DOMException';
|
|
2298
|
+
const ReferenceError$1 = 'ReferenceError';
|
|
2299
|
+
const SyntaxError$1 = 'SyntaxError';
|
|
2300
|
+
const TypeError$1 = 'TypeError';
|
|
2301
|
+
const getErrorConstructor = (message, type) => {
|
|
2302
|
+
if (type) {
|
|
2303
|
+
switch (type) {
|
|
2304
|
+
case DomException:
|
|
2305
|
+
return DOMException;
|
|
2306
|
+
case ReferenceError$1:
|
|
2307
|
+
return ReferenceError;
|
|
2308
|
+
case SyntaxError$1:
|
|
2309
|
+
return SyntaxError;
|
|
2310
|
+
case TypeError$1:
|
|
2311
|
+
return TypeError;
|
|
2312
|
+
default:
|
|
2313
|
+
return Error;
|
|
2314
|
+
}
|
|
2233
2315
|
}
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
this._rawIpc.postMessage(preloadChannelType, message, transfer);
|
|
2316
|
+
if (message.startsWith('TypeError: ')) {
|
|
2317
|
+
return TypeError;
|
|
2237
2318
|
}
|
|
2238
|
-
|
|
2239
|
-
|
|
2319
|
+
if (message.startsWith('SyntaxError: ')) {
|
|
2320
|
+
return SyntaxError;
|
|
2240
2321
|
}
|
|
2241
|
-
|
|
2242
|
-
|
|
2322
|
+
if (message.startsWith('ReferenceError: ')) {
|
|
2323
|
+
return ReferenceError;
|
|
2243
2324
|
}
|
|
2244
|
-
|
|
2245
|
-
|
|
2325
|
+
return Error;
|
|
2326
|
+
};
|
|
2327
|
+
const constructError = (message, type, name) => {
|
|
2328
|
+
const ErrorConstructor = getErrorConstructor(message, type);
|
|
2329
|
+
if (ErrorConstructor === DOMException && name) {
|
|
2330
|
+
return new ErrorConstructor(message, name);
|
|
2246
2331
|
}
|
|
2247
|
-
|
|
2248
|
-
const
|
|
2249
|
-
|
|
2332
|
+
if (ErrorConstructor === Error) {
|
|
2333
|
+
const error = new Error(message);
|
|
2334
|
+
if (name && name !== 'VError') {
|
|
2335
|
+
error.name = name;
|
|
2336
|
+
}
|
|
2337
|
+
return error;
|
|
2338
|
+
}
|
|
2339
|
+
return new ErrorConstructor(message);
|
|
2250
2340
|
};
|
|
2251
|
-
const
|
|
2252
|
-
|
|
2253
|
-
listen: listen$2,
|
|
2254
|
-
wrap: wrap$a
|
|
2341
|
+
const joinLines$1 = lines => {
|
|
2342
|
+
return lines.join(NewLine$1);
|
|
2255
2343
|
};
|
|
2256
|
-
const
|
|
2257
|
-
|
|
2258
|
-
emitter.addEventListener(type, callback);
|
|
2259
|
-
} else {
|
|
2260
|
-
emitter.on(type, callback);
|
|
2261
|
-
}
|
|
2344
|
+
const splitLines$1 = lines => {
|
|
2345
|
+
return lines.split(NewLine$1);
|
|
2262
2346
|
};
|
|
2263
|
-
const
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2347
|
+
const getCurrentStack = () => {
|
|
2348
|
+
const stackLinesToSkip = 3;
|
|
2349
|
+
const currentStack = joinLines$1(splitLines$1(new Error().stack || '').slice(stackLinesToSkip));
|
|
2350
|
+
return currentStack;
|
|
2351
|
+
};
|
|
2352
|
+
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
2353
|
+
return string.indexOf(NewLine$1, startIndex);
|
|
2354
|
+
};
|
|
2355
|
+
const getParentStack = error => {
|
|
2356
|
+
let parentStack = error.stack || error.data || error.message || '';
|
|
2357
|
+
if (parentStack.startsWith(' at')) {
|
|
2358
|
+
parentStack = error.message + NewLine$1 + parentStack;
|
|
2268
2359
|
}
|
|
2360
|
+
return parentStack;
|
|
2269
2361
|
};
|
|
2270
|
-
const
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
for (const event of Object.keys(eventMap)) {
|
|
2278
|
-
removeListener(eventEmitter, event, listenerMap[event]);
|
|
2362
|
+
const MethodNotFound = -32601;
|
|
2363
|
+
const Custom = -32001;
|
|
2364
|
+
const restoreJsonRpcError = error => {
|
|
2365
|
+
const currentStack = getCurrentStack();
|
|
2366
|
+
if (error && error instanceof Error) {
|
|
2367
|
+
if (typeof error.stack === 'string') {
|
|
2368
|
+
error.stack = error.stack + NewLine$1 + currentStack;
|
|
2279
2369
|
}
|
|
2280
|
-
|
|
2281
|
-
};
|
|
2282
|
-
for (const [event, type] of Object.entries(eventMap)) {
|
|
2283
|
-
const listener = event => {
|
|
2284
|
-
cleanup({
|
|
2285
|
-
event,
|
|
2286
|
-
type
|
|
2287
|
-
});
|
|
2288
|
-
};
|
|
2289
|
-
addListener(eventEmitter, event, listener);
|
|
2290
|
-
listenerMap[event] = listener;
|
|
2370
|
+
return error;
|
|
2291
2371
|
}
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
const
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
if (!isMessagePortMain(messagePort)) {
|
|
2298
|
-
throw new IpcError('port must be of type MessagePortMain');
|
|
2372
|
+
if (error && error.code && error.code === MethodNotFound) {
|
|
2373
|
+
const restoredError = new JsonRpcError(error.message);
|
|
2374
|
+
const parentStack = getParentStack(error);
|
|
2375
|
+
restoredError.stack = parentStack + NewLine$1 + currentStack;
|
|
2376
|
+
return restoredError;
|
|
2299
2377
|
}
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2378
|
+
if (error && error.message) {
|
|
2379
|
+
const restoredError = constructError(error.message, error.type, error.name);
|
|
2380
|
+
if (error.data) {
|
|
2381
|
+
if (error.data.stack && error.data.type && error.message) {
|
|
2382
|
+
restoredError.stack = error.data.type + ': ' + error.message + NewLine$1 + error.data.stack + NewLine$1 + currentStack;
|
|
2383
|
+
} else if (error.data.stack) {
|
|
2384
|
+
restoredError.stack = error.data.stack;
|
|
2385
|
+
}
|
|
2386
|
+
if (error.data.codeFrame) {
|
|
2387
|
+
// @ts-ignore
|
|
2388
|
+
restoredError.codeFrame = error.data.codeFrame;
|
|
2389
|
+
}
|
|
2390
|
+
if (error.data.code) {
|
|
2391
|
+
// @ts-ignore
|
|
2392
|
+
restoredError.code = error.data.code;
|
|
2393
|
+
}
|
|
2394
|
+
if (error.data.type) {
|
|
2395
|
+
// @ts-ignore
|
|
2396
|
+
restoredError.name = error.data.type;
|
|
2397
|
+
}
|
|
2398
|
+
} else {
|
|
2399
|
+
if (error.stack) {
|
|
2400
|
+
const lowerStack = restoredError.stack || '';
|
|
2401
|
+
// @ts-ignore
|
|
2402
|
+
const indexNewLine = getNewLineIndex(lowerStack);
|
|
2403
|
+
const parentStack = getParentStack(error);
|
|
2404
|
+
// @ts-ignore
|
|
2405
|
+
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
2406
|
+
}
|
|
2407
|
+
if (error.codeFrame) {
|
|
2408
|
+
// @ts-ignore
|
|
2409
|
+
restoredError.codeFrame = error.codeFrame;
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
return restoredError;
|
|
2413
|
+
}
|
|
2414
|
+
if (typeof error === 'string') {
|
|
2415
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
2416
|
+
}
|
|
2417
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
2304
2418
|
};
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2419
|
+
const unwrapJsonRpcResult = responseMessage => {
|
|
2420
|
+
if ('error' in responseMessage) {
|
|
2421
|
+
const restoredError = restoreJsonRpcError(responseMessage.error);
|
|
2422
|
+
throw restoredError;
|
|
2309
2423
|
}
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
newValue,
|
|
2313
|
-
transfer
|
|
2314
|
-
} = fixElectronParameters(message);
|
|
2315
|
-
this._rawIpc.postMessage(newValue, transfer);
|
|
2424
|
+
if ('result' in responseMessage) {
|
|
2425
|
+
return responseMessage.result;
|
|
2316
2426
|
}
|
|
2317
|
-
|
|
2318
|
-
|
|
2427
|
+
throw new JsonRpcError('unexpected response message');
|
|
2428
|
+
};
|
|
2429
|
+
const warn = (...args) => {
|
|
2430
|
+
console.warn(...args);
|
|
2431
|
+
};
|
|
2432
|
+
const resolve = (id, response) => {
|
|
2433
|
+
const fn = get$4(id);
|
|
2434
|
+
if (!fn) {
|
|
2435
|
+
console.log(response);
|
|
2436
|
+
warn(`callback ${id} may already be disposed`);
|
|
2437
|
+
return;
|
|
2319
2438
|
}
|
|
2320
|
-
|
|
2321
|
-
|
|
2439
|
+
fn(response);
|
|
2440
|
+
remove$2(id);
|
|
2441
|
+
};
|
|
2442
|
+
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
2443
|
+
const getErrorType = prettyError => {
|
|
2444
|
+
if (prettyError && prettyError.type) {
|
|
2445
|
+
return prettyError.type;
|
|
2322
2446
|
}
|
|
2323
|
-
|
|
2324
|
-
|
|
2447
|
+
if (prettyError && prettyError.constructor && prettyError.constructor.name) {
|
|
2448
|
+
return prettyError.constructor.name;
|
|
2325
2449
|
}
|
|
2326
|
-
|
|
2327
|
-
const wrap$7 = messagePort => {
|
|
2328
|
-
return new IpcParentWithElectronMessagePort(messagePort);
|
|
2450
|
+
return undefined;
|
|
2329
2451
|
};
|
|
2330
|
-
const
|
|
2331
|
-
|
|
2332
|
-
create: create$7$1,
|
|
2333
|
-
signal: signal$2,
|
|
2334
|
-
wrap: wrap$7
|
|
2452
|
+
const isAlreadyStack = line => {
|
|
2453
|
+
return line.trim().startsWith('at ');
|
|
2335
2454
|
};
|
|
2336
|
-
const
|
|
2337
|
-
const
|
|
2338
|
-
const
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
cleanup({
|
|
2363
|
-
event,
|
|
2364
|
-
stderr,
|
|
2365
|
-
stdout,
|
|
2366
|
-
type: Message$1
|
|
2367
|
-
});
|
|
2455
|
+
const getStack = prettyError => {
|
|
2456
|
+
const stackString = prettyError.stack || '';
|
|
2457
|
+
const newLineIndex = stackString.indexOf('\n');
|
|
2458
|
+
if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
|
|
2459
|
+
return stackString.slice(newLineIndex + 1);
|
|
2460
|
+
}
|
|
2461
|
+
return stackString;
|
|
2462
|
+
};
|
|
2463
|
+
const getErrorProperty = (error, prettyError) => {
|
|
2464
|
+
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
2465
|
+
return {
|
|
2466
|
+
code: MethodNotFound,
|
|
2467
|
+
data: error.stack,
|
|
2468
|
+
message: error.message
|
|
2469
|
+
};
|
|
2470
|
+
}
|
|
2471
|
+
return {
|
|
2472
|
+
code: Custom,
|
|
2473
|
+
data: {
|
|
2474
|
+
code: prettyError.code,
|
|
2475
|
+
codeFrame: prettyError.codeFrame,
|
|
2476
|
+
name: prettyError.name,
|
|
2477
|
+
stack: getStack(prettyError),
|
|
2478
|
+
type: getErrorType(prettyError)
|
|
2479
|
+
},
|
|
2480
|
+
message: prettyError.message
|
|
2368
2481
|
};
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
});
|
|
2482
|
+
};
|
|
2483
|
+
const create$1$2 = (id, error) => {
|
|
2484
|
+
return {
|
|
2485
|
+
error,
|
|
2486
|
+
id,
|
|
2487
|
+
jsonrpc: Two$1
|
|
2376
2488
|
};
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
type
|
|
2386
|
-
} = await promise;
|
|
2489
|
+
};
|
|
2490
|
+
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
2491
|
+
const prettyError = preparePrettyError(error);
|
|
2492
|
+
logError(error, prettyError);
|
|
2493
|
+
const errorProperty = getErrorProperty(error, prettyError);
|
|
2494
|
+
return create$1$2(id, errorProperty);
|
|
2495
|
+
};
|
|
2496
|
+
const create$c = (message, result) => {
|
|
2387
2497
|
return {
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
type
|
|
2498
|
+
id: message.id,
|
|
2499
|
+
jsonrpc: Two$1,
|
|
2500
|
+
result: result ?? null
|
|
2392
2501
|
};
|
|
2393
2502
|
};
|
|
2394
|
-
const
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
execArgv,
|
|
2409
|
-
serviceName: name,
|
|
2410
|
-
stdio: 'pipe'
|
|
2411
|
-
});
|
|
2412
|
-
const handleExit = () => {
|
|
2413
|
-
// @ts-ignore
|
|
2414
|
-
childProcess.stdout.unpipe(process.stdout);
|
|
2415
|
-
// @ts-ignore
|
|
2416
|
-
childProcess.stderr.unpipe(process.stderr);
|
|
2503
|
+
const getSuccessResponse = (message, result) => {
|
|
2504
|
+
const resultProperty = result ?? null;
|
|
2505
|
+
return create$c(message, resultProperty);
|
|
2506
|
+
};
|
|
2507
|
+
const getErrorResponseSimple = (id, error) => {
|
|
2508
|
+
return {
|
|
2509
|
+
error: {
|
|
2510
|
+
code: Custom,
|
|
2511
|
+
data: error,
|
|
2512
|
+
// @ts-ignore
|
|
2513
|
+
message: error.message
|
|
2514
|
+
},
|
|
2515
|
+
id,
|
|
2516
|
+
jsonrpc: Two$1
|
|
2417
2517
|
};
|
|
2418
|
-
childProcess.once('exit', handleExit);
|
|
2419
|
-
// @ts-ignore
|
|
2420
|
-
childProcess.stdout.pipe(process.stdout);
|
|
2421
|
-
const {
|
|
2422
|
-
stderr,
|
|
2423
|
-
stdout,
|
|
2424
|
-
type
|
|
2425
|
-
} = await getFirstUtilityProcessEvent(childProcess);
|
|
2426
|
-
if (type === Exit) {
|
|
2427
|
-
throw new IpcError(`Utility process exited before ipc connection was established`, stdout, stderr);
|
|
2428
|
-
}
|
|
2429
|
-
// @ts-ignore
|
|
2430
|
-
childProcess.stderr.pipe(process.stderr);
|
|
2431
|
-
return childProcess;
|
|
2432
2518
|
};
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
newValue,
|
|
2443
|
-
transfer
|
|
2444
|
-
} = fixElectronParameters(message);
|
|
2445
|
-
this._rawIpc.postMessage(newValue, transfer);
|
|
2446
|
-
}
|
|
2447
|
-
dispose() {
|
|
2448
|
-
this._rawIpc.kill();
|
|
2449
|
-
}
|
|
2450
|
-
onClose(callback) {
|
|
2451
|
-
this._rawIpc.on('exit', callback);
|
|
2452
|
-
}
|
|
2453
|
-
onMessage(callback) {
|
|
2454
|
-
this._rawIpc.on('message', callback);
|
|
2519
|
+
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
2520
|
+
try {
|
|
2521
|
+
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
2522
|
+
return getSuccessResponse(message, result);
|
|
2523
|
+
} catch (error) {
|
|
2524
|
+
if (ipc.canUseSimpleErrorResponse) {
|
|
2525
|
+
return getErrorResponseSimple(message.id, error);
|
|
2526
|
+
}
|
|
2527
|
+
return getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
2455
2528
|
}
|
|
2456
2529
|
};
|
|
2457
|
-
const
|
|
2458
|
-
return
|
|
2530
|
+
const defaultPreparePrettyError = error => {
|
|
2531
|
+
return error;
|
|
2459
2532
|
};
|
|
2460
|
-
const
|
|
2461
|
-
|
|
2462
|
-
create: create$6$1,
|
|
2463
|
-
wrap: wrap$6
|
|
2533
|
+
const defaultLogError = () => {
|
|
2534
|
+
// ignore
|
|
2464
2535
|
};
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
const {
|
|
2470
|
-
code,
|
|
2471
|
-
message,
|
|
2472
|
-
stack
|
|
2473
|
-
} = getHelpfulChildProcessError('', stderr);
|
|
2474
|
-
super(message || 'child process error');
|
|
2475
|
-
this.name = 'ChildProcessError';
|
|
2476
|
-
if (code) {
|
|
2477
|
-
// @ts-ignore
|
|
2478
|
-
this.code = code;
|
|
2479
|
-
}
|
|
2480
|
-
if (stack) {
|
|
2481
|
-
// @ts-ignore
|
|
2482
|
-
const lines = splitLines$1(this.stack);
|
|
2483
|
-
const [firstLine, ...stackLines] = lines;
|
|
2484
|
-
const newStackLines = [firstLine, ...stack, ...stackLines];
|
|
2485
|
-
const newStack = joinLines$1(newStackLines);
|
|
2486
|
-
this.stack = newStack;
|
|
2487
|
-
}
|
|
2488
|
-
}
|
|
2489
|
-
}
|
|
2536
|
+
const defaultRequiresSocket = () => {
|
|
2537
|
+
return false;
|
|
2538
|
+
};
|
|
2539
|
+
const defaultResolve = resolve;
|
|
2490
2540
|
|
|
2491
|
-
//
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
const
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2541
|
+
// TODO maybe remove this in v6 or v7, only accept options object to simplify the code
|
|
2542
|
+
const normalizeParams = args => {
|
|
2543
|
+
if (args.length === 1) {
|
|
2544
|
+
const options = args[0];
|
|
2545
|
+
return {
|
|
2546
|
+
execute: options.execute,
|
|
2547
|
+
ipc: options.ipc,
|
|
2548
|
+
logError: options.logError || defaultLogError,
|
|
2549
|
+
message: options.message,
|
|
2550
|
+
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
2551
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket,
|
|
2552
|
+
resolve: options.resolve || defaultResolve
|
|
2553
|
+
};
|
|
2498
2554
|
}
|
|
2499
|
-
const newValue = removeValues(value, transfer);
|
|
2500
2555
|
return {
|
|
2501
|
-
|
|
2502
|
-
|
|
2556
|
+
execute: args[2],
|
|
2557
|
+
ipc: args[0],
|
|
2558
|
+
logError: args[5],
|
|
2559
|
+
message: args[1],
|
|
2560
|
+
preparePrettyError: args[4],
|
|
2561
|
+
requiresSocket: args[6],
|
|
2562
|
+
resolve: args[3]
|
|
2503
2563
|
};
|
|
2504
2564
|
};
|
|
2505
|
-
const
|
|
2565
|
+
const handleJsonRpcMessage = async (...args) => {
|
|
2566
|
+
const options = normalizeParams(args);
|
|
2506
2567
|
const {
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2568
|
+
execute,
|
|
2569
|
+
ipc,
|
|
2570
|
+
logError,
|
|
2571
|
+
message,
|
|
2572
|
+
preparePrettyError,
|
|
2573
|
+
requiresSocket,
|
|
2574
|
+
resolve
|
|
2575
|
+
} = options;
|
|
2576
|
+
if ('id' in message) {
|
|
2577
|
+
if ('method' in message) {
|
|
2578
|
+
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
2579
|
+
try {
|
|
2580
|
+
ipc.send(response);
|
|
2581
|
+
} catch (error) {
|
|
2582
|
+
const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
2583
|
+
ipc.send(errorResponse);
|
|
2518
2584
|
}
|
|
2519
|
-
|
|
2520
|
-
childProcess.off('exit', handleExit);
|
|
2521
|
-
childProcess.off('error', handleError);
|
|
2522
|
-
resolve(value);
|
|
2523
|
-
};
|
|
2524
|
-
const handleStdErrData = data => {
|
|
2525
|
-
stderr += data;
|
|
2526
|
-
};
|
|
2527
|
-
const handleStdoutData = data => {
|
|
2528
|
-
stdout += data;
|
|
2529
|
-
};
|
|
2530
|
-
const handleMessage = event => {
|
|
2531
|
-
cleanup({
|
|
2532
|
-
event,
|
|
2533
|
-
stderr,
|
|
2534
|
-
stdout,
|
|
2535
|
-
type: Message$1
|
|
2536
|
-
});
|
|
2537
|
-
};
|
|
2538
|
-
const handleExit = event => {
|
|
2539
|
-
cleanup({
|
|
2540
|
-
event,
|
|
2541
|
-
stderr,
|
|
2542
|
-
stdout,
|
|
2543
|
-
type: Exit
|
|
2544
|
-
});
|
|
2545
|
-
};
|
|
2546
|
-
const handleError = event => {
|
|
2547
|
-
cleanup({
|
|
2548
|
-
event,
|
|
2549
|
-
stderr,
|
|
2550
|
-
stdout,
|
|
2551
|
-
type: Error$2
|
|
2552
|
-
});
|
|
2553
|
-
};
|
|
2554
|
-
if (childProcess.stdout && childProcess.stderr) {
|
|
2555
|
-
childProcess.stderr.on('data', handleStdErrData);
|
|
2556
|
-
childProcess.stdout.on('data', handleStdoutData);
|
|
2585
|
+
return;
|
|
2557
2586
|
}
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2587
|
+
resolve(message.id, message);
|
|
2588
|
+
return;
|
|
2589
|
+
}
|
|
2590
|
+
if ('method' in message) {
|
|
2591
|
+
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
2592
|
+
return;
|
|
2593
|
+
}
|
|
2594
|
+
throw new JsonRpcError('unexpected message');
|
|
2595
|
+
};
|
|
2596
|
+
const invokeHelper$1 = async (ipc, method, params, useSendAndTransfer) => {
|
|
2597
|
+
const {
|
|
2598
|
+
message,
|
|
2599
|
+
promise
|
|
2600
|
+
} = create$2$1(method, params);
|
|
2601
|
+
if (ipc.sendAndTransfer) {
|
|
2602
|
+
ipc.sendAndTransfer(message);
|
|
2603
|
+
} else {
|
|
2604
|
+
ipc.send(message);
|
|
2605
|
+
}
|
|
2606
|
+
const responseMessage = await promise;
|
|
2607
|
+
return unwrapJsonRpcResult(responseMessage);
|
|
2608
|
+
};
|
|
2609
|
+
const invokeAndTransfer$1 = (ipc, method, ...params) => {
|
|
2610
|
+
return invokeHelper$1(ipc, method, params);
|
|
2611
|
+
};
|
|
2612
|
+
|
|
2613
|
+
const Two = '2.0';
|
|
2614
|
+
|
|
2615
|
+
const create$b = (method, params) => {
|
|
2562
2616
|
return {
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
type
|
|
2617
|
+
jsonrpc: Two,
|
|
2618
|
+
method,
|
|
2619
|
+
params
|
|
2567
2620
|
};
|
|
2568
2621
|
};
|
|
2569
2622
|
|
|
2570
|
-
|
|
2571
|
-
const
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
path,
|
|
2577
|
-
stdio = 'inherit'
|
|
2578
|
-
}) => {
|
|
2579
|
-
try {
|
|
2580
|
-
string(path);
|
|
2581
|
-
const actualArgv = ['--ipc-type=node-forked-process', ...argv];
|
|
2582
|
-
const {
|
|
2583
|
-
fork
|
|
2584
|
-
} = await import('node:child_process');
|
|
2585
|
-
const childProcess = fork(path, actualArgv, {
|
|
2586
|
-
env,
|
|
2587
|
-
execArgv,
|
|
2588
|
-
stdio: 'pipe'
|
|
2589
|
-
});
|
|
2590
|
-
const {
|
|
2591
|
-
event,
|
|
2592
|
-
stderr,
|
|
2593
|
-
type
|
|
2594
|
-
} = await getFirstNodeChildProcessEvent(childProcess);
|
|
2595
|
-
if (type === Exit) {
|
|
2596
|
-
throw new ChildProcessError(stderr);
|
|
2597
|
-
}
|
|
2598
|
-
if (type === Error$2) {
|
|
2599
|
-
throw new IpcError(`child process had an error ${event}`);
|
|
2600
|
-
}
|
|
2601
|
-
if (stdio === 'inherit' && childProcess.stdout && childProcess.stderr) {
|
|
2602
|
-
childProcess.stdout.pipe(process.stdout);
|
|
2603
|
-
childProcess.stderr.pipe(process.stderr);
|
|
2604
|
-
}
|
|
2605
|
-
return childProcess;
|
|
2606
|
-
} catch (error) {
|
|
2607
|
-
throw new VError(error, `Failed to launch ${name}`);
|
|
2608
|
-
}
|
|
2609
|
-
};
|
|
2610
|
-
class IpcParentWithNodeForkedProcess extends Ipc {
|
|
2611
|
-
constructor(childProcess) {
|
|
2612
|
-
super(childProcess);
|
|
2613
|
-
this.pid = childProcess.pid;
|
|
2614
|
-
}
|
|
2615
|
-
getData(message) {
|
|
2616
|
-
return message;
|
|
2617
|
-
}
|
|
2618
|
-
send(message) {
|
|
2619
|
-
this._rawIpc.send(message);
|
|
2620
|
-
}
|
|
2621
|
-
sendAndTransfer(message) {
|
|
2622
|
-
const {
|
|
2623
|
-
newValue,
|
|
2624
|
-
transfer
|
|
2625
|
-
} = fixNodeChildProcessParameters(message);
|
|
2626
|
-
this._rawIpc.send(newValue, transfer);
|
|
2627
|
-
}
|
|
2628
|
-
dispose() {
|
|
2629
|
-
this._rawIpc.kill();
|
|
2630
|
-
}
|
|
2631
|
-
onClose(callback) {
|
|
2632
|
-
this._rawIpc.on('close', callback);
|
|
2633
|
-
}
|
|
2634
|
-
onMessage(callback) {
|
|
2635
|
-
this._rawIpc.on('message', callback);
|
|
2636
|
-
}
|
|
2637
|
-
}
|
|
2638
|
-
const wrap$2 = childProcess => {
|
|
2639
|
-
return new IpcParentWithNodeForkedProcess(childProcess);
|
|
2640
|
-
};
|
|
2641
|
-
const IpcParentWithNodeForkedProcess$1 = {
|
|
2642
|
-
__proto__: null,
|
|
2643
|
-
create: create$2$2,
|
|
2644
|
-
wrap: wrap$2
|
|
2645
|
-
};
|
|
2646
|
-
const fixNodeWorkerParameters = value => {
|
|
2647
|
-
const transfer = getTransferrables(value);
|
|
2648
|
-
if (transfer.length === 0) {
|
|
2649
|
-
throw new IpcError('no transferrables found');
|
|
2650
|
-
}
|
|
2651
|
-
return {
|
|
2652
|
-
newValue: value,
|
|
2653
|
-
transfer: transfer
|
|
2654
|
-
};
|
|
2655
|
-
};
|
|
2656
|
-
const getFirstNodeWorkerEvent = worker => {
|
|
2657
|
-
return getFirstEvent(worker, {
|
|
2658
|
-
error: Error$2,
|
|
2659
|
-
exit: Exit,
|
|
2660
|
-
message: Message$1
|
|
2661
|
-
});
|
|
2662
|
-
};
|
|
2663
|
-
const create$1$2 = async ({
|
|
2664
|
-
argv = [],
|
|
2665
|
-
env = process.env,
|
|
2666
|
-
execArgv = [],
|
|
2667
|
-
name,
|
|
2668
|
-
path,
|
|
2669
|
-
stdio
|
|
2670
|
-
}) => {
|
|
2671
|
-
string(path);
|
|
2672
|
-
const actualArgv = ['--ipc-type=node-worker', ...argv];
|
|
2673
|
-
const actualEnv = {
|
|
2674
|
-
...env,
|
|
2675
|
-
ELECTRON_RUN_AS_NODE: '1'
|
|
2623
|
+
const create$a = (id, method, params) => {
|
|
2624
|
+
const message = {
|
|
2625
|
+
id,
|
|
2626
|
+
jsonrpc: Two,
|
|
2627
|
+
method,
|
|
2628
|
+
params
|
|
2676
2629
|
};
|
|
2677
|
-
|
|
2678
|
-
const {
|
|
2679
|
-
Worker
|
|
2680
|
-
} = await import('node:worker_threads');
|
|
2681
|
-
const worker = new Worker(path, {
|
|
2682
|
-
argv: actualArgv,
|
|
2683
|
-
env: actualEnv,
|
|
2684
|
-
execArgv,
|
|
2685
|
-
name,
|
|
2686
|
-
stderr: ignoreStdio,
|
|
2687
|
-
stdout: ignoreStdio
|
|
2688
|
-
});
|
|
2689
|
-
const {
|
|
2690
|
-
event,
|
|
2691
|
-
type
|
|
2692
|
-
} = await getFirstNodeWorkerEvent(worker);
|
|
2693
|
-
if (type === Exit) {
|
|
2694
|
-
throw new IpcError(`Worker exited before ipc connection was established`);
|
|
2695
|
-
}
|
|
2696
|
-
if (type === Error$2) {
|
|
2697
|
-
throw new IpcError(`Worker threw an error before ipc connection was established: ${event}`);
|
|
2698
|
-
}
|
|
2699
|
-
if (event !== readyMessage) {
|
|
2700
|
-
throw new IpcError('unexpected first message from worker');
|
|
2701
|
-
}
|
|
2702
|
-
return worker;
|
|
2703
|
-
};
|
|
2704
|
-
class IpcParentWithNodeWorker extends Ipc {
|
|
2705
|
-
getData(message) {
|
|
2706
|
-
return message;
|
|
2707
|
-
}
|
|
2708
|
-
send(message) {
|
|
2709
|
-
this._rawIpc.postMessage(message);
|
|
2710
|
-
}
|
|
2711
|
-
sendAndTransfer(message) {
|
|
2712
|
-
const {
|
|
2713
|
-
newValue,
|
|
2714
|
-
transfer
|
|
2715
|
-
} = fixNodeWorkerParameters(message);
|
|
2716
|
-
this._rawIpc.postMessage(newValue, transfer);
|
|
2717
|
-
}
|
|
2718
|
-
async dispose() {
|
|
2719
|
-
await this._rawIpc.terminate();
|
|
2720
|
-
}
|
|
2721
|
-
onClose(callback) {
|
|
2722
|
-
this._rawIpc.on('exit', callback);
|
|
2723
|
-
}
|
|
2724
|
-
onMessage(callback) {
|
|
2725
|
-
this._rawIpc.on('message', callback);
|
|
2726
|
-
}
|
|
2727
|
-
}
|
|
2728
|
-
const wrap$1 = worker => {
|
|
2729
|
-
return new IpcParentWithNodeWorker(worker);
|
|
2730
|
-
};
|
|
2731
|
-
const IpcParentWithNodeWorker$1 = {
|
|
2732
|
-
__proto__: null,
|
|
2733
|
-
create: create$1$2,
|
|
2734
|
-
wrap: wrap$1
|
|
2630
|
+
return message;
|
|
2735
2631
|
};
|
|
2736
2632
|
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
this.name = 'CommandNotFoundError';
|
|
2741
|
-
}
|
|
2742
|
-
}
|
|
2743
|
-
const commands = Object.create(null);
|
|
2744
|
-
const register = commandMap => {
|
|
2745
|
-
Object.assign(commands, commandMap);
|
|
2746
|
-
};
|
|
2747
|
-
const getCommand = key => {
|
|
2748
|
-
return commands[key];
|
|
2749
|
-
};
|
|
2750
|
-
const execute$1 = (command, ...args) => {
|
|
2751
|
-
const fn = getCommand(command);
|
|
2752
|
-
if (!fn) {
|
|
2753
|
-
throw new CommandNotFoundError(command);
|
|
2754
|
-
}
|
|
2755
|
-
return fn(...args);
|
|
2633
|
+
let id = 0;
|
|
2634
|
+
const create$9 = () => {
|
|
2635
|
+
return ++id;
|
|
2756
2636
|
};
|
|
2757
2637
|
|
|
2758
|
-
const
|
|
2759
|
-
const
|
|
2760
|
-
const set$2 = (id, fn) => {
|
|
2761
|
-
callbacks[id] = fn;
|
|
2762
|
-
};
|
|
2763
|
-
const get$4 = id => {
|
|
2764
|
-
return callbacks[id];
|
|
2765
|
-
};
|
|
2766
|
-
const remove$2 = id => {
|
|
2767
|
-
delete callbacks[id];
|
|
2768
|
-
};
|
|
2769
|
-
let id$1 = 0;
|
|
2770
|
-
const create$3$1 = () => {
|
|
2771
|
-
return ++id$1;
|
|
2772
|
-
};
|
|
2773
|
-
const registerPromise$1 = () => {
|
|
2774
|
-
const id = create$3$1();
|
|
2638
|
+
const registerPromise = map => {
|
|
2639
|
+
const id = create$9();
|
|
2775
2640
|
const {
|
|
2776
2641
|
promise,
|
|
2777
2642
|
resolve
|
|
2778
2643
|
} = Promise.withResolvers();
|
|
2779
|
-
|
|
2644
|
+
map[id] = resolve;
|
|
2780
2645
|
return {
|
|
2781
2646
|
id,
|
|
2782
2647
|
promise
|
|
2783
2648
|
};
|
|
2784
2649
|
};
|
|
2785
|
-
|
|
2650
|
+
|
|
2651
|
+
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
2786
2652
|
const {
|
|
2787
2653
|
id,
|
|
2788
2654
|
promise
|
|
2789
|
-
} = registerPromise
|
|
2790
|
-
const message =
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2655
|
+
} = registerPromise(callbacks);
|
|
2656
|
+
const message = create$a(id, method, params);
|
|
2657
|
+
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
2658
|
+
ipc.sendAndTransfer(message);
|
|
2659
|
+
} else {
|
|
2660
|
+
ipc.send(message);
|
|
2661
|
+
}
|
|
2662
|
+
const responseMessage = await promise;
|
|
2663
|
+
return unwrapJsonRpcResult(responseMessage);
|
|
2664
|
+
};
|
|
2665
|
+
const createRpc = ipc => {
|
|
2666
|
+
const callbacks = Object.create(null);
|
|
2667
|
+
ipc._resolve = (id, response) => {
|
|
2668
|
+
const fn = callbacks[id];
|
|
2669
|
+
if (!fn) {
|
|
2670
|
+
console.warn(`callback ${id} may already be disposed`);
|
|
2671
|
+
return;
|
|
2672
|
+
}
|
|
2673
|
+
fn(response);
|
|
2674
|
+
delete callbacks[id];
|
|
2795
2675
|
};
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2676
|
+
const rpc = {
|
|
2677
|
+
async dispose() {
|
|
2678
|
+
await ipc?.dispose();
|
|
2679
|
+
},
|
|
2680
|
+
invoke(method, ...params) {
|
|
2681
|
+
return invokeHelper(callbacks, ipc, method, params, false);
|
|
2682
|
+
},
|
|
2683
|
+
invokeAndTransfer(method, ...params) {
|
|
2684
|
+
return invokeHelper(callbacks, ipc, method, params, true);
|
|
2685
|
+
},
|
|
2686
|
+
// @ts-ignore
|
|
2687
|
+
ipc,
|
|
2688
|
+
/**
|
|
2689
|
+
* @deprecated
|
|
2690
|
+
*/
|
|
2691
|
+
send(method, ...params) {
|
|
2692
|
+
const message = create$b(method, params);
|
|
2693
|
+
ipc.send(message);
|
|
2694
|
+
}
|
|
2799
2695
|
};
|
|
2696
|
+
return rpc;
|
|
2800
2697
|
};
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2698
|
+
|
|
2699
|
+
const requiresSocket$1 = () => {
|
|
2700
|
+
return false;
|
|
2701
|
+
};
|
|
2702
|
+
const preparePrettyError = error => {
|
|
2703
|
+
return error;
|
|
2704
|
+
};
|
|
2705
|
+
const logError$1 = () => {
|
|
2706
|
+
// handled by renderer worker
|
|
2707
|
+
};
|
|
2708
|
+
const handleMessage$1 = event => {
|
|
2709
|
+
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket$1;
|
|
2710
|
+
const actualExecute = event?.target?.execute || execute$1;
|
|
2711
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError$1, actualRequiresSocket);
|
|
2712
|
+
};
|
|
2713
|
+
|
|
2714
|
+
const handleIpc$1 = ipc => {
|
|
2715
|
+
if ('addEventListener' in ipc) {
|
|
2716
|
+
ipc.addEventListener('message', handleMessage$1);
|
|
2717
|
+
} else if ('on' in ipc) {
|
|
2718
|
+
// deprecated
|
|
2719
|
+
ipc.on('message', handleMessage$1);
|
|
2805
2720
|
}
|
|
2806
|
-
}
|
|
2807
|
-
const NewLine = '\n';
|
|
2808
|
-
const DomException = 'DOMException';
|
|
2809
|
-
const ReferenceError$1 = 'ReferenceError';
|
|
2810
|
-
const SyntaxError$1 = 'SyntaxError';
|
|
2811
|
-
const TypeError$1 = 'TypeError';
|
|
2812
|
-
const getErrorConstructor = (message, type) => {
|
|
2813
|
-
if (type) {
|
|
2814
|
-
switch (type) {
|
|
2815
|
-
case DomException:
|
|
2816
|
-
return DOMException;
|
|
2817
|
-
case ReferenceError$1:
|
|
2818
|
-
return ReferenceError;
|
|
2819
|
-
case SyntaxError$1:
|
|
2820
|
-
return SyntaxError;
|
|
2821
|
-
case TypeError$1:
|
|
2822
|
-
return TypeError;
|
|
2823
|
-
default:
|
|
2824
|
-
return Error;
|
|
2825
|
-
}
|
|
2826
|
-
}
|
|
2827
|
-
if (message.startsWith('TypeError: ')) {
|
|
2828
|
-
return TypeError;
|
|
2829
|
-
}
|
|
2830
|
-
if (message.startsWith('SyntaxError: ')) {
|
|
2831
|
-
return SyntaxError;
|
|
2832
|
-
}
|
|
2833
|
-
if (message.startsWith('ReferenceError: ')) {
|
|
2834
|
-
return ReferenceError;
|
|
2835
|
-
}
|
|
2836
|
-
return Error;
|
|
2837
|
-
};
|
|
2838
|
-
const constructError = (message, type, name) => {
|
|
2839
|
-
const ErrorConstructor = getErrorConstructor(message, type);
|
|
2840
|
-
if (ErrorConstructor === DOMException && name) {
|
|
2841
|
-
return new ErrorConstructor(message, name);
|
|
2842
|
-
}
|
|
2843
|
-
if (ErrorConstructor === Error) {
|
|
2844
|
-
const error = new Error(message);
|
|
2845
|
-
if (name && name !== 'VError') {
|
|
2846
|
-
error.name = name;
|
|
2847
|
-
}
|
|
2848
|
-
return error;
|
|
2849
|
-
}
|
|
2850
|
-
return new ErrorConstructor(message);
|
|
2851
|
-
};
|
|
2852
|
-
const joinLines = lines => {
|
|
2853
|
-
return lines.join(NewLine);
|
|
2854
|
-
};
|
|
2855
|
-
const splitLines = lines => {
|
|
2856
|
-
return lines.split(NewLine);
|
|
2857
|
-
};
|
|
2858
|
-
const getCurrentStack = () => {
|
|
2859
|
-
const stackLinesToSkip = 3;
|
|
2860
|
-
const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
|
|
2861
|
-
return currentStack;
|
|
2862
|
-
};
|
|
2863
|
-
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
2864
|
-
return string.indexOf(NewLine, startIndex);
|
|
2865
2721
|
};
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2722
|
+
|
|
2723
|
+
const listen$1 = async (module, options) => {
|
|
2724
|
+
const rawIpc = await module.listen(options);
|
|
2725
|
+
if (module.signal) {
|
|
2726
|
+
module.signal(rawIpc);
|
|
2870
2727
|
}
|
|
2871
|
-
|
|
2728
|
+
const ipc = module.wrap(rawIpc);
|
|
2729
|
+
return ipc;
|
|
2872
2730
|
};
|
|
2873
|
-
|
|
2874
|
-
const
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
restoredError.stack = parentStack + NewLine + currentStack;
|
|
2887
|
-
return restoredError;
|
|
2888
|
-
}
|
|
2889
|
-
if (error && error.message) {
|
|
2890
|
-
const restoredError = constructError(error.message, error.type, error.name);
|
|
2891
|
-
if (error.data) {
|
|
2892
|
-
if (error.data.stack && error.data.type && error.message) {
|
|
2893
|
-
restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
|
|
2894
|
-
} else if (error.data.stack) {
|
|
2895
|
-
restoredError.stack = error.data.stack;
|
|
2896
|
-
}
|
|
2897
|
-
if (error.data.codeFrame) {
|
|
2898
|
-
// @ts-ignore
|
|
2899
|
-
restoredError.codeFrame = error.data.codeFrame;
|
|
2900
|
-
}
|
|
2901
|
-
if (error.data.code) {
|
|
2902
|
-
// @ts-ignore
|
|
2903
|
-
restoredError.code = error.data.code;
|
|
2904
|
-
}
|
|
2905
|
-
if (error.data.type) {
|
|
2906
|
-
// @ts-ignore
|
|
2907
|
-
restoredError.name = error.data.type;
|
|
2908
|
-
}
|
|
2909
|
-
} else {
|
|
2910
|
-
if (error.stack) {
|
|
2911
|
-
const lowerStack = restoredError.stack || '';
|
|
2912
|
-
// @ts-ignore
|
|
2913
|
-
const indexNewLine = getNewLineIndex(lowerStack);
|
|
2914
|
-
const parentStack = getParentStack(error);
|
|
2915
|
-
// @ts-ignore
|
|
2916
|
-
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
2917
|
-
}
|
|
2918
|
-
if (error.codeFrame) {
|
|
2919
|
-
// @ts-ignore
|
|
2920
|
-
restoredError.codeFrame = error.codeFrame;
|
|
2921
|
-
}
|
|
2922
|
-
}
|
|
2923
|
-
return restoredError;
|
|
2924
|
-
}
|
|
2925
|
-
if (typeof error === 'string') {
|
|
2926
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
2731
|
+
|
|
2732
|
+
const create$8 = async ({
|
|
2733
|
+
commandMap,
|
|
2734
|
+
messagePort,
|
|
2735
|
+
requiresSocket
|
|
2736
|
+
}) => {
|
|
2737
|
+
// TODO create a commandMap per rpc instance
|
|
2738
|
+
register(commandMap);
|
|
2739
|
+
const ipc = await listen$1(IpcChildWithElectronMessagePort$1$1, {
|
|
2740
|
+
messagePort
|
|
2741
|
+
});
|
|
2742
|
+
if (requiresSocket) {
|
|
2743
|
+
ipc.requiresSocket = requiresSocket;
|
|
2927
2744
|
}
|
|
2928
|
-
|
|
2745
|
+
handleIpc$1(ipc);
|
|
2746
|
+
const rpc = createRpc(ipc);
|
|
2747
|
+
return rpc;
|
|
2929
2748
|
};
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2749
|
+
|
|
2750
|
+
const create$5 = async ({
|
|
2751
|
+
argv,
|
|
2752
|
+
commandMap,
|
|
2753
|
+
env,
|
|
2754
|
+
execArgv,
|
|
2755
|
+
name,
|
|
2756
|
+
path,
|
|
2757
|
+
requiresSocket
|
|
2758
|
+
}) => {
|
|
2759
|
+
// TODO create a commandMap per rpc instance
|
|
2760
|
+
register(commandMap);
|
|
2761
|
+
const rawIpc = await IpcParentWithElectronUtilityProcess$1$2.create({
|
|
2762
|
+
argv,
|
|
2763
|
+
env,
|
|
2764
|
+
execArgv,
|
|
2765
|
+
name,
|
|
2766
|
+
path
|
|
2767
|
+
});
|
|
2768
|
+
const ipc = IpcParentWithElectronUtilityProcess$1$2.wrap(rawIpc);
|
|
2769
|
+
if (requiresSocket) {
|
|
2770
|
+
// @ts-ignore
|
|
2771
|
+
ipc.requiresSocket = requiresSocket;
|
|
2937
2772
|
}
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
console.warn(...args);
|
|
2773
|
+
handleIpc$1(ipc);
|
|
2774
|
+
const rpc = createRpc(ipc);
|
|
2775
|
+
return rpc;
|
|
2942
2776
|
};
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2777
|
+
|
|
2778
|
+
const create$4 = async ({
|
|
2779
|
+
commandMap,
|
|
2780
|
+
requiresSocket,
|
|
2781
|
+
webContents
|
|
2782
|
+
}) => {
|
|
2783
|
+
// TODO create a commandMap per rpc instance
|
|
2784
|
+
register(commandMap);
|
|
2785
|
+
const ipc = IpcChildWithRendererProcess2$1$1.wrap(webContents);
|
|
2786
|
+
if (requiresSocket) {
|
|
2787
|
+
// @ts-ignore
|
|
2788
|
+
ipc.requiresSocket = requiresSocket;
|
|
2949
2789
|
}
|
|
2950
|
-
|
|
2951
|
-
|
|
2790
|
+
handleIpc$1(ipc);
|
|
2791
|
+
const rpc = createRpc(ipc);
|
|
2792
|
+
return rpc;
|
|
2952
2793
|
};
|
|
2953
|
-
|
|
2954
|
-
const
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
}
|
|
2961
|
-
return
|
|
2794
|
+
|
|
2795
|
+
const commandMapRef = Object.create(null);
|
|
2796
|
+
|
|
2797
|
+
const getPortTuple = () => {
|
|
2798
|
+
const {
|
|
2799
|
+
port1,
|
|
2800
|
+
port2
|
|
2801
|
+
} = new MessageChannelMain();
|
|
2802
|
+
return {
|
|
2803
|
+
port1,
|
|
2804
|
+
port2
|
|
2805
|
+
};
|
|
2962
2806
|
};
|
|
2963
|
-
|
|
2964
|
-
|
|
2807
|
+
|
|
2808
|
+
const getSharedProcessArgv = isProduction => {
|
|
2809
|
+
return [];
|
|
2965
2810
|
};
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
return stackString;
|
|
2811
|
+
|
|
2812
|
+
const EmbedsProcess = 2;
|
|
2813
|
+
const MainProcess = -5;
|
|
2814
|
+
|
|
2815
|
+
const mark = key => {
|
|
2816
|
+
performance.mark(key);
|
|
2973
2817
|
};
|
|
2974
|
-
const
|
|
2975
|
-
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
2976
|
-
return {
|
|
2977
|
-
code: MethodNotFound,
|
|
2978
|
-
data: error.stack,
|
|
2979
|
-
message: error.message
|
|
2980
|
-
};
|
|
2981
|
-
}
|
|
2818
|
+
const toUiEntry = performanceEntry => {
|
|
2982
2819
|
return {
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
stack: getStack(prettyError),
|
|
2989
|
-
type: getErrorType(prettyError)
|
|
2990
|
-
},
|
|
2991
|
-
message: prettyError.message
|
|
2820
|
+
detail: performanceEntry.detail,
|
|
2821
|
+
duration: performanceEntry.duration,
|
|
2822
|
+
entryType: performanceEntry.entryType,
|
|
2823
|
+
name: performanceEntry.name,
|
|
2824
|
+
startTime: performanceEntry.startTime
|
|
2992
2825
|
};
|
|
2993
2826
|
};
|
|
2994
|
-
const
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
jsonrpc: Two$1
|
|
2999
|
-
};
|
|
2827
|
+
const getEntries = () => {
|
|
2828
|
+
const entries = performance.getEntries();
|
|
2829
|
+
const uiEntries = entries.map(toUiEntry);
|
|
2830
|
+
return uiEntries;
|
|
3000
2831
|
};
|
|
3001
|
-
const
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
jsonrpc: Two$1,
|
|
3011
|
-
result: result ?? null
|
|
3012
|
-
};
|
|
2832
|
+
const {
|
|
2833
|
+
timeOrigin
|
|
2834
|
+
} = performance;
|
|
2835
|
+
|
|
2836
|
+
const Performance = {
|
|
2837
|
+
__proto__: null,
|
|
2838
|
+
getEntries,
|
|
2839
|
+
mark,
|
|
2840
|
+
timeOrigin
|
|
3013
2841
|
};
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
2842
|
+
|
|
2843
|
+
const WillLoadUrl = 'code/willLoadUrl';
|
|
2844
|
+
const DidLoadUrl = 'code/didLoadUrl';
|
|
2845
|
+
const AppReady = 'code/appReady';
|
|
2846
|
+
const WillStartSharedProcess = 'code/willStartSharedProcess';
|
|
2847
|
+
const DidStartSharedProcess = 'code/didStartSharedProcess';
|
|
2848
|
+
const WillCreateCodeWindow = 'code/willCreateCodeWindow';
|
|
2849
|
+
const DidCreateCodeWindow = 'code/didCreateCodeWindow';
|
|
2850
|
+
|
|
2851
|
+
const join = (...paths) => {
|
|
2852
|
+
return NodePath.join(...paths);
|
|
3017
2853
|
};
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
2854
|
+
|
|
2855
|
+
const __dirname$1 = dirname(fileURLToPath(import.meta.url));
|
|
2856
|
+
const root = process.env.LVCE_ROOT || join(__dirname$1, '../../../../..');
|
|
2857
|
+
|
|
2858
|
+
const {
|
|
2859
|
+
env,
|
|
2860
|
+
platform
|
|
2861
|
+
} = process;
|
|
2862
|
+
const isLinux = platform === 'linux';
|
|
2863
|
+
const isProduction = false;
|
|
2864
|
+
const homeDirectory = homedir();
|
|
2865
|
+
|
|
2866
|
+
const xdgCache = env.XDG_CACHE_HOME || (homeDirectory ? join(homeDirectory, '.cache') : undefined);
|
|
2867
|
+
const xdgData = env.XDG_DATA_HOME || (homeDirectory ? join(homeDirectory, '.local', 'share') : undefined);
|
|
2868
|
+
join(xdgData || tmpdir(), applicationName);
|
|
2869
|
+
const chromeUserDataPath = xdgCache ? join(xdgCache, applicationName, 'userdata') : '';
|
|
2870
|
+
|
|
2871
|
+
const useIpcForResponse = true;
|
|
2872
|
+
const getSessionId = () => {
|
|
2873
|
+
return process.env.SESSION_ID || `persist:${scheme}`;
|
|
3029
2874
|
};
|
|
3030
|
-
const
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
return getSuccessResponse(message, result);
|
|
3034
|
-
} catch (error) {
|
|
3035
|
-
if (ipc.canUseSimpleErrorResponse) {
|
|
3036
|
-
return getErrorResponseSimple(message.id, error);
|
|
3037
|
-
}
|
|
3038
|
-
return getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
2875
|
+
const getSharedProcessPath = () => {
|
|
2876
|
+
if (process.env.LVCE_SHARED_PROCESS_PATH) {
|
|
2877
|
+
return process.env.LVCE_SHARED_PROCESS_PATH;
|
|
3039
2878
|
}
|
|
2879
|
+
return join(root, 'packages', 'shared-process', 'src', 'sharedProcessMain.ts');
|
|
3040
2880
|
};
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
};
|
|
3044
|
-
const defaultLogError = () => {
|
|
3045
|
-
// ignore
|
|
3046
|
-
};
|
|
3047
|
-
const defaultRequiresSocket = () => {
|
|
2881
|
+
|
|
2882
|
+
const requiresSocket = () => {
|
|
3048
2883
|
return false;
|
|
3049
2884
|
};
|
|
3050
|
-
const defaultResolve = resolve;
|
|
3051
2885
|
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
if (args.length === 1) {
|
|
3055
|
-
const options = args[0];
|
|
3056
|
-
return {
|
|
3057
|
-
execute: options.execute,
|
|
3058
|
-
ipc: options.ipc,
|
|
3059
|
-
logError: options.logError || defaultLogError,
|
|
3060
|
-
message: options.message,
|
|
3061
|
-
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
3062
|
-
requiresSocket: options.requiresSocket || defaultRequiresSocket,
|
|
3063
|
-
resolve: options.resolve || defaultResolve
|
|
3064
|
-
};
|
|
3065
|
-
}
|
|
3066
|
-
return {
|
|
3067
|
-
execute: args[2],
|
|
3068
|
-
ipc: args[0],
|
|
3069
|
-
logError: args[5],
|
|
3070
|
-
message: args[1],
|
|
3071
|
-
preparePrettyError: args[4],
|
|
3072
|
-
requiresSocket: args[6],
|
|
3073
|
-
resolve: args[3]
|
|
3074
|
-
};
|
|
3075
|
-
};
|
|
3076
|
-
const handleJsonRpcMessage = async (...args) => {
|
|
3077
|
-
const options = normalizeParams(args);
|
|
3078
|
-
const {
|
|
3079
|
-
execute,
|
|
3080
|
-
ipc,
|
|
3081
|
-
logError,
|
|
3082
|
-
message,
|
|
3083
|
-
preparePrettyError,
|
|
3084
|
-
requiresSocket,
|
|
3085
|
-
resolve
|
|
3086
|
-
} = options;
|
|
3087
|
-
if ('id' in message) {
|
|
3088
|
-
if ('method' in message) {
|
|
3089
|
-
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
3090
|
-
try {
|
|
3091
|
-
ipc.send(response);
|
|
3092
|
-
} catch (error) {
|
|
3093
|
-
const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
3094
|
-
ipc.send(errorResponse);
|
|
3095
|
-
}
|
|
3096
|
-
return;
|
|
3097
|
-
}
|
|
3098
|
-
resolve(message.id, message);
|
|
3099
|
-
return;
|
|
3100
|
-
}
|
|
3101
|
-
if ('method' in message) {
|
|
3102
|
-
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
3103
|
-
return;
|
|
3104
|
-
}
|
|
3105
|
-
throw new JsonRpcError('unexpected message');
|
|
2886
|
+
const handleChildError = error => {
|
|
2887
|
+
exit$1(Error$3);
|
|
3106
2888
|
};
|
|
3107
|
-
const
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
promise
|
|
3111
|
-
} = create$2$1(method, params);
|
|
3112
|
-
if (ipc.sendAndTransfer) {
|
|
3113
|
-
ipc.sendAndTransfer(message);
|
|
3114
|
-
} else {
|
|
3115
|
-
ipc.send(message);
|
|
3116
|
-
}
|
|
3117
|
-
const responseMessage = await promise;
|
|
3118
|
-
return unwrapJsonRpcResult(responseMessage);
|
|
2889
|
+
const handleChildExit = code => {
|
|
2890
|
+
info(`[main process] shared process exited with code ${code}`);
|
|
2891
|
+
exit$1(code);
|
|
3119
2892
|
};
|
|
3120
|
-
const
|
|
3121
|
-
|
|
2893
|
+
const handleChildDisconnect = () => {
|
|
2894
|
+
info('[main process] shared process disconnected');
|
|
3122
2895
|
};
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
2896
|
+
const launchSharedProcess = async ({
|
|
2897
|
+
env = {},
|
|
2898
|
+
method
|
|
2899
|
+
}) => {
|
|
2900
|
+
mark(WillStartSharedProcess);
|
|
2901
|
+
const sharedProcessPath = getSharedProcessPath();
|
|
2902
|
+
const execArgv = getSharedProcessArgv();
|
|
2903
|
+
const fullEnv = {
|
|
2904
|
+
...process.env,
|
|
2905
|
+
...env
|
|
3131
2906
|
};
|
|
3132
|
-
|
|
2907
|
+
const sharedProcessRpc = await create$5({
|
|
2908
|
+
argv: [],
|
|
2909
|
+
commandMap: commandMapRef,
|
|
2910
|
+
env: fullEnv,
|
|
2911
|
+
execArgv,
|
|
2912
|
+
name: 'shared-process',
|
|
2913
|
+
path: sharedProcessPath,
|
|
2914
|
+
// @ts-ignore
|
|
2915
|
+
requiresSocket: requiresSocket
|
|
2916
|
+
});
|
|
3133
2917
|
|
|
3134
|
-
|
|
3135
|
-
const
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
};
|
|
2918
|
+
// @ts-ignore
|
|
2919
|
+
const sharedProcess = sharedProcessRpc.ipc;
|
|
2920
|
+
// @ts-ignore
|
|
2921
|
+
sharedProcess._rawIpc.on('error', handleChildError);
|
|
2922
|
+
// @ts-ignore
|
|
2923
|
+
sharedProcess._rawIpc.on('exit', handleChildExit);
|
|
2924
|
+
// @ts-ignore
|
|
2925
|
+
sharedProcess._rawIpc.on('disconnect', handleChildDisconnect);
|
|
3143
2926
|
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
2927
|
+
// create secondary ipc to support transferring objects
|
|
2928
|
+
// from shared process to main process
|
|
2929
|
+
// TODO let shared process ask for secondary
|
|
2930
|
+
// ipc instead of sending it directly?
|
|
2931
|
+
const {
|
|
2932
|
+
port1,
|
|
2933
|
+
port2
|
|
2934
|
+
} = getPortTuple();
|
|
2935
|
+
await sharedProcessRpc.invokeAndTransfer('HandleElectronMessagePort.handleElectronMessagePort', port2, MainProcess);
|
|
2936
|
+
await create$8({
|
|
2937
|
+
commandMap: commandMapRef,
|
|
2938
|
+
messagePort: port1,
|
|
2939
|
+
requiresSocket: requiresSocket
|
|
2940
|
+
});
|
|
2941
|
+
mark(DidStartSharedProcess);
|
|
2942
|
+
return sharedProcessRpc;
|
|
3147
2943
|
};
|
|
3148
2944
|
|
|
3149
|
-
const
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
} = Promise.withResolvers();
|
|
3155
|
-
map[id] = resolve;
|
|
3156
|
-
return {
|
|
3157
|
-
id,
|
|
3158
|
-
promise
|
|
3159
|
-
};
|
|
2945
|
+
const state$5 = {
|
|
2946
|
+
/**
|
|
2947
|
+
* @type {any}
|
|
2948
|
+
*/
|
|
2949
|
+
promise: undefined
|
|
3160
2950
|
};
|
|
3161
2951
|
|
|
3162
|
-
const
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
2952
|
+
const getOrCreate = async ({
|
|
2953
|
+
env = {},
|
|
2954
|
+
method
|
|
2955
|
+
}) => {
|
|
2956
|
+
if (!state$5.promise) {
|
|
2957
|
+
// @ts-ignore
|
|
2958
|
+
state$5.promise = launchSharedProcess({
|
|
2959
|
+
env,
|
|
2960
|
+
method
|
|
2961
|
+
});
|
|
3172
2962
|
}
|
|
3173
|
-
|
|
3174
|
-
return unwrapJsonRpcResult(responseMessage);
|
|
2963
|
+
return state$5.promise;
|
|
3175
2964
|
};
|
|
3176
|
-
const
|
|
3177
|
-
const
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
send(method, ...params) {
|
|
3203
|
-
const message = create$8(method, params);
|
|
3204
|
-
ipc.send(message);
|
|
2965
|
+
const send$1 = async (method, ...params) => {
|
|
2966
|
+
const rpc = await getOrCreate({
|
|
2967
|
+
method: ElectronUtilityProcess$1
|
|
2968
|
+
});
|
|
2969
|
+
rpc.send(method, ...params);
|
|
2970
|
+
};
|
|
2971
|
+
const invoke = async (method, ...params) => {
|
|
2972
|
+
const rpc = await getOrCreate({
|
|
2973
|
+
method: ElectronUtilityProcess$1
|
|
2974
|
+
});
|
|
2975
|
+
return rpc.invoke(method, ...params);
|
|
2976
|
+
};
|
|
2977
|
+
const invokeAndTransfer = async (method, ...params) => {
|
|
2978
|
+
const rpc = await getOrCreate({
|
|
2979
|
+
method: ElectronUtilityProcess$1
|
|
2980
|
+
});
|
|
2981
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
2982
|
+
};
|
|
2983
|
+
|
|
2984
|
+
const handleCliArgs = async parsedArgs => {
|
|
2985
|
+
try {
|
|
2986
|
+
await invoke('HandleCliArgs.handleCliArgs', parsedArgs);
|
|
2987
|
+
} catch (error) {
|
|
2988
|
+
setExitCode(Error$3);
|
|
2989
|
+
if (error && error instanceof Error && error.stack && error.stack.includes('shared-process')) ; else {
|
|
2990
|
+
handleError(error);
|
|
3205
2991
|
}
|
|
3206
|
-
}
|
|
3207
|
-
|
|
2992
|
+
} finally {
|
|
2993
|
+
exit();
|
|
2994
|
+
}
|
|
3208
2995
|
};
|
|
3209
2996
|
|
|
3210
|
-
const
|
|
3211
|
-
|
|
2997
|
+
const CliForwardToSharedProcess = {
|
|
2998
|
+
__proto__: null,
|
|
2999
|
+
handleCliArgs
|
|
3212
3000
|
};
|
|
3213
|
-
|
|
3214
|
-
|
|
3001
|
+
|
|
3002
|
+
const SharedProcess = 4;
|
|
3003
|
+
const None = 0;
|
|
3004
|
+
|
|
3005
|
+
const on = (event, listener) => {
|
|
3006
|
+
app.on(event, listener);
|
|
3215
3007
|
};
|
|
3216
|
-
const
|
|
3217
|
-
|
|
3008
|
+
const whenReady = () => {
|
|
3009
|
+
return app.whenReady();
|
|
3218
3010
|
};
|
|
3219
|
-
const
|
|
3220
|
-
|
|
3221
|
-
const actualExecute = event?.target?.execute || execute$1;
|
|
3222
|
-
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError$1, actualRequiresSocket);
|
|
3011
|
+
const appendCommandLineSwitch = (commandLineSwitch, value) => {
|
|
3012
|
+
app.commandLine.appendSwitch(commandLineSwitch, value);
|
|
3223
3013
|
};
|
|
3224
3014
|
|
|
3225
|
-
const
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3015
|
+
const Version = 'version';
|
|
3016
|
+
const Help = 'help';
|
|
3017
|
+
const Wait = 'wait';
|
|
3018
|
+
const BuiltinSelfTest = 'built-in-self-test';
|
|
3019
|
+
const Web = 'web';
|
|
3020
|
+
const SandBox = 'sandbox';
|
|
3021
|
+
const Install = 'install';
|
|
3022
|
+
const List = 'list';
|
|
3023
|
+
const Link = 'link';
|
|
3024
|
+
const Unlink = 'unlink';
|
|
3025
|
+
const Status = 'status';
|
|
3233
3026
|
|
|
3234
|
-
const
|
|
3235
|
-
const
|
|
3236
|
-
if (
|
|
3237
|
-
|
|
3027
|
+
const getCliModuleId = parsedArgs => {
|
|
3028
|
+
const arg0 = parsedArgs._[0];
|
|
3029
|
+
if (arg0 === Install || arg0 === List || arg0 === Link || arg0 === Unlink || parsedArgs[Status] || parsedArgs[Version] || parsedArgs[Help] || parsedArgs[Web] || parsedArgs[BuiltinSelfTest]) {
|
|
3030
|
+
return SharedProcess;
|
|
3238
3031
|
}
|
|
3239
|
-
|
|
3240
|
-
return ipc;
|
|
3032
|
+
return None;
|
|
3241
3033
|
};
|
|
3242
3034
|
|
|
3243
|
-
const
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
register(commandMap);
|
|
3250
|
-
const ipc = await listen$1(IpcChildWithElectronMessagePort$1, {
|
|
3251
|
-
messagePort
|
|
3252
|
-
});
|
|
3253
|
-
if (requiresSocket) {
|
|
3254
|
-
ipc.requiresSocket = requiresSocket;
|
|
3035
|
+
const getModule$3 = moduleId => {
|
|
3036
|
+
switch (moduleId) {
|
|
3037
|
+
case SharedProcess:
|
|
3038
|
+
return CliForwardToSharedProcess;
|
|
3039
|
+
default:
|
|
3040
|
+
throw new Error('module not found');
|
|
3255
3041
|
}
|
|
3256
|
-
handleIpc$1(ipc);
|
|
3257
|
-
const rpc = createRpc(ipc);
|
|
3258
|
-
return rpc;
|
|
3259
3042
|
};
|
|
3260
|
-
|
|
3261
|
-
const
|
|
3262
|
-
|
|
3263
|
-
commandMap,
|
|
3264
|
-
env,
|
|
3265
|
-
execArgv,
|
|
3266
|
-
name,
|
|
3267
|
-
path,
|
|
3268
|
-
requiresSocket
|
|
3269
|
-
}) => {
|
|
3270
|
-
// TODO create a commandMap per rpc instance
|
|
3271
|
-
register(commandMap);
|
|
3272
|
-
const rawIpc = await IpcParentWithElectronUtilityProcess$1$1.create({
|
|
3273
|
-
argv,
|
|
3274
|
-
env,
|
|
3275
|
-
execArgv,
|
|
3276
|
-
name,
|
|
3277
|
-
path
|
|
3278
|
-
});
|
|
3279
|
-
const ipc = IpcParentWithElectronUtilityProcess$1$1.wrap(rawIpc);
|
|
3280
|
-
if (requiresSocket) {
|
|
3281
|
-
// @ts-ignore
|
|
3282
|
-
ipc.requiresSocket = requiresSocket;
|
|
3283
|
-
}
|
|
3284
|
-
handleIpc$1(ipc);
|
|
3285
|
-
const rpc = createRpc(ipc);
|
|
3286
|
-
return rpc;
|
|
3043
|
+
const handleArgs = (moduleId, parsedArgs) => {
|
|
3044
|
+
const module = getModule$3(moduleId);
|
|
3045
|
+
return module.handleCliArgs(parsedArgs);
|
|
3287
3046
|
};
|
|
3288
|
-
|
|
3289
|
-
const
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
const ipc = IpcChildWithRendererProcess2$1.wrap(webContents);
|
|
3297
|
-
if (requiresSocket) {
|
|
3298
|
-
// @ts-ignore
|
|
3299
|
-
ipc.requiresSocket = requiresSocket;
|
|
3047
|
+
const canHandleFastCliArgs = parsedArgs => {
|
|
3048
|
+
const moduleId = getCliModuleId(parsedArgs);
|
|
3049
|
+
return moduleId;
|
|
3050
|
+
};
|
|
3051
|
+
const handleFastCliArgs = async (moduleId, parsedArgs) => {
|
|
3052
|
+
if (moduleId) {
|
|
3053
|
+
await whenReady();
|
|
3054
|
+
return handleArgs(moduleId, parsedArgs);
|
|
3300
3055
|
}
|
|
3301
|
-
|
|
3302
|
-
const rpc = createRpc(ipc);
|
|
3303
|
-
return rpc;
|
|
3056
|
+
return false;
|
|
3304
3057
|
};
|
|
3305
3058
|
|
|
3306
|
-
const
|
|
3059
|
+
const setLocale = locale => {
|
|
3060
|
+
app.commandLine.appendSwitch('lang', locale);
|
|
3061
|
+
};
|
|
3307
3062
|
|
|
3308
|
-
const
|
|
3309
|
-
|
|
3310
|
-
port1,
|
|
3311
|
-
port2
|
|
3312
|
-
} = new MessageChannelMain();
|
|
3313
|
-
return {
|
|
3314
|
-
port1,
|
|
3315
|
-
port2
|
|
3316
|
-
};
|
|
3063
|
+
const enableSandbox = () => {
|
|
3064
|
+
app.enableSandbox();
|
|
3317
3065
|
};
|
|
3318
3066
|
|
|
3319
|
-
const
|
|
3320
|
-
|
|
3067
|
+
const enable$1 = parsedCliArgs => {
|
|
3068
|
+
// command line switches
|
|
3069
|
+
if (parsedCliArgs.sandbox) {
|
|
3070
|
+
enableSandbox();
|
|
3071
|
+
} else {
|
|
3072
|
+
// see https://github.com/microsoft/vscode/issues/151187#issuecomment-1221475319
|
|
3073
|
+
if (isLinux) {
|
|
3074
|
+
// @ts-ignore
|
|
3075
|
+
appendCommandLineSwitch('--disable-gpu-sandbox');
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
setLocale('en');
|
|
3321
3079
|
};
|
|
3322
3080
|
|
|
3323
|
-
const
|
|
3324
|
-
const
|
|
3081
|
+
const BeforeQuit = 'before-quit';
|
|
3082
|
+
const SecondInstance = 'second-instance';
|
|
3083
|
+
const WindowAllClosed = 'window-all-closed';
|
|
3084
|
+
const WebContentsCreated = 'web-contents-created';
|
|
3325
3085
|
|
|
3326
|
-
|
|
3327
|
-
|
|
3086
|
+
/* eslint-disable @typescript-eslint/no-misused-promises */
|
|
3087
|
+
const setMenu = menu => {
|
|
3088
|
+
Menu.setApplicationMenu(menu);
|
|
3328
3089
|
};
|
|
3329
|
-
const
|
|
3090
|
+
const click = async (menuItem, browserWindow, keys) => {
|
|
3091
|
+
if (!browserWindow) {
|
|
3092
|
+
return;
|
|
3093
|
+
}
|
|
3094
|
+
await send$1('TitleBar.handleElectronMenuClick', browserWindow.id, menuItem.label);
|
|
3095
|
+
};
|
|
3096
|
+
const addClickListener = item => {
|
|
3097
|
+
if (item.submenu) {
|
|
3098
|
+
return {
|
|
3099
|
+
...item,
|
|
3100
|
+
click,
|
|
3101
|
+
submenu: item.submenu.map(addClickListener)
|
|
3102
|
+
};
|
|
3103
|
+
}
|
|
3330
3104
|
return {
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
name: performanceEntry.name,
|
|
3335
|
-
startTime: performanceEntry.startTime
|
|
3105
|
+
...item,
|
|
3106
|
+
click,
|
|
3107
|
+
submenu: undefined
|
|
3336
3108
|
};
|
|
3337
3109
|
};
|
|
3338
|
-
const
|
|
3339
|
-
|
|
3340
|
-
const
|
|
3341
|
-
|
|
3110
|
+
const setItems = items => {
|
|
3111
|
+
array(items);
|
|
3112
|
+
const itemsWithClickListeners = items.map(addClickListener);
|
|
3113
|
+
const menu = Menu.buildFromTemplate(itemsWithClickListeners);
|
|
3114
|
+
setMenu(menu);
|
|
3342
3115
|
};
|
|
3343
|
-
const {
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
const Performance = {
|
|
3348
|
-
__proto__: null,
|
|
3349
|
-
getEntries,
|
|
3350
|
-
mark,
|
|
3351
|
-
timeOrigin
|
|
3352
|
-
};
|
|
3353
|
-
|
|
3354
|
-
const WillLoadUrl = 'code/willLoadUrl';
|
|
3355
|
-
const DidLoadUrl = 'code/didLoadUrl';
|
|
3356
|
-
const AppReady = 'code/appReady';
|
|
3357
|
-
const WillStartSharedProcess = 'code/willStartSharedProcess';
|
|
3358
|
-
const DidStartSharedProcess = 'code/didStartSharedProcess';
|
|
3359
|
-
const WillCreateCodeWindow = 'code/willCreateCodeWindow';
|
|
3360
|
-
const DidCreateCodeWindow = 'code/didCreateCodeWindow';
|
|
3361
|
-
|
|
3362
|
-
const join = (...paths) => {
|
|
3363
|
-
return NodePath.join(...paths);
|
|
3364
|
-
};
|
|
3365
|
-
|
|
3366
|
-
const __dirname$1 = dirname(fileURLToPath(import.meta.url));
|
|
3367
|
-
const root = process.env.LVCE_ROOT || join(__dirname$1, '../../../../..');
|
|
3368
|
-
|
|
3369
|
-
const {
|
|
3370
|
-
env,
|
|
3371
|
-
platform
|
|
3372
|
-
} = process;
|
|
3373
|
-
const isLinux = platform === 'linux';
|
|
3374
|
-
const isProduction = false;
|
|
3375
|
-
const homeDirectory = homedir();
|
|
3376
|
-
|
|
3377
|
-
const xdgCache = env.XDG_CACHE_HOME || (homeDirectory ? join(homeDirectory, '.cache') : undefined);
|
|
3378
|
-
const xdgData = env.XDG_DATA_HOME || (homeDirectory ? join(homeDirectory, '.local', 'share') : undefined);
|
|
3379
|
-
join(xdgData || tmpdir(), applicationName);
|
|
3380
|
-
const chromeUserDataPath = xdgCache ? join(xdgCache, applicationName, 'userdata') : '';
|
|
3381
|
-
|
|
3382
|
-
const useIpcForResponse = true;
|
|
3383
|
-
const getSessionId = () => {
|
|
3384
|
-
return process.env.SESSION_ID || `persist:${scheme}`;
|
|
3385
|
-
};
|
|
3386
|
-
const getSharedProcessPath = () => {
|
|
3387
|
-
if (process.env.LVCE_SHARED_PROCESS_PATH) {
|
|
3388
|
-
return process.env.LVCE_SHARED_PROCESS_PATH;
|
|
3389
|
-
}
|
|
3390
|
-
return join(root, 'packages', 'shared-process', 'src', 'sharedProcessMain.ts');
|
|
3391
|
-
};
|
|
3392
|
-
|
|
3393
|
-
const requiresSocket = () => {
|
|
3394
|
-
return false;
|
|
3395
|
-
};
|
|
3396
|
-
|
|
3397
|
-
const handleChildError = error => {
|
|
3398
|
-
exit$1(Error$3);
|
|
3399
|
-
};
|
|
3400
|
-
const handleChildExit = code => {
|
|
3401
|
-
info(`[main process] shared process exited with code ${code}`);
|
|
3402
|
-
exit$1(code);
|
|
3403
|
-
};
|
|
3404
|
-
const handleChildDisconnect = () => {
|
|
3405
|
-
info('[main process] shared process disconnected');
|
|
3406
|
-
};
|
|
3407
|
-
const launchSharedProcess = async ({
|
|
3408
|
-
env = {},
|
|
3409
|
-
method
|
|
3410
|
-
}) => {
|
|
3411
|
-
mark(WillStartSharedProcess);
|
|
3412
|
-
const sharedProcessPath = getSharedProcessPath();
|
|
3413
|
-
const execArgv = getSharedProcessArgv();
|
|
3414
|
-
const fullEnv = {
|
|
3415
|
-
...process.env,
|
|
3416
|
-
...env
|
|
3417
|
-
};
|
|
3418
|
-
const sharedProcessRpc = await create$4({
|
|
3419
|
-
argv: [],
|
|
3420
|
-
commandMap: commandMapRef,
|
|
3421
|
-
env: fullEnv,
|
|
3422
|
-
execArgv,
|
|
3423
|
-
name: 'shared-process',
|
|
3424
|
-
path: sharedProcessPath,
|
|
3425
|
-
// @ts-ignore
|
|
3426
|
-
requiresSocket: requiresSocket
|
|
3427
|
-
});
|
|
3428
|
-
|
|
3429
|
-
// @ts-ignore
|
|
3430
|
-
const sharedProcess = sharedProcessRpc.ipc;
|
|
3431
|
-
// @ts-ignore
|
|
3432
|
-
sharedProcess._rawIpc.on('error', handleChildError);
|
|
3433
|
-
// @ts-ignore
|
|
3434
|
-
sharedProcess._rawIpc.on('exit', handleChildExit);
|
|
3435
|
-
// @ts-ignore
|
|
3436
|
-
sharedProcess._rawIpc.on('disconnect', handleChildDisconnect);
|
|
3437
|
-
|
|
3438
|
-
// create secondary ipc to support transferring objects
|
|
3439
|
-
// from shared process to main process
|
|
3440
|
-
// TODO let shared process ask for secondary
|
|
3441
|
-
// ipc instead of sending it directly?
|
|
3442
|
-
const {
|
|
3443
|
-
port1,
|
|
3444
|
-
port2
|
|
3445
|
-
} = getPortTuple();
|
|
3446
|
-
await sharedProcessRpc.invokeAndTransfer('HandleElectronMessagePort.handleElectronMessagePort', port2, MainProcess);
|
|
3447
|
-
await create$5({
|
|
3448
|
-
commandMap: commandMapRef,
|
|
3449
|
-
messagePort: port1,
|
|
3450
|
-
requiresSocket: requiresSocket
|
|
3451
|
-
});
|
|
3452
|
-
mark(DidStartSharedProcess);
|
|
3453
|
-
return sharedProcessRpc;
|
|
3454
|
-
};
|
|
3455
|
-
|
|
3456
|
-
const state$5 = {
|
|
3457
|
-
/**
|
|
3458
|
-
* @type {any}
|
|
3459
|
-
*/
|
|
3460
|
-
promise: undefined
|
|
3461
|
-
};
|
|
3462
|
-
|
|
3463
|
-
const getOrCreate = async ({
|
|
3464
|
-
env = {},
|
|
3465
|
-
method
|
|
3466
|
-
}) => {
|
|
3467
|
-
if (!state$5.promise) {
|
|
3468
|
-
// @ts-ignore
|
|
3469
|
-
state$5.promise = launchSharedProcess({
|
|
3470
|
-
env,
|
|
3471
|
-
method
|
|
3472
|
-
});
|
|
3473
|
-
}
|
|
3474
|
-
return state$5.promise;
|
|
3475
|
-
};
|
|
3476
|
-
const send$1 = async (method, ...params) => {
|
|
3477
|
-
const rpc = await getOrCreate({
|
|
3478
|
-
method: ElectronUtilityProcess$1
|
|
3479
|
-
});
|
|
3480
|
-
rpc.send(method, ...params);
|
|
3481
|
-
};
|
|
3482
|
-
const invoke = async (method, ...params) => {
|
|
3483
|
-
const rpc = await getOrCreate({
|
|
3484
|
-
method: ElectronUtilityProcess$1
|
|
3485
|
-
});
|
|
3486
|
-
return rpc.invoke(method, ...params);
|
|
3487
|
-
};
|
|
3488
|
-
const invokeAndTransfer = async (method, ...params) => {
|
|
3489
|
-
const rpc = await getOrCreate({
|
|
3490
|
-
method: ElectronUtilityProcess$1
|
|
3491
|
-
});
|
|
3492
|
-
return rpc.invokeAndTransfer(method, ...params);
|
|
3493
|
-
};
|
|
3494
|
-
|
|
3495
|
-
const handleCliArgs = async parsedArgs => {
|
|
3496
|
-
try {
|
|
3497
|
-
await invoke('HandleCliArgs.handleCliArgs', parsedArgs);
|
|
3498
|
-
} catch (error) {
|
|
3499
|
-
setExitCode(Error$3);
|
|
3500
|
-
if (error && error instanceof Error && error.stack && error.stack.includes('shared-process')) ; else {
|
|
3501
|
-
handleError(error);
|
|
3502
|
-
}
|
|
3503
|
-
} finally {
|
|
3504
|
-
exit();
|
|
3505
|
-
}
|
|
3506
|
-
};
|
|
3507
|
-
|
|
3508
|
-
const CliForwardToSharedProcess = {
|
|
3509
|
-
__proto__: null,
|
|
3510
|
-
handleCliArgs
|
|
3116
|
+
const createTitleBar = items => {
|
|
3117
|
+
const menuBar = Menu.buildFromTemplate(items);
|
|
3118
|
+
return menuBar;
|
|
3511
3119
|
};
|
|
3512
3120
|
|
|
3513
|
-
const
|
|
3514
|
-
const
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
app.on(event, listener);
|
|
3518
|
-
};
|
|
3519
|
-
const whenReady = () => {
|
|
3520
|
-
return app.whenReady();
|
|
3121
|
+
const PHASE_DEFAULT = 0;
|
|
3122
|
+
const PHASE_SHUTDOWN = -1;
|
|
3123
|
+
const state$4 = {
|
|
3124
|
+
phase: PHASE_DEFAULT
|
|
3521
3125
|
};
|
|
3522
|
-
const
|
|
3523
|
-
|
|
3126
|
+
const isShutDown = () => {
|
|
3127
|
+
return state$4.phase === PHASE_SHUTDOWN;
|
|
3524
3128
|
};
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
const Help = 'help';
|
|
3528
|
-
const Wait = 'wait';
|
|
3529
|
-
const BuiltinSelfTest = 'built-in-self-test';
|
|
3530
|
-
const Web = 'web';
|
|
3531
|
-
const SandBox = 'sandbox';
|
|
3532
|
-
const Install = 'install';
|
|
3533
|
-
const List = 'list';
|
|
3534
|
-
const Link = 'link';
|
|
3535
|
-
const Unlink = 'unlink';
|
|
3536
|
-
const Status = 'status';
|
|
3537
|
-
|
|
3538
|
-
const getCliModuleId = parsedArgs => {
|
|
3539
|
-
const arg0 = parsedArgs._[0];
|
|
3540
|
-
if (arg0 === Install || arg0 === List || arg0 === Link || arg0 === Unlink || parsedArgs[Status] || parsedArgs[Version] || parsedArgs[Help] || parsedArgs[Web] || parsedArgs[BuiltinSelfTest]) {
|
|
3541
|
-
return SharedProcess;
|
|
3542
|
-
}
|
|
3543
|
-
return None;
|
|
3129
|
+
const setShutDown = () => {
|
|
3130
|
+
state$4.phase = PHASE_SHUTDOWN;
|
|
3544
3131
|
};
|
|
3545
3132
|
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
return CliForwardToSharedProcess;
|
|
3550
|
-
default:
|
|
3551
|
-
throw new Error('module not found');
|
|
3552
|
-
}
|
|
3553
|
-
};
|
|
3554
|
-
const handleArgs = (moduleId, parsedArgs) => {
|
|
3555
|
-
const module = getModule$3(moduleId);
|
|
3556
|
-
return module.handleCliArgs(parsedArgs);
|
|
3557
|
-
};
|
|
3558
|
-
const canHandleFastCliArgs = parsedArgs => {
|
|
3559
|
-
const moduleId = getCliModuleId(parsedArgs);
|
|
3560
|
-
return moduleId;
|
|
3561
|
-
};
|
|
3562
|
-
const handleFastCliArgs = async (moduleId, parsedArgs) => {
|
|
3563
|
-
if (moduleId) {
|
|
3564
|
-
await whenReady();
|
|
3565
|
-
return handleArgs(moduleId, parsedArgs);
|
|
3566
|
-
}
|
|
3567
|
-
return false;
|
|
3133
|
+
// TODO move this function to shared process
|
|
3134
|
+
const handleBeforeQuit = () => {
|
|
3135
|
+
setShutDown();
|
|
3568
3136
|
};
|
|
3569
3137
|
|
|
3570
|
-
const
|
|
3571
|
-
|
|
3138
|
+
const handleReady = async (parsedArgs, workingDirectory) => {
|
|
3139
|
+
await invoke('HandleElectronReady.handleElectronReady', parsedArgs, workingDirectory);
|
|
3572
3140
|
};
|
|
3573
3141
|
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
};
|
|
3142
|
+
var minimist$1;
|
|
3143
|
+
var hasRequiredMinimist;
|
|
3577
3144
|
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
enableSandbox();
|
|
3582
|
-
} else {
|
|
3583
|
-
// see https://github.com/microsoft/vscode/issues/151187#issuecomment-1221475319
|
|
3584
|
-
if (isLinux) {
|
|
3585
|
-
// @ts-ignore
|
|
3586
|
-
appendCommandLineSwitch('--disable-gpu-sandbox');
|
|
3587
|
-
}
|
|
3588
|
-
}
|
|
3589
|
-
setLocale('en');
|
|
3590
|
-
};
|
|
3591
|
-
|
|
3592
|
-
const BeforeQuit = 'before-quit';
|
|
3593
|
-
const SecondInstance = 'second-instance';
|
|
3594
|
-
const WindowAllClosed = 'window-all-closed';
|
|
3595
|
-
const WebContentsCreated = 'web-contents-created';
|
|
3596
|
-
|
|
3597
|
-
/* eslint-disable @typescript-eslint/no-misused-promises */
|
|
3598
|
-
const setMenu = menu => {
|
|
3599
|
-
Menu.setApplicationMenu(menu);
|
|
3600
|
-
};
|
|
3601
|
-
const click = async (menuItem, browserWindow, keys) => {
|
|
3602
|
-
if (!browserWindow) {
|
|
3603
|
-
return;
|
|
3604
|
-
}
|
|
3605
|
-
await send$1('TitleBar.handleElectronMenuClick', browserWindow.id, menuItem.label);
|
|
3606
|
-
};
|
|
3607
|
-
const addClickListener = item => {
|
|
3608
|
-
if (item.submenu) {
|
|
3609
|
-
return {
|
|
3610
|
-
...item,
|
|
3611
|
-
click,
|
|
3612
|
-
submenu: item.submenu.map(addClickListener)
|
|
3613
|
-
};
|
|
3614
|
-
}
|
|
3615
|
-
return {
|
|
3616
|
-
...item,
|
|
3617
|
-
click,
|
|
3618
|
-
submenu: undefined
|
|
3619
|
-
};
|
|
3620
|
-
};
|
|
3621
|
-
const setItems = items => {
|
|
3622
|
-
array(items);
|
|
3623
|
-
const itemsWithClickListeners = items.map(addClickListener);
|
|
3624
|
-
const menu = Menu.buildFromTemplate(itemsWithClickListeners);
|
|
3625
|
-
setMenu(menu);
|
|
3626
|
-
};
|
|
3627
|
-
const createTitleBar = items => {
|
|
3628
|
-
const menuBar = Menu.buildFromTemplate(items);
|
|
3629
|
-
return menuBar;
|
|
3630
|
-
};
|
|
3631
|
-
|
|
3632
|
-
const PHASE_DEFAULT = 0;
|
|
3633
|
-
const PHASE_SHUTDOWN = -1;
|
|
3634
|
-
const state$4 = {
|
|
3635
|
-
phase: PHASE_DEFAULT
|
|
3636
|
-
};
|
|
3637
|
-
const isShutDown = () => {
|
|
3638
|
-
return state$4.phase === PHASE_SHUTDOWN;
|
|
3639
|
-
};
|
|
3640
|
-
const setShutDown = () => {
|
|
3641
|
-
state$4.phase = PHASE_SHUTDOWN;
|
|
3642
|
-
};
|
|
3643
|
-
|
|
3644
|
-
// TODO move this function to shared process
|
|
3645
|
-
const handleBeforeQuit = () => {
|
|
3646
|
-
setShutDown();
|
|
3647
|
-
};
|
|
3648
|
-
|
|
3649
|
-
const handleReady = async (parsedArgs, workingDirectory) => {
|
|
3650
|
-
await invoke('HandleElectronReady.handleElectronReady', parsedArgs, workingDirectory);
|
|
3651
|
-
};
|
|
3652
|
-
|
|
3653
|
-
var minimist$1;
|
|
3654
|
-
var hasRequiredMinimist;
|
|
3655
|
-
|
|
3656
|
-
function requireMinimist () {
|
|
3657
|
-
if (hasRequiredMinimist) return minimist$1;
|
|
3658
|
-
hasRequiredMinimist = 1;
|
|
3145
|
+
function requireMinimist () {
|
|
3146
|
+
if (hasRequiredMinimist) return minimist$1;
|
|
3147
|
+
hasRequiredMinimist = 1;
|
|
3659
3148
|
|
|
3660
3149
|
function hasKey(obj, keys) {
|
|
3661
3150
|
var o = obj;
|
|
@@ -3924,10 +3413,7 @@ const Allow = 'allow';
|
|
|
3924
3413
|
const Deny = 'deny';
|
|
3925
3414
|
|
|
3926
3415
|
const shouldOpenExternal = url => {
|
|
3927
|
-
|
|
3928
|
-
return true;
|
|
3929
|
-
}
|
|
3930
|
-
return false;
|
|
3416
|
+
return url.startsWith('http:') || url.startsWith('https:');
|
|
3931
3417
|
};
|
|
3932
3418
|
|
|
3933
3419
|
const openExternal = async url => {
|
|
@@ -3976,10 +3462,7 @@ const setCanceled = id => {
|
|
|
3976
3462
|
};
|
|
3977
3463
|
|
|
3978
3464
|
const shouldAllowNavigation = webContentsId => {
|
|
3979
|
-
|
|
3980
|
-
return true;
|
|
3981
|
-
}
|
|
3982
|
-
return false;
|
|
3465
|
+
return hasWebContents(webContentsId);
|
|
3983
3466
|
};
|
|
3984
3467
|
|
|
3985
3468
|
const handleWebContentsWindowOpen = ({
|
|
@@ -4019,10 +3502,7 @@ const handleWindowAllClosed = async () => {
|
|
|
4019
3502
|
};
|
|
4020
3503
|
|
|
4021
3504
|
const isProtocolHandleApiSupported = protocol => {
|
|
4022
|
-
|
|
4023
|
-
return true;
|
|
4024
|
-
}
|
|
4025
|
-
return false;
|
|
3505
|
+
return !!protocol.handle;
|
|
4026
3506
|
};
|
|
4027
3507
|
|
|
4028
3508
|
|
|
@@ -4231,10 +3711,10 @@ const getElectronFileResponseConfig = async (url, request) => {
|
|
|
4231
3711
|
return getElectronFileResponseIpc(url, request);
|
|
4232
3712
|
}
|
|
4233
3713
|
const actual = getActualPath(relative);
|
|
4234
|
-
|
|
4235
|
-
if (match === undefined) {
|
|
3714
|
+
if (!(actual in files)) {
|
|
4236
3715
|
return getNotFoundResponse();
|
|
4237
3716
|
}
|
|
3717
|
+
const match = files[actual];
|
|
4238
3718
|
const responseHeaders = headers[match];
|
|
4239
3719
|
const absolutePath = getAbsolutePath(actual);
|
|
4240
3720
|
if (!existsSync(absolutePath)) {
|
|
@@ -4308,7 +3788,7 @@ const set$1 = value => {
|
|
|
4308
3788
|
state$2.session = value;
|
|
4309
3789
|
};
|
|
4310
3790
|
|
|
4311
|
-
const create$
|
|
3791
|
+
const create$3 = rpc => {
|
|
4312
3792
|
const handleRequest = async request => {
|
|
4313
3793
|
const {
|
|
4314
3794
|
method,
|
|
@@ -4331,13 +3811,13 @@ const get$1 = () => {
|
|
|
4331
3811
|
};
|
|
4332
3812
|
const registerWebviewProtocol = async port => {
|
|
4333
3813
|
object(port);
|
|
4334
|
-
const rpc = await create$
|
|
3814
|
+
const rpc = await create$8({
|
|
4335
3815
|
commandMap: {},
|
|
4336
3816
|
messagePort: port,
|
|
4337
3817
|
requiresSocket: requiresSocket
|
|
4338
3818
|
});
|
|
4339
3819
|
const session = get$1();
|
|
4340
|
-
const handleRequest = create$
|
|
3820
|
+
const handleRequest = create$3(rpc);
|
|
4341
3821
|
handle(session.protocol, WebView, handleRequest);
|
|
4342
3822
|
};
|
|
4343
3823
|
|
|
@@ -4400,7 +3880,7 @@ const createAppWindow = async (windowOptions, parsedArgs, workingDirectory, titl
|
|
|
4400
3880
|
}
|
|
4401
3881
|
};
|
|
4402
3882
|
window.on('close', handleWindowClose);
|
|
4403
|
-
await create$
|
|
3883
|
+
await create$4({
|
|
4404
3884
|
commandMap: commandMapRef,
|
|
4405
3885
|
webContents: window.webContents
|
|
4406
3886
|
});
|
|
@@ -4540,7 +4020,6 @@ const getByName = name => {
|
|
|
4540
4020
|
|
|
4541
4021
|
const createPidMap = () => {
|
|
4542
4022
|
const browserWindows = BrowserWindow.getAllWindows();
|
|
4543
|
-
const browserViews = [];
|
|
4544
4023
|
const utilityProcesses = getAll();
|
|
4545
4024
|
const pidWindowMap = Object.create(null);
|
|
4546
4025
|
for (const browserWindow of browserWindows) {
|
|
@@ -4564,17 +4043,6 @@ const createPidMap = () => {
|
|
|
4564
4043
|
pidWindowMap[pid] = displayName;
|
|
4565
4044
|
}
|
|
4566
4045
|
}
|
|
4567
|
-
for (const {
|
|
4568
|
-
view
|
|
4569
|
-
} of browserViews) {
|
|
4570
|
-
// @ts-ignore
|
|
4571
|
-
const viewWebContents = view.webContents;
|
|
4572
|
-
const pid = viewWebContents.getOSProcessId();
|
|
4573
|
-
if (pid in pidWindowMap) {
|
|
4574
|
-
continue;
|
|
4575
|
-
}
|
|
4576
|
-
pidWindowMap[pid] = `hidden-browser-view-${viewWebContents.id}`;
|
|
4577
|
-
}
|
|
4578
4046
|
for (const [pid, value] of utilityProcesses) {
|
|
4579
4047
|
// @ts-ignore
|
|
4580
4048
|
pidWindowMap[pid] = value.name;
|
|
@@ -4591,7 +4059,7 @@ const get = id => {
|
|
|
4591
4059
|
};
|
|
4592
4060
|
|
|
4593
4061
|
const createUtilityProcessRpc = async options => {
|
|
4594
|
-
const rpc = await create$
|
|
4062
|
+
const rpc = await create$5({
|
|
4595
4063
|
commandMap: commandMapRef,
|
|
4596
4064
|
...options
|
|
4597
4065
|
});
|
|
@@ -4758,18 +4226,87 @@ const getWindowById = windowId => {
|
|
|
4758
4226
|
return Electron.BrowserWindow.fromId(windowId);
|
|
4759
4227
|
};
|
|
4760
4228
|
|
|
4761
|
-
const
|
|
4229
|
+
const devtoolsBeforeInputListeners = new WeakMap();
|
|
4230
|
+
const isToggleDevtoolsInput = input => {
|
|
4231
|
+
if (input.type !== 'keyDown') {
|
|
4232
|
+
return false;
|
|
4233
|
+
}
|
|
4234
|
+
if (!input.shift) {
|
|
4235
|
+
return false;
|
|
4236
|
+
}
|
|
4237
|
+
if (!input.control && !input.meta) {
|
|
4238
|
+
return false;
|
|
4239
|
+
}
|
|
4240
|
+
return input.code === 'KeyI' || input.key === 'I' || input.key === 'i';
|
|
4241
|
+
};
|
|
4242
|
+
const removeDevtoolsKeyListener = devtoolsWebContents => {
|
|
4243
|
+
const listener = devtoolsBeforeInputListeners.get(devtoolsWebContents);
|
|
4244
|
+
if (!listener) {
|
|
4245
|
+
return;
|
|
4246
|
+
}
|
|
4247
|
+
devtoolsBeforeInputListeners.delete(devtoolsWebContents);
|
|
4248
|
+
devtoolsWebContents.off('before-input-event', listener);
|
|
4249
|
+
};
|
|
4250
|
+
const attachDevtoolsKeyListener = browserWindow => {
|
|
4251
|
+
const devtoolsWebContents = browserWindow.webContents.devToolsWebContents;
|
|
4252
|
+
if (!devtoolsWebContents) {
|
|
4253
|
+
return;
|
|
4254
|
+
}
|
|
4255
|
+
if (devtoolsBeforeInputListeners.has(devtoolsWebContents)) {
|
|
4256
|
+
return;
|
|
4257
|
+
}
|
|
4258
|
+
const listener = (event, input) => {
|
|
4259
|
+
if (!isToggleDevtoolsInput(input)) {
|
|
4260
|
+
return;
|
|
4261
|
+
}
|
|
4262
|
+
event.preventDefault();
|
|
4263
|
+
browserWindow.webContents.closeDevTools();
|
|
4264
|
+
};
|
|
4265
|
+
devtoolsBeforeInputListeners.set(devtoolsWebContents, listener);
|
|
4266
|
+
devtoolsWebContents.on('before-input-event', listener);
|
|
4267
|
+
devtoolsWebContents.once('destroyed', () => {
|
|
4268
|
+
removeDevtoolsKeyListener(devtoolsWebContents);
|
|
4269
|
+
});
|
|
4270
|
+
browserWindow.webContents.once('devtools-closed', () => {
|
|
4271
|
+
removeDevtoolsKeyListener(devtoolsWebContents);
|
|
4272
|
+
});
|
|
4273
|
+
};
|
|
4274
|
+
const getBrowserWindow = browserWindowId => {
|
|
4762
4275
|
const browserWindow = getWindowById(browserWindowId);
|
|
4763
4276
|
if (!browserWindow) {
|
|
4764
4277
|
info(`[main-process] browser window not found ${browserWindow}`);
|
|
4278
|
+
return undefined;
|
|
4279
|
+
}
|
|
4280
|
+
return browserWindow;
|
|
4281
|
+
};
|
|
4282
|
+
const toggleDevtools = browserWindow => {
|
|
4283
|
+
if (browserWindow.webContents.isDevToolsOpened()) {
|
|
4284
|
+
browserWindow.webContents.closeDevTools();
|
|
4285
|
+
return;
|
|
4286
|
+
}
|
|
4287
|
+
if (browserWindow.webContents.devToolsWebContents) {
|
|
4288
|
+
attachDevtoolsKeyListener(browserWindow);
|
|
4289
|
+
} else {
|
|
4290
|
+
browserWindow.webContents.once('devtools-opened', () => {
|
|
4291
|
+
attachDevtoolsKeyListener(browserWindow);
|
|
4292
|
+
});
|
|
4293
|
+
}
|
|
4294
|
+
browserWindow.webContents.openDevTools();
|
|
4295
|
+
};
|
|
4296
|
+
const executeWindowFunction = (browserWindowId, key) => {
|
|
4297
|
+
const browserWindow = getBrowserWindow(browserWindowId);
|
|
4298
|
+
if (!browserWindow) {
|
|
4299
|
+
return;
|
|
4300
|
+
}
|
|
4301
|
+
if (key === 'toggleDevtools') {
|
|
4302
|
+
toggleDevtools(browserWindow);
|
|
4765
4303
|
return;
|
|
4766
4304
|
}
|
|
4767
4305
|
browserWindow[key]();
|
|
4768
4306
|
};
|
|
4769
4307
|
const executeWebContentsFunction = (browserWindowId, key, ...args) => {
|
|
4770
|
-
const browserWindow =
|
|
4308
|
+
const browserWindow = getBrowserWindow(browserWindowId);
|
|
4771
4309
|
if (!browserWindow) {
|
|
4772
|
-
info(`[main-process] browser window not found ${browserWindow}`);
|
|
4773
4310
|
return;
|
|
4774
4311
|
}
|
|
4775
4312
|
browserWindow.webContents[key](...args);
|
|
@@ -5206,187 +4743,98 @@ const Quote = 93;
|
|
|
5206
4743
|
const Star = 131;
|
|
5207
4744
|
const Plus = 132;
|
|
5208
4745
|
|
|
4746
|
+
const keyCodeMap = {
|
|
4747
|
+
[Backquote$1]: Backquote,
|
|
4748
|
+
[Backslash$1]: Backslash,
|
|
4749
|
+
[Backspace$1]: Backspace,
|
|
4750
|
+
[BracketLeft$1]: BracketLeft,
|
|
4751
|
+
[BracketRight$1]: BracketRight,
|
|
4752
|
+
[Comma$1]: Comma,
|
|
4753
|
+
[Delete$1]: Delete,
|
|
4754
|
+
[Digit0$1]: Digit0,
|
|
4755
|
+
[Digit1$1]: Digit1,
|
|
4756
|
+
[Digit2$1]: Digit2,
|
|
4757
|
+
[Digit3$1]: Digit3,
|
|
4758
|
+
[Digit4$1]: Digit4,
|
|
4759
|
+
[Digit5$1]: Digit5,
|
|
4760
|
+
[Digit6$1]: Digit6,
|
|
4761
|
+
[Digit7$1]: Digit7,
|
|
4762
|
+
[Digit8$1]: Digit8,
|
|
4763
|
+
[Digit9$1]: Digit9,
|
|
4764
|
+
[DownArrow$1]: DownArrow,
|
|
4765
|
+
[End$1]: End,
|
|
4766
|
+
[Enter$1]: Enter,
|
|
4767
|
+
[Equal$1]: Equal,
|
|
4768
|
+
[Escape$1]: Escape,
|
|
4769
|
+
[F1$1]: F1,
|
|
4770
|
+
[F10$1]: F10,
|
|
4771
|
+
[F11$1]: F11,
|
|
4772
|
+
[F12$1]: F12,
|
|
4773
|
+
[F13$1]: F13,
|
|
4774
|
+
[F14$1]: F14,
|
|
4775
|
+
[F15$1]: F15,
|
|
4776
|
+
[F16$1]: F16,
|
|
4777
|
+
[F17$1]: F17,
|
|
4778
|
+
[F18$1]: F18,
|
|
4779
|
+
[F19$1]: F19,
|
|
4780
|
+
[F2$1]: F2,
|
|
4781
|
+
[F20$1]: F20,
|
|
4782
|
+
[F21$1]: F21,
|
|
4783
|
+
[F22$1]: F22,
|
|
4784
|
+
[F23$1]: F23,
|
|
4785
|
+
[F24$1]: F24,
|
|
4786
|
+
[F3$1]: F3,
|
|
4787
|
+
[F4$1]: F4,
|
|
4788
|
+
[F5$1]: F5,
|
|
4789
|
+
[F6$1]: F6,
|
|
4790
|
+
[F7$1]: F7,
|
|
4791
|
+
[F8$1]: F8,
|
|
4792
|
+
[F9$1]: F9,
|
|
4793
|
+
[Home$1]: Home,
|
|
4794
|
+
[Insert$1]: Insert,
|
|
4795
|
+
[KeyA$1]: KeyA,
|
|
4796
|
+
[KeyB$1]: KeyB,
|
|
4797
|
+
[KeyC$1]: KeyC,
|
|
4798
|
+
[KeyD$1]: KeyD,
|
|
4799
|
+
[KeyE$1]: KeyE,
|
|
4800
|
+
[KeyF$1]: KeyF,
|
|
4801
|
+
[KeyG$1]: KeyG,
|
|
4802
|
+
[KeyH$1]: KeyH,
|
|
4803
|
+
[KeyI$1]: KeyI,
|
|
4804
|
+
[KeyJ$1]: KeyJ,
|
|
4805
|
+
[KeyK$1]: KeyK,
|
|
4806
|
+
[KeyL$1]: KeyL,
|
|
4807
|
+
[KeyM$1]: KeyM,
|
|
4808
|
+
[KeyN$1]: KeyN,
|
|
4809
|
+
[KeyO$1]: KeyO,
|
|
4810
|
+
[KeyP$1]: KeyP,
|
|
4811
|
+
[KeyQ$1]: KeyQ,
|
|
4812
|
+
[KeyR$1]: KeyR,
|
|
4813
|
+
[KeyS$1]: KeyS,
|
|
4814
|
+
[KeyT$1]: KeyT,
|
|
4815
|
+
[KeyU$1]: KeyU,
|
|
4816
|
+
[KeyV$1]: KeyV,
|
|
4817
|
+
[KeyW$1]: KeyW,
|
|
4818
|
+
[KeyX$1]: KeyX,
|
|
4819
|
+
[KeyY$1]: KeyY,
|
|
4820
|
+
[KeyZ$1]: KeyZ,
|
|
4821
|
+
[LeftArrow$1]: LeftArrow,
|
|
4822
|
+
[Minus$1]: Minus,
|
|
4823
|
+
[PageDown$1]: PageDown,
|
|
4824
|
+
[PageUp$1]: PageUp,
|
|
4825
|
+
[Period$1]: Period,
|
|
4826
|
+
[Plus$1]: Plus,
|
|
4827
|
+
[Quote$1]: Quote,
|
|
4828
|
+
[RightArrow$1]: RightArrow,
|
|
4829
|
+
[SemiColon$1]: SemiColon,
|
|
4830
|
+
[Slash$1]: Slash,
|
|
4831
|
+
[Space$2]: Space$1,
|
|
4832
|
+
[Star$1]: Star,
|
|
4833
|
+
[Tab$1]: Tab,
|
|
4834
|
+
[UpArrow$1]: UpArrow
|
|
4835
|
+
};
|
|
5209
4836
|
const getKeyCode = key => {
|
|
5210
|
-
|
|
5211
|
-
case Backquote$1:
|
|
5212
|
-
return Backquote;
|
|
5213
|
-
case Backslash$1:
|
|
5214
|
-
return Backslash;
|
|
5215
|
-
case Backspace$1:
|
|
5216
|
-
return Backspace;
|
|
5217
|
-
case BracketLeft$1:
|
|
5218
|
-
return BracketLeft;
|
|
5219
|
-
case BracketRight$1:
|
|
5220
|
-
return BracketRight;
|
|
5221
|
-
case Comma$1:
|
|
5222
|
-
return Comma;
|
|
5223
|
-
case Delete$1:
|
|
5224
|
-
return Delete;
|
|
5225
|
-
case Digit0$1:
|
|
5226
|
-
return Digit0;
|
|
5227
|
-
case Digit1$1:
|
|
5228
|
-
return Digit1;
|
|
5229
|
-
case Digit2$1:
|
|
5230
|
-
return Digit2;
|
|
5231
|
-
case Digit3$1:
|
|
5232
|
-
return Digit3;
|
|
5233
|
-
case Digit4$1:
|
|
5234
|
-
return Digit4;
|
|
5235
|
-
case Digit5$1:
|
|
5236
|
-
return Digit5;
|
|
5237
|
-
case Digit6$1:
|
|
5238
|
-
return Digit6;
|
|
5239
|
-
case Digit7$1:
|
|
5240
|
-
return Digit7;
|
|
5241
|
-
case Digit8$1:
|
|
5242
|
-
return Digit8;
|
|
5243
|
-
case Digit9$1:
|
|
5244
|
-
return Digit9;
|
|
5245
|
-
case DownArrow$1:
|
|
5246
|
-
return DownArrow;
|
|
5247
|
-
case End$1:
|
|
5248
|
-
return End;
|
|
5249
|
-
case Enter$1:
|
|
5250
|
-
return Enter;
|
|
5251
|
-
case Equal$1:
|
|
5252
|
-
return Equal;
|
|
5253
|
-
case Escape$1:
|
|
5254
|
-
return Escape;
|
|
5255
|
-
case F1$1:
|
|
5256
|
-
return F1;
|
|
5257
|
-
case F10$1:
|
|
5258
|
-
return F10;
|
|
5259
|
-
case F11$1:
|
|
5260
|
-
return F11;
|
|
5261
|
-
case F12$1:
|
|
5262
|
-
return F12;
|
|
5263
|
-
case F13$1:
|
|
5264
|
-
return F13;
|
|
5265
|
-
case F14$1:
|
|
5266
|
-
return F14;
|
|
5267
|
-
case F15$1:
|
|
5268
|
-
return F15;
|
|
5269
|
-
case F16$1:
|
|
5270
|
-
return F16;
|
|
5271
|
-
case F17$1:
|
|
5272
|
-
return F17;
|
|
5273
|
-
case F18$1:
|
|
5274
|
-
return F18;
|
|
5275
|
-
case F19$1:
|
|
5276
|
-
return F19;
|
|
5277
|
-
case F2$1:
|
|
5278
|
-
return F2;
|
|
5279
|
-
case F20$1:
|
|
5280
|
-
return F20;
|
|
5281
|
-
case F21$1:
|
|
5282
|
-
return F21;
|
|
5283
|
-
case F22$1:
|
|
5284
|
-
return F22;
|
|
5285
|
-
case F23$1:
|
|
5286
|
-
return F23;
|
|
5287
|
-
case F24$1:
|
|
5288
|
-
return F24;
|
|
5289
|
-
case F3$1:
|
|
5290
|
-
return F3;
|
|
5291
|
-
case F4$1:
|
|
5292
|
-
return F4;
|
|
5293
|
-
case F5$1:
|
|
5294
|
-
return F5;
|
|
5295
|
-
case F6$1:
|
|
5296
|
-
return F6;
|
|
5297
|
-
case F7$1:
|
|
5298
|
-
return F7;
|
|
5299
|
-
case F8$1:
|
|
5300
|
-
return F8;
|
|
5301
|
-
case F9$1:
|
|
5302
|
-
return F9;
|
|
5303
|
-
case Home$1:
|
|
5304
|
-
return Home;
|
|
5305
|
-
case Insert$1:
|
|
5306
|
-
return Insert;
|
|
5307
|
-
case KeyA$1:
|
|
5308
|
-
return KeyA;
|
|
5309
|
-
case KeyB$1:
|
|
5310
|
-
return KeyB;
|
|
5311
|
-
case KeyC$1:
|
|
5312
|
-
return KeyC;
|
|
5313
|
-
case KeyD$1:
|
|
5314
|
-
return KeyD;
|
|
5315
|
-
case KeyE$1:
|
|
5316
|
-
return KeyE;
|
|
5317
|
-
case KeyF$1:
|
|
5318
|
-
return KeyF;
|
|
5319
|
-
case KeyG$1:
|
|
5320
|
-
return KeyG;
|
|
5321
|
-
case KeyH$1:
|
|
5322
|
-
return KeyH;
|
|
5323
|
-
case KeyI$1:
|
|
5324
|
-
return KeyI;
|
|
5325
|
-
case KeyJ$1:
|
|
5326
|
-
return KeyJ;
|
|
5327
|
-
case KeyK$1:
|
|
5328
|
-
return KeyK;
|
|
5329
|
-
case KeyL$1:
|
|
5330
|
-
return KeyL;
|
|
5331
|
-
case KeyM$1:
|
|
5332
|
-
return KeyM;
|
|
5333
|
-
case KeyN$1:
|
|
5334
|
-
return KeyN;
|
|
5335
|
-
case KeyO$1:
|
|
5336
|
-
return KeyO;
|
|
5337
|
-
case KeyP$1:
|
|
5338
|
-
return KeyP;
|
|
5339
|
-
case KeyQ$1:
|
|
5340
|
-
return KeyQ;
|
|
5341
|
-
case KeyR$1:
|
|
5342
|
-
return KeyR;
|
|
5343
|
-
case KeyS$1:
|
|
5344
|
-
return KeyS;
|
|
5345
|
-
case KeyT$1:
|
|
5346
|
-
return KeyT;
|
|
5347
|
-
case KeyU$1:
|
|
5348
|
-
return KeyU;
|
|
5349
|
-
case KeyV$1:
|
|
5350
|
-
return KeyV;
|
|
5351
|
-
case KeyW$1:
|
|
5352
|
-
return KeyW;
|
|
5353
|
-
case KeyX$1:
|
|
5354
|
-
return KeyX;
|
|
5355
|
-
case KeyY$1:
|
|
5356
|
-
return KeyY;
|
|
5357
|
-
case KeyZ$1:
|
|
5358
|
-
return KeyZ;
|
|
5359
|
-
case LeftArrow$1:
|
|
5360
|
-
return LeftArrow;
|
|
5361
|
-
case Minus$1:
|
|
5362
|
-
return Minus;
|
|
5363
|
-
case PageDown$1:
|
|
5364
|
-
return PageDown;
|
|
5365
|
-
case PageUp$1:
|
|
5366
|
-
return PageUp;
|
|
5367
|
-
case Period$1:
|
|
5368
|
-
return Period;
|
|
5369
|
-
case Plus$1:
|
|
5370
|
-
return Plus;
|
|
5371
|
-
case Quote$1:
|
|
5372
|
-
return Quote;
|
|
5373
|
-
case RightArrow$1:
|
|
5374
|
-
return RightArrow;
|
|
5375
|
-
case SemiColon$1:
|
|
5376
|
-
return SemiColon;
|
|
5377
|
-
case Slash$1:
|
|
5378
|
-
return Slash;
|
|
5379
|
-
case Space$2:
|
|
5380
|
-
return Space$1;
|
|
5381
|
-
case Star$1:
|
|
5382
|
-
return Star;
|
|
5383
|
-
case Tab$1:
|
|
5384
|
-
return Tab;
|
|
5385
|
-
case UpArrow$1:
|
|
5386
|
-
return UpArrow;
|
|
5387
|
-
default:
|
|
5388
|
-
return Unknown;
|
|
5389
|
-
}
|
|
4837
|
+
return keyCodeMap[key] ?? Unknown;
|
|
5390
4838
|
};
|
|
5391
4839
|
|
|
5392
4840
|
const CtrlCmd = 1 << 11 >>> 0;
|
|
@@ -5903,14 +5351,16 @@ const getSlimCode = html => {
|
|
|
5903
5351
|
result = result.replaceAll(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style\s*>/gi, '');
|
|
5904
5352
|
return result;
|
|
5905
5353
|
};
|
|
5906
|
-
const
|
|
5354
|
+
const getBodyOuterHtml = async view => {
|
|
5907
5355
|
const {
|
|
5908
5356
|
webContents
|
|
5909
5357
|
} = view;
|
|
5910
5358
|
const code = `document.body.outerHTML`;
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5359
|
+
return webContents.executeJavaScript(code);
|
|
5360
|
+
};
|
|
5361
|
+
const getDomTree = async view => {
|
|
5362
|
+
const result = await getBodyOuterHtml(view);
|
|
5363
|
+
return getSlimCode(result);
|
|
5914
5364
|
};
|
|
5915
5365
|
const insertCss = async (view, code) => {
|
|
5916
5366
|
const {
|
|
@@ -5955,138 +5405,1123 @@ const cancelNavigation = view => {
|
|
|
5955
5405
|
webContents.navigationHistory.goBack();
|
|
5956
5406
|
}
|
|
5957
5407
|
};
|
|
5958
|
-
const show = id => {
|
|
5959
|
-
// console.log('[main-process] show browser view', id)
|
|
5960
|
-
const state = get$3(id);
|
|
5961
|
-
if (!state) {
|
|
5962
|
-
return;
|
|
5408
|
+
const show = id => {
|
|
5409
|
+
// console.log('[main-process] show browser view', id)
|
|
5410
|
+
const state = get$3(id);
|
|
5411
|
+
if (!state) {
|
|
5412
|
+
return;
|
|
5413
|
+
}
|
|
5414
|
+
const {
|
|
5415
|
+
browserWindow,
|
|
5416
|
+
view
|
|
5417
|
+
} = state;
|
|
5418
|
+
browserWindow.contentView.addChildView(view);
|
|
5419
|
+
};
|
|
5420
|
+
const addToWindow = (browserWindowId, browserViewId) => {
|
|
5421
|
+
const state = get$3(browserViewId);
|
|
5422
|
+
const {
|
|
5423
|
+
view
|
|
5424
|
+
} = state;
|
|
5425
|
+
const browserWindow = BrowserWindow.fromId(browserWindowId);
|
|
5426
|
+
if (!browserWindow) {
|
|
5427
|
+
return;
|
|
5428
|
+
}
|
|
5429
|
+
browserWindow.contentView.addChildView(view);
|
|
5430
|
+
};
|
|
5431
|
+
const hide = id => {
|
|
5432
|
+
const state = get$3(id);
|
|
5433
|
+
if (!state) {
|
|
5434
|
+
return;
|
|
5435
|
+
}
|
|
5436
|
+
const {
|
|
5437
|
+
browserWindow,
|
|
5438
|
+
view
|
|
5439
|
+
} = state;
|
|
5440
|
+
browserWindow.contentView.removeChildView(view);
|
|
5441
|
+
};
|
|
5442
|
+
|
|
5443
|
+
/**
|
|
5444
|
+
*
|
|
5445
|
+
* @param {Electron.BrowserView} view
|
|
5446
|
+
* @param {number} x
|
|
5447
|
+
* @param {number} y
|
|
5448
|
+
*/
|
|
5449
|
+
const inspectElement = (view, x, y) => {
|
|
5450
|
+
number(x);
|
|
5451
|
+
number(y);
|
|
5452
|
+
const {
|
|
5453
|
+
webContents
|
|
5454
|
+
} = view;
|
|
5455
|
+
webContents.inspectElement(x, y);
|
|
5456
|
+
};
|
|
5457
|
+
|
|
5458
|
+
/**
|
|
5459
|
+
*
|
|
5460
|
+
* @param {Electron.BrowserView} view
|
|
5461
|
+
* @param {string} backgroundColor
|
|
5462
|
+
*/
|
|
5463
|
+
const setBackgroundColor = (view, backgroundColor) => {
|
|
5464
|
+
view.setBackgroundColor(backgroundColor);
|
|
5465
|
+
};
|
|
5466
|
+
|
|
5467
|
+
/**
|
|
5468
|
+
*
|
|
5469
|
+
* @param {Electron.BrowserView} view
|
|
5470
|
+
* @param {number} x
|
|
5471
|
+
* @param {number} y
|
|
5472
|
+
*/
|
|
5473
|
+
const copyImageAt = (view, x, y) => {
|
|
5474
|
+
number(x);
|
|
5475
|
+
number(y);
|
|
5476
|
+
const {
|
|
5477
|
+
webContents
|
|
5478
|
+
} = view;
|
|
5479
|
+
webContents.copyImageAt(x, y);
|
|
5480
|
+
};
|
|
5481
|
+
const setFallThroughKeyBindings = fallthroughKeyBindings => {
|
|
5482
|
+
setFallthroughKeyBindings(fallthroughKeyBindings);
|
|
5483
|
+
};
|
|
5484
|
+
|
|
5485
|
+
// TODO maybe move some of these to webContentFunctions
|
|
5486
|
+
|
|
5487
|
+
/**
|
|
5488
|
+
* @param {Electron.BrowserView} view
|
|
5489
|
+
*/
|
|
5490
|
+
const getStats = view => {
|
|
5491
|
+
const {
|
|
5492
|
+
webContents
|
|
5493
|
+
} = view;
|
|
5494
|
+
const canGoBack = webContents.navigationHistory.canGoBack();
|
|
5495
|
+
const canGoForward = webContents.navigationHistory.canGoForward();
|
|
5496
|
+
const url = webContents.getURL();
|
|
5497
|
+
const title = webContents.getTitle();
|
|
5498
|
+
return {
|
|
5499
|
+
canGoBack,
|
|
5500
|
+
canGoForward,
|
|
5501
|
+
title,
|
|
5502
|
+
url
|
|
5503
|
+
};
|
|
5504
|
+
};
|
|
5505
|
+
|
|
5506
|
+
const printPrettyError = (prettyError, prefix = '') => {
|
|
5507
|
+
error(`${prefix}${prettyError.type}: ${prettyError.message}\n\n${prettyError.codeFrame}\n\n${prettyError.stack}\n`);
|
|
5508
|
+
};
|
|
5509
|
+
|
|
5510
|
+
const execute = (method, ...params) => {
|
|
5511
|
+
const fn = commandMapRef[method];
|
|
5512
|
+
if (!fn) {
|
|
5513
|
+
throw new Error(`command not found: ${method}`);
|
|
5514
|
+
}
|
|
5515
|
+
return fn(...params);
|
|
5516
|
+
};
|
|
5517
|
+
const logError = (error, prettyError) => {
|
|
5518
|
+
printPrettyError(prettyError, '[main-process] ');
|
|
5519
|
+
};
|
|
5520
|
+
const handleMessage = event => {
|
|
5521
|
+
return handleJsonRpcMessage(event.target, event.data, execute, resolve, prepare,
|
|
5522
|
+
// @ts-ignore
|
|
5523
|
+
logError, requiresSocket);
|
|
5524
|
+
};
|
|
5525
|
+
|
|
5526
|
+
const handleIpc = ipc => {
|
|
5527
|
+
if ('addEventListener' in ipc) {
|
|
5528
|
+
ipc.addEventListener('message', handleMessage);
|
|
5529
|
+
} else if ('on' in ipc) {
|
|
5530
|
+
// deprecated
|
|
5531
|
+
ipc.on('message', handleMessage);
|
|
5532
|
+
}
|
|
5533
|
+
};
|
|
5534
|
+
const unhandleIpc = ipc => {
|
|
5535
|
+
if ('removeEventListener' in ipc) {
|
|
5536
|
+
ipc.removeEventListener('message', handleMessage);
|
|
5537
|
+
} else if ('off' in ipc) {
|
|
5538
|
+
ipc.off('message', handleMessage);
|
|
5539
|
+
}
|
|
5540
|
+
};
|
|
5541
|
+
|
|
5542
|
+
const isMessagePort = value => {
|
|
5543
|
+
return value && value instanceof MessagePort;
|
|
5544
|
+
};
|
|
5545
|
+
const isMessagePortMain = value => {
|
|
5546
|
+
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
5547
|
+
};
|
|
5548
|
+
const isOffscreenCanvas = value => {
|
|
5549
|
+
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
5550
|
+
};
|
|
5551
|
+
const isInstanceOf = (value, constructorName) => {
|
|
5552
|
+
return value?.constructor?.name === constructorName;
|
|
5553
|
+
};
|
|
5554
|
+
const isSocket = value => {
|
|
5555
|
+
return isInstanceOf(value, 'Socket');
|
|
5556
|
+
};
|
|
5557
|
+
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
5558
|
+
const isTransferrable = value => {
|
|
5559
|
+
for (const fn of transferrables) {
|
|
5560
|
+
if (fn(value)) {
|
|
5561
|
+
return true;
|
|
5562
|
+
}
|
|
5563
|
+
}
|
|
5564
|
+
return false;
|
|
5565
|
+
};
|
|
5566
|
+
const walkValue = (value, transferrables, isTransferrable) => {
|
|
5567
|
+
if (!value) {
|
|
5568
|
+
return;
|
|
5569
|
+
}
|
|
5570
|
+
if (isTransferrable(value)) {
|
|
5571
|
+
transferrables.push(value);
|
|
5572
|
+
return;
|
|
5573
|
+
}
|
|
5574
|
+
if (Array.isArray(value)) {
|
|
5575
|
+
for (const item of value) {
|
|
5576
|
+
walkValue(item, transferrables, isTransferrable);
|
|
5577
|
+
}
|
|
5578
|
+
return;
|
|
5579
|
+
}
|
|
5580
|
+
if (typeof value === 'object') {
|
|
5581
|
+
for (const property of Object.values(value)) {
|
|
5582
|
+
walkValue(property, transferrables, isTransferrable);
|
|
5583
|
+
}
|
|
5584
|
+
}
|
|
5585
|
+
};
|
|
5586
|
+
const getTransferrables = value => {
|
|
5587
|
+
const transferrables = [];
|
|
5588
|
+
walkValue(value, transferrables, isTransferrable);
|
|
5589
|
+
return transferrables;
|
|
5590
|
+
};
|
|
5591
|
+
const removeValues = (value, toRemove) => {
|
|
5592
|
+
if (!value) {
|
|
5593
|
+
return value;
|
|
5594
|
+
}
|
|
5595
|
+
if (Array.isArray(value)) {
|
|
5596
|
+
const newItems = [];
|
|
5597
|
+
for (const item of value) {
|
|
5598
|
+
if (!toRemove.includes(item)) {
|
|
5599
|
+
newItems.push(removeValues(item, toRemove));
|
|
5600
|
+
}
|
|
5601
|
+
}
|
|
5602
|
+
return newItems;
|
|
5603
|
+
}
|
|
5604
|
+
if (typeof value === 'object') {
|
|
5605
|
+
const newObject = Object.create(null);
|
|
5606
|
+
for (const [key, property] of Object.entries(value)) {
|
|
5607
|
+
if (!toRemove.includes(property)) {
|
|
5608
|
+
newObject[key] = removeValues(property, toRemove);
|
|
5609
|
+
}
|
|
5610
|
+
}
|
|
5611
|
+
return newObject;
|
|
5612
|
+
}
|
|
5613
|
+
return value;
|
|
5614
|
+
};
|
|
5615
|
+
|
|
5616
|
+
// workaround for electron not supporting transferrable objects
|
|
5617
|
+
// as parameters. If the transferrable object is a parameter, in electron
|
|
5618
|
+
// only an empty objected is received in the main process
|
|
5619
|
+
const fixElectronParameters = value => {
|
|
5620
|
+
const transfer = getTransferrables(value);
|
|
5621
|
+
const newValue = removeValues(value, transfer);
|
|
5622
|
+
return {
|
|
5623
|
+
newValue,
|
|
5624
|
+
transfer
|
|
5625
|
+
};
|
|
5626
|
+
};
|
|
5627
|
+
const getActualDataElectron = event => {
|
|
5628
|
+
const {
|
|
5629
|
+
data,
|
|
5630
|
+
ports
|
|
5631
|
+
} = event;
|
|
5632
|
+
if (ports.length === 0) {
|
|
5633
|
+
return data;
|
|
5634
|
+
}
|
|
5635
|
+
return {
|
|
5636
|
+
...data,
|
|
5637
|
+
params: [...ports, ...data.params]
|
|
5638
|
+
};
|
|
5639
|
+
};
|
|
5640
|
+
const attachEvents = that => {
|
|
5641
|
+
const handleMessage = (...args) => {
|
|
5642
|
+
const data = that.getData(...args);
|
|
5643
|
+
that.dispatchEvent(new MessageEvent('message', {
|
|
5644
|
+
data
|
|
5645
|
+
}));
|
|
5646
|
+
};
|
|
5647
|
+
that.onMessage(handleMessage);
|
|
5648
|
+
const handleClose = event => {
|
|
5649
|
+
that.dispatchEvent(new Event('close'));
|
|
5650
|
+
};
|
|
5651
|
+
that.onClose(handleClose);
|
|
5652
|
+
};
|
|
5653
|
+
class Ipc extends EventTarget {
|
|
5654
|
+
constructor(rawIpc) {
|
|
5655
|
+
super();
|
|
5656
|
+
this._rawIpc = rawIpc;
|
|
5657
|
+
attachEvents(this);
|
|
5658
|
+
}
|
|
5659
|
+
}
|
|
5660
|
+
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
5661
|
+
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
5662
|
+
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
5663
|
+
const NewLine = '\n';
|
|
5664
|
+
const joinLines = lines => {
|
|
5665
|
+
return lines.join(NewLine);
|
|
5666
|
+
};
|
|
5667
|
+
const RE_AT = /^\s+at/;
|
|
5668
|
+
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
|
|
5669
|
+
const isNormalStackLine = line => {
|
|
5670
|
+
return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
|
|
5671
|
+
};
|
|
5672
|
+
const getDetails = lines => {
|
|
5673
|
+
const index = lines.findIndex(isNormalStackLine);
|
|
5674
|
+
if (index === -1) {
|
|
5675
|
+
return {
|
|
5676
|
+
actualMessage: joinLines(lines),
|
|
5677
|
+
rest: []
|
|
5678
|
+
};
|
|
5679
|
+
}
|
|
5680
|
+
let lastIndex = index - 1;
|
|
5681
|
+
while (++lastIndex < lines.length) {
|
|
5682
|
+
if (!isNormalStackLine(lines[lastIndex])) {
|
|
5683
|
+
break;
|
|
5684
|
+
}
|
|
5685
|
+
}
|
|
5686
|
+
return {
|
|
5687
|
+
actualMessage: lines[index - 1],
|
|
5688
|
+
rest: lines.slice(index, lastIndex)
|
|
5689
|
+
};
|
|
5690
|
+
};
|
|
5691
|
+
const splitLines = lines => {
|
|
5692
|
+
return lines.split(NewLine);
|
|
5693
|
+
};
|
|
5694
|
+
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
|
|
5695
|
+
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
|
|
5696
|
+
const isMessageCodeBlockStartIndex = line => {
|
|
5697
|
+
return RE_MESSAGE_CODE_BLOCK_START.test(line);
|
|
5698
|
+
};
|
|
5699
|
+
const isMessageCodeBlockEndIndex = line => {
|
|
5700
|
+
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
5701
|
+
};
|
|
5702
|
+
const getMessageCodeBlock = stderr => {
|
|
5703
|
+
const lines = splitLines(stderr);
|
|
5704
|
+
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
|
|
5705
|
+
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
5706
|
+
const relevantLines = lines.slice(startIndex, endIndex);
|
|
5707
|
+
const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
|
|
5708
|
+
return relevantMessage;
|
|
5709
|
+
};
|
|
5710
|
+
const isModuleNotFoundMessage = line => {
|
|
5711
|
+
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
5712
|
+
};
|
|
5713
|
+
const getModuleNotFoundError = stderr => {
|
|
5714
|
+
const lines = splitLines(stderr);
|
|
5715
|
+
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
5716
|
+
const message = lines[messageIndex];
|
|
5717
|
+
return {
|
|
5718
|
+
code: ERR_MODULE_NOT_FOUND,
|
|
5719
|
+
message
|
|
5720
|
+
};
|
|
5721
|
+
};
|
|
5722
|
+
const isModuleNotFoundError = stderr => {
|
|
5723
|
+
if (!stderr) {
|
|
5724
|
+
return false;
|
|
5725
|
+
}
|
|
5726
|
+
return stderr.includes('ERR_MODULE_NOT_FOUND');
|
|
5727
|
+
};
|
|
5728
|
+
const isModulesSyntaxError = stderr => {
|
|
5729
|
+
if (!stderr) {
|
|
5730
|
+
return false;
|
|
5731
|
+
}
|
|
5732
|
+
return stderr.includes('SyntaxError: Cannot use import statement outside a module');
|
|
5733
|
+
};
|
|
5734
|
+
const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
|
|
5735
|
+
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
|
|
5736
|
+
const isUnhelpfulNativeModuleError = stderr => {
|
|
5737
|
+
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
|
5738
|
+
};
|
|
5739
|
+
const getNativeModuleErrorMessage = stderr => {
|
|
5740
|
+
const message = getMessageCodeBlock(stderr);
|
|
5741
|
+
return {
|
|
5742
|
+
code: E_INCOMPATIBLE_NATIVE_MODULE,
|
|
5743
|
+
message: `Incompatible native node module: ${message}`
|
|
5744
|
+
};
|
|
5745
|
+
};
|
|
5746
|
+
const getModuleSyntaxError = () => {
|
|
5747
|
+
return {
|
|
5748
|
+
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
|
|
5749
|
+
message: `ES Modules are not supported in electron`
|
|
5750
|
+
};
|
|
5751
|
+
};
|
|
5752
|
+
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
5753
|
+
if (isUnhelpfulNativeModuleError(stderr)) {
|
|
5754
|
+
return getNativeModuleErrorMessage(stderr);
|
|
5755
|
+
}
|
|
5756
|
+
if (isModulesSyntaxError(stderr)) {
|
|
5757
|
+
return getModuleSyntaxError();
|
|
5758
|
+
}
|
|
5759
|
+
if (isModuleNotFoundError(stderr)) {
|
|
5760
|
+
return getModuleNotFoundError(stderr);
|
|
5761
|
+
}
|
|
5762
|
+
const lines = splitLines(stderr);
|
|
5763
|
+
const {
|
|
5764
|
+
actualMessage,
|
|
5765
|
+
rest
|
|
5766
|
+
} = getDetails(lines);
|
|
5767
|
+
return {
|
|
5768
|
+
code: '',
|
|
5769
|
+
message: actualMessage,
|
|
5770
|
+
stack: rest
|
|
5771
|
+
};
|
|
5772
|
+
};
|
|
5773
|
+
class IpcError extends VError {
|
|
5774
|
+
// @ts-ignore
|
|
5775
|
+
constructor(betterMessage, stdout = '', stderr = '') {
|
|
5776
|
+
if (stdout || stderr) {
|
|
5777
|
+
// @ts-ignore
|
|
5778
|
+
const {
|
|
5779
|
+
code,
|
|
5780
|
+
message,
|
|
5781
|
+
stack
|
|
5782
|
+
} = getHelpfulChildProcessError(stdout, stderr);
|
|
5783
|
+
const cause = new Error(message);
|
|
5784
|
+
// @ts-ignore
|
|
5785
|
+
cause.code = code;
|
|
5786
|
+
cause.stack = stack;
|
|
5787
|
+
super(cause, betterMessage);
|
|
5788
|
+
} else {
|
|
5789
|
+
super(betterMessage);
|
|
5790
|
+
}
|
|
5791
|
+
// @ts-ignore
|
|
5792
|
+
this.name = 'IpcError';
|
|
5793
|
+
// @ts-ignore
|
|
5794
|
+
this.stdout = stdout;
|
|
5795
|
+
// @ts-ignore
|
|
5796
|
+
this.stderr = stderr;
|
|
5797
|
+
}
|
|
5798
|
+
}
|
|
5799
|
+
const listen$b = ({
|
|
5800
|
+
messagePort
|
|
5801
|
+
}) => {
|
|
5802
|
+
if (!isMessagePortMain(messagePort)) {
|
|
5803
|
+
throw new IpcError('port must be of type MessagePortMain');
|
|
5804
|
+
}
|
|
5805
|
+
return messagePort;
|
|
5806
|
+
};
|
|
5807
|
+
const signal$c = messagePort => {
|
|
5808
|
+
messagePort.start();
|
|
5809
|
+
};
|
|
5810
|
+
class IpcChildWithElectronMessagePort extends Ipc {
|
|
5811
|
+
getData = getActualDataElectron;
|
|
5812
|
+
send(message) {
|
|
5813
|
+
this._rawIpc.postMessage(message);
|
|
5814
|
+
}
|
|
5815
|
+
sendAndTransfer(message) {
|
|
5816
|
+
const {
|
|
5817
|
+
newValue,
|
|
5818
|
+
transfer
|
|
5819
|
+
} = fixElectronParameters(message);
|
|
5820
|
+
this._rawIpc.postMessage(newValue, transfer);
|
|
5821
|
+
}
|
|
5822
|
+
dispose() {
|
|
5823
|
+
this._rawIpc.close();
|
|
5824
|
+
}
|
|
5825
|
+
onMessage(callback) {
|
|
5826
|
+
this._rawIpc.on('message', callback);
|
|
5827
|
+
}
|
|
5828
|
+
onClose(callback) {
|
|
5829
|
+
this._rawIpc.on('close', callback);
|
|
5830
|
+
}
|
|
5831
|
+
}
|
|
5832
|
+
const wrap$j = messagePort => {
|
|
5833
|
+
return new IpcChildWithElectronMessagePort(messagePort);
|
|
5834
|
+
};
|
|
5835
|
+
const IpcChildWithElectronMessagePort$1 = {
|
|
5836
|
+
__proto__: null,
|
|
5837
|
+
listen: listen$b,
|
|
5838
|
+
signal: signal$c,
|
|
5839
|
+
wrap: wrap$j
|
|
5840
|
+
};
|
|
5841
|
+
|
|
5842
|
+
// @ts-ignore
|
|
5843
|
+
const getUtilityProcessPortData = event => {
|
|
5844
|
+
const {
|
|
5845
|
+
data,
|
|
5846
|
+
ports
|
|
5847
|
+
} = event;
|
|
5848
|
+
if (ports.length === 0) {
|
|
5849
|
+
return data;
|
|
5850
|
+
}
|
|
5851
|
+
return {
|
|
5852
|
+
...data,
|
|
5853
|
+
params: [...ports, ...data.params]
|
|
5854
|
+
};
|
|
5855
|
+
};
|
|
5856
|
+
const readyMessage = 'ready';
|
|
5857
|
+
const listen$a = () => {
|
|
5858
|
+
// @ts-ignore
|
|
5859
|
+
const {
|
|
5860
|
+
parentPort
|
|
5861
|
+
} = process;
|
|
5862
|
+
if (!parentPort) {
|
|
5863
|
+
throw new IpcError('parent port must be defined');
|
|
5864
|
+
}
|
|
5865
|
+
return parentPort;
|
|
5866
|
+
};
|
|
5867
|
+
const signal$b = parentPort => {
|
|
5868
|
+
parentPort.postMessage(readyMessage);
|
|
5869
|
+
};
|
|
5870
|
+
class IpcChildWithElectronUtilityProcess extends Ipc {
|
|
5871
|
+
getData(event) {
|
|
5872
|
+
return getUtilityProcessPortData(event);
|
|
5873
|
+
}
|
|
5874
|
+
send(message) {
|
|
5875
|
+
this._rawIpc.postMessage(message);
|
|
5876
|
+
}
|
|
5877
|
+
sendAndTransfer(message) {
|
|
5878
|
+
const {
|
|
5879
|
+
newValue,
|
|
5880
|
+
transfer
|
|
5881
|
+
} = fixElectronParameters(message);
|
|
5882
|
+
this._rawIpc.postMessage(newValue, transfer);
|
|
5883
|
+
}
|
|
5884
|
+
dispose() {
|
|
5885
|
+
this._rawIpc.close();
|
|
5886
|
+
}
|
|
5887
|
+
onClose(callback) {
|
|
5888
|
+
this._rawIpc.on('close', callback);
|
|
5889
|
+
}
|
|
5890
|
+
onMessage(callback) {
|
|
5891
|
+
this._rawIpc.on('message', callback);
|
|
5892
|
+
}
|
|
5893
|
+
}
|
|
5894
|
+
const wrap$i = parentPort => {
|
|
5895
|
+
return new IpcChildWithElectronUtilityProcess(parentPort);
|
|
5896
|
+
};
|
|
5897
|
+
const IpcChildWithElectronUtilityProcess$1 = {
|
|
5898
|
+
__proto__: null,
|
|
5899
|
+
listen: listen$a,
|
|
5900
|
+
signal: signal$b,
|
|
5901
|
+
wrap: wrap$i
|
|
5902
|
+
};
|
|
5903
|
+
const getActualData = (message, handle) => {
|
|
5904
|
+
if (handle) {
|
|
5905
|
+
return {
|
|
5906
|
+
...message,
|
|
5907
|
+
params: [handle, ...message.params]
|
|
5908
|
+
};
|
|
5909
|
+
}
|
|
5910
|
+
return message;
|
|
5911
|
+
};
|
|
5912
|
+
const getTransferrablesNode = value => {
|
|
5913
|
+
const transferrables = getTransferrables(value);
|
|
5914
|
+
if (transferrables.length === 0) {
|
|
5915
|
+
throw new Error(`no transferrables found`);
|
|
5916
|
+
}
|
|
5917
|
+
return transferrables[0];
|
|
5918
|
+
};
|
|
5919
|
+
const listen$5 = async () => {
|
|
5920
|
+
if (!process.send) {
|
|
5921
|
+
throw new IpcError('process.send must be defined');
|
|
5922
|
+
}
|
|
5923
|
+
return process;
|
|
5924
|
+
};
|
|
5925
|
+
const signal$7 = process => {
|
|
5926
|
+
process.send(readyMessage);
|
|
5927
|
+
};
|
|
5928
|
+
class IpcChildWithNodeForkedProcess extends Ipc {
|
|
5929
|
+
getData(message, handle) {
|
|
5930
|
+
return getActualData(message, handle);
|
|
5931
|
+
}
|
|
5932
|
+
onClose(callback) {
|
|
5933
|
+
this._rawIpc.on('close', callback);
|
|
5934
|
+
}
|
|
5935
|
+
send(message) {
|
|
5936
|
+
this._rawIpc.send(message);
|
|
5937
|
+
}
|
|
5938
|
+
onMessage(callback) {
|
|
5939
|
+
this._rawIpc.on('message', callback);
|
|
5940
|
+
}
|
|
5941
|
+
sendAndTransfer(message) {
|
|
5942
|
+
const transfer = getTransferrablesNode(message);
|
|
5943
|
+
this._rawIpc.send(message, transfer);
|
|
5944
|
+
}
|
|
5945
|
+
dispose() {
|
|
5946
|
+
// ignore
|
|
5947
|
+
}
|
|
5948
|
+
}
|
|
5949
|
+
const wrap$d = process => {
|
|
5950
|
+
return new IpcChildWithNodeForkedProcess(process);
|
|
5951
|
+
};
|
|
5952
|
+
const IpcChildWithNodeForkedProcess$1 = {
|
|
5953
|
+
__proto__: null,
|
|
5954
|
+
listen: listen$5,
|
|
5955
|
+
signal: signal$7,
|
|
5956
|
+
wrap: wrap$d
|
|
5957
|
+
};
|
|
5958
|
+
const listen$3 = async () => {
|
|
5959
|
+
const {
|
|
5960
|
+
parentPort
|
|
5961
|
+
} = await import('node:worker_threads');
|
|
5962
|
+
if (!parentPort) {
|
|
5963
|
+
throw new IpcError('parentPort is required for node worker threads ipc');
|
|
5964
|
+
}
|
|
5965
|
+
return parentPort;
|
|
5966
|
+
};
|
|
5967
|
+
const signal$5 = parentPort => {
|
|
5968
|
+
parentPort.postMessage(readyMessage);
|
|
5969
|
+
};
|
|
5970
|
+
class IpcChildWithNodeWorker extends Ipc {
|
|
5971
|
+
getData(data) {
|
|
5972
|
+
return data;
|
|
5973
|
+
}
|
|
5974
|
+
onClose(callback) {
|
|
5975
|
+
this._rawIpc.on('close', callback);
|
|
5976
|
+
}
|
|
5977
|
+
send(message) {
|
|
5978
|
+
this._rawIpc.postMessage(message);
|
|
5979
|
+
}
|
|
5980
|
+
onMessage(callback) {
|
|
5981
|
+
this._rawIpc.on('message', callback);
|
|
5982
|
+
}
|
|
5983
|
+
sendAndTransfer(message) {
|
|
5984
|
+
const transfer = getTransferrablesNode(message);
|
|
5985
|
+
this._rawIpc.postMessage(message, transfer);
|
|
5986
|
+
}
|
|
5987
|
+
dispose() {
|
|
5988
|
+
this._rawIpc.close();
|
|
5989
|
+
}
|
|
5990
|
+
}
|
|
5991
|
+
const wrap$b = parentPort => {
|
|
5992
|
+
return new IpcChildWithNodeWorker(parentPort);
|
|
5993
|
+
};
|
|
5994
|
+
const IpcChildWithNodeWorker$1 = {
|
|
5995
|
+
__proto__: null,
|
|
5996
|
+
listen: listen$3,
|
|
5997
|
+
signal: signal$5,
|
|
5998
|
+
wrap: wrap$b
|
|
5999
|
+
};
|
|
6000
|
+
const preloadChannelType = 'port';
|
|
6001
|
+
const listen$2 = ({
|
|
6002
|
+
webContents
|
|
6003
|
+
}) => {
|
|
6004
|
+
return webContents;
|
|
6005
|
+
};
|
|
6006
|
+
const getData$1 = (event, message) => {
|
|
6007
|
+
const {
|
|
6008
|
+
ports,
|
|
6009
|
+
sender
|
|
6010
|
+
} = event;
|
|
6011
|
+
const data = {
|
|
6012
|
+
...message,
|
|
6013
|
+
params: [...message.params, ...ports, sender.id]
|
|
6014
|
+
};
|
|
6015
|
+
return data;
|
|
6016
|
+
};
|
|
6017
|
+
class IpcChildWithRendererProcess2 extends Ipc {
|
|
6018
|
+
getData(event, message) {
|
|
6019
|
+
return getData$1(event, message);
|
|
6020
|
+
}
|
|
6021
|
+
send(message) {
|
|
6022
|
+
this._rawIpc.postMessage(preloadChannelType, message);
|
|
6023
|
+
}
|
|
6024
|
+
sendAndTransfer(message) {
|
|
6025
|
+
const transfer = getTransferrables(message);
|
|
6026
|
+
this._rawIpc.postMessage(preloadChannelType, message, transfer);
|
|
6027
|
+
}
|
|
6028
|
+
dispose() {
|
|
6029
|
+
// ignore
|
|
6030
|
+
}
|
|
6031
|
+
onMessage(callback) {
|
|
6032
|
+
this._rawIpc.ipc.on(preloadChannelType, callback);
|
|
6033
|
+
}
|
|
6034
|
+
onClose(callback) {
|
|
6035
|
+
this._rawIpc.on('destroyed', callback);
|
|
6036
|
+
}
|
|
6037
|
+
}
|
|
6038
|
+
const wrap$a = webContents => {
|
|
6039
|
+
return new IpcChildWithRendererProcess2(webContents);
|
|
6040
|
+
};
|
|
6041
|
+
const IpcChildWithRendererProcess2$1 = {
|
|
6042
|
+
__proto__: null,
|
|
6043
|
+
listen: listen$2,
|
|
6044
|
+
wrap: wrap$a
|
|
6045
|
+
};
|
|
6046
|
+
const addListener = (emitter, type, callback) => {
|
|
6047
|
+
if ('addEventListener' in emitter) {
|
|
6048
|
+
emitter.addEventListener(type, callback);
|
|
6049
|
+
} else {
|
|
6050
|
+
emitter.on(type, callback);
|
|
6051
|
+
}
|
|
6052
|
+
};
|
|
6053
|
+
const removeListener = (emitter, type, callback) => {
|
|
6054
|
+
if ('removeEventListener' in emitter) {
|
|
6055
|
+
emitter.removeEventListener(type, callback);
|
|
6056
|
+
} else {
|
|
6057
|
+
emitter.off(type, callback);
|
|
6058
|
+
}
|
|
6059
|
+
};
|
|
6060
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
6061
|
+
const {
|
|
6062
|
+
promise,
|
|
6063
|
+
resolve
|
|
6064
|
+
} = Promise.withResolvers();
|
|
6065
|
+
const listenerMap = Object.create(null);
|
|
6066
|
+
const cleanup = value => {
|
|
6067
|
+
for (const event of Object.keys(eventMap)) {
|
|
6068
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
6069
|
+
}
|
|
6070
|
+
resolve(value);
|
|
6071
|
+
};
|
|
6072
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
6073
|
+
const listener = event => {
|
|
6074
|
+
cleanup({
|
|
6075
|
+
event,
|
|
6076
|
+
type
|
|
6077
|
+
});
|
|
6078
|
+
};
|
|
6079
|
+
addListener(eventEmitter, event, listener);
|
|
6080
|
+
listenerMap[event] = listener;
|
|
6081
|
+
}
|
|
6082
|
+
return promise;
|
|
6083
|
+
};
|
|
6084
|
+
const create$7 = ({
|
|
6085
|
+
messagePort
|
|
6086
|
+
}) => {
|
|
6087
|
+
if (!isMessagePortMain(messagePort)) {
|
|
6088
|
+
throw new IpcError('port must be of type MessagePortMain');
|
|
6089
|
+
}
|
|
6090
|
+
return messagePort;
|
|
6091
|
+
};
|
|
6092
|
+
const signal$2 = messagePort => {
|
|
6093
|
+
messagePort.start();
|
|
6094
|
+
};
|
|
6095
|
+
class IpcParentWithElectronMessagePort extends Ipc {
|
|
6096
|
+
getData = getActualDataElectron;
|
|
6097
|
+
send(message) {
|
|
6098
|
+
this._rawIpc.postMessage(message);
|
|
6099
|
+
}
|
|
6100
|
+
sendAndTransfer(message) {
|
|
6101
|
+
const {
|
|
6102
|
+
newValue,
|
|
6103
|
+
transfer
|
|
6104
|
+
} = fixElectronParameters(message);
|
|
6105
|
+
this._rawIpc.postMessage(newValue, transfer);
|
|
6106
|
+
}
|
|
6107
|
+
dispose() {
|
|
6108
|
+
this._rawIpc.close();
|
|
6109
|
+
}
|
|
6110
|
+
onMessage(callback) {
|
|
6111
|
+
this._rawIpc.on('message', callback);
|
|
6112
|
+
}
|
|
6113
|
+
onClose(callback) {
|
|
6114
|
+
this._rawIpc.on('close', callback);
|
|
6115
|
+
}
|
|
6116
|
+
}
|
|
6117
|
+
const wrap$7 = messagePort => {
|
|
6118
|
+
return new IpcParentWithElectronMessagePort(messagePort);
|
|
6119
|
+
};
|
|
6120
|
+
const IpcParentWithElectronMessagePort$1 = {
|
|
6121
|
+
__proto__: null,
|
|
6122
|
+
create: create$7,
|
|
6123
|
+
signal: signal$2,
|
|
6124
|
+
wrap: wrap$7
|
|
6125
|
+
};
|
|
6126
|
+
const Exit = 1;
|
|
6127
|
+
const Error$2 = 2;
|
|
6128
|
+
const Message$1 = 3;
|
|
6129
|
+
const getFirstUtilityProcessEvent = async utilityProcess => {
|
|
6130
|
+
const {
|
|
6131
|
+
promise,
|
|
6132
|
+
resolve
|
|
6133
|
+
} = Promise.withResolvers();
|
|
6134
|
+
let stdout = '';
|
|
6135
|
+
let stderr = '';
|
|
6136
|
+
const cleanup = value => {
|
|
6137
|
+
// @ts-ignore
|
|
6138
|
+
utilityProcess.stderr.off('data', handleStdErrData);
|
|
6139
|
+
// @ts-ignore
|
|
6140
|
+
utilityProcess.stdout.off('data', handleStdoutData);
|
|
6141
|
+
utilityProcess.off('message', handleMessage);
|
|
6142
|
+
utilityProcess.off('exit', handleExit);
|
|
6143
|
+
resolve(value);
|
|
6144
|
+
};
|
|
6145
|
+
const handleStdErrData = data => {
|
|
6146
|
+
stderr += data;
|
|
6147
|
+
};
|
|
6148
|
+
const handleStdoutData = data => {
|
|
6149
|
+
stdout += data;
|
|
6150
|
+
};
|
|
6151
|
+
const handleMessage = event => {
|
|
6152
|
+
cleanup({
|
|
6153
|
+
event,
|
|
6154
|
+
stderr,
|
|
6155
|
+
stdout,
|
|
6156
|
+
type: Message$1
|
|
6157
|
+
});
|
|
6158
|
+
};
|
|
6159
|
+
const handleExit = event => {
|
|
6160
|
+
cleanup({
|
|
6161
|
+
event,
|
|
6162
|
+
stderr,
|
|
6163
|
+
stdout,
|
|
6164
|
+
type: Exit
|
|
6165
|
+
});
|
|
6166
|
+
};
|
|
6167
|
+
// @ts-ignore
|
|
6168
|
+
utilityProcess.stderr.on('data', handleStdErrData);
|
|
6169
|
+
// @ts-ignore
|
|
6170
|
+
utilityProcess.stdout.on('data', handleStdoutData);
|
|
6171
|
+
utilityProcess.on('message', handleMessage);
|
|
6172
|
+
utilityProcess.on('exit', handleExit);
|
|
6173
|
+
const {
|
|
6174
|
+
event,
|
|
6175
|
+
type
|
|
6176
|
+
} = await promise;
|
|
6177
|
+
return {
|
|
6178
|
+
event,
|
|
6179
|
+
stderr,
|
|
6180
|
+
stdout,
|
|
6181
|
+
type
|
|
6182
|
+
};
|
|
6183
|
+
};
|
|
6184
|
+
const create$6 = async ({
|
|
6185
|
+
argv = [],
|
|
6186
|
+
env = process.env,
|
|
6187
|
+
execArgv = [],
|
|
6188
|
+
name,
|
|
6189
|
+
path
|
|
6190
|
+
}) => {
|
|
6191
|
+
string(path);
|
|
6192
|
+
const actualArgv = ['--ipc-type=electron-utility-process', ...argv];
|
|
6193
|
+
const {
|
|
6194
|
+
utilityProcess
|
|
6195
|
+
} = await import('electron');
|
|
6196
|
+
const childProcess = utilityProcess.fork(path, actualArgv, {
|
|
6197
|
+
env,
|
|
6198
|
+
execArgv,
|
|
6199
|
+
serviceName: name,
|
|
6200
|
+
stdio: 'pipe'
|
|
6201
|
+
});
|
|
6202
|
+
const handleExit = () => {
|
|
6203
|
+
// @ts-ignore
|
|
6204
|
+
childProcess.stdout.unpipe(process.stdout);
|
|
6205
|
+
// @ts-ignore
|
|
6206
|
+
childProcess.stderr.unpipe(process.stderr);
|
|
6207
|
+
};
|
|
6208
|
+
childProcess.once('exit', handleExit);
|
|
6209
|
+
// @ts-ignore
|
|
6210
|
+
childProcess.stdout.pipe(process.stdout);
|
|
6211
|
+
const {
|
|
6212
|
+
stderr,
|
|
6213
|
+
stdout,
|
|
6214
|
+
type
|
|
6215
|
+
} = await getFirstUtilityProcessEvent(childProcess);
|
|
6216
|
+
if (type === Exit) {
|
|
6217
|
+
throw new IpcError(`Utility process exited before ipc connection was established`, stdout, stderr);
|
|
6218
|
+
}
|
|
6219
|
+
// @ts-ignore
|
|
6220
|
+
childProcess.stderr.pipe(process.stderr);
|
|
6221
|
+
return childProcess;
|
|
6222
|
+
};
|
|
6223
|
+
let IpcParentWithElectronUtilityProcess$1 = class IpcParentWithElectronUtilityProcess extends Ipc {
|
|
6224
|
+
getData(data) {
|
|
6225
|
+
return data;
|
|
6226
|
+
}
|
|
6227
|
+
send(message) {
|
|
6228
|
+
this._rawIpc.postMessage(message);
|
|
6229
|
+
}
|
|
6230
|
+
sendAndTransfer(message) {
|
|
6231
|
+
const {
|
|
6232
|
+
newValue,
|
|
6233
|
+
transfer
|
|
6234
|
+
} = fixElectronParameters(message);
|
|
6235
|
+
this._rawIpc.postMessage(newValue, transfer);
|
|
6236
|
+
}
|
|
6237
|
+
dispose() {
|
|
6238
|
+
this._rawIpc.kill();
|
|
6239
|
+
}
|
|
6240
|
+
onClose(callback) {
|
|
6241
|
+
this._rawIpc.on('exit', callback);
|
|
6242
|
+
}
|
|
6243
|
+
onMessage(callback) {
|
|
6244
|
+
this._rawIpc.on('message', callback);
|
|
6245
|
+
}
|
|
6246
|
+
};
|
|
6247
|
+
const wrap$6 = process => {
|
|
6248
|
+
return new IpcParentWithElectronUtilityProcess$1(process);
|
|
6249
|
+
};
|
|
6250
|
+
const IpcParentWithElectronUtilityProcess$1$1 = {
|
|
6251
|
+
__proto__: null,
|
|
6252
|
+
create: create$6,
|
|
6253
|
+
wrap: wrap$6
|
|
6254
|
+
};
|
|
6255
|
+
class ChildProcessError extends Error {
|
|
6256
|
+
// @ts-ignore
|
|
6257
|
+
constructor(stderr) {
|
|
6258
|
+
// @ts-ignore
|
|
6259
|
+
const {
|
|
6260
|
+
code,
|
|
6261
|
+
message,
|
|
6262
|
+
stack
|
|
6263
|
+
} = getHelpfulChildProcessError('', stderr);
|
|
6264
|
+
super(message || 'child process error');
|
|
6265
|
+
this.name = 'ChildProcessError';
|
|
6266
|
+
if (code) {
|
|
6267
|
+
// @ts-ignore
|
|
6268
|
+
this.code = code;
|
|
6269
|
+
}
|
|
6270
|
+
if (stack) {
|
|
6271
|
+
// @ts-ignore
|
|
6272
|
+
const lines = splitLines(this.stack);
|
|
6273
|
+
const [firstLine, ...stackLines] = lines;
|
|
6274
|
+
const newStackLines = [firstLine, ...stack, ...stackLines];
|
|
6275
|
+
const newStack = joinLines(newStackLines);
|
|
6276
|
+
this.stack = newStack;
|
|
6277
|
+
}
|
|
6278
|
+
}
|
|
6279
|
+
}
|
|
6280
|
+
|
|
6281
|
+
// workaround for node not supporting transferrable objects
|
|
6282
|
+
// as parameters. If the transferrable object is a parameter,
|
|
6283
|
+
// it is received as a plain object is received in the receiving process
|
|
6284
|
+
const fixNodeChildProcessParameters = value => {
|
|
6285
|
+
const transfer = getTransferrables(value);
|
|
6286
|
+
if (transfer.length === 0) {
|
|
6287
|
+
throw new IpcError('no transferrables found');
|
|
6288
|
+
}
|
|
6289
|
+
const newValue = removeValues(value, transfer);
|
|
6290
|
+
return {
|
|
6291
|
+
newValue,
|
|
6292
|
+
transfer: transfer[0]
|
|
6293
|
+
};
|
|
6294
|
+
};
|
|
6295
|
+
const getFirstNodeChildProcessEvent = async childProcess => {
|
|
6296
|
+
const {
|
|
6297
|
+
event,
|
|
6298
|
+
stderr,
|
|
6299
|
+
stdout,
|
|
6300
|
+
type
|
|
6301
|
+
} = await new Promise((resolve, reject) => {
|
|
6302
|
+
let stderr = '';
|
|
6303
|
+
let stdout = '';
|
|
6304
|
+
const cleanup = value => {
|
|
6305
|
+
if (childProcess.stdout && childProcess.stderr) {
|
|
6306
|
+
childProcess.stderr.off('data', handleStdErrData);
|
|
6307
|
+
childProcess.stdout.off('data', handleStdoutData);
|
|
6308
|
+
}
|
|
6309
|
+
childProcess.off('message', handleMessage);
|
|
6310
|
+
childProcess.off('exit', handleExit);
|
|
6311
|
+
childProcess.off('error', handleError);
|
|
6312
|
+
resolve(value);
|
|
6313
|
+
};
|
|
6314
|
+
const handleStdErrData = data => {
|
|
6315
|
+
stderr += data;
|
|
6316
|
+
};
|
|
6317
|
+
const handleStdoutData = data => {
|
|
6318
|
+
stdout += data;
|
|
6319
|
+
};
|
|
6320
|
+
const handleMessage = event => {
|
|
6321
|
+
cleanup({
|
|
6322
|
+
event,
|
|
6323
|
+
stderr,
|
|
6324
|
+
stdout,
|
|
6325
|
+
type: Message$1
|
|
6326
|
+
});
|
|
6327
|
+
};
|
|
6328
|
+
const handleExit = event => {
|
|
6329
|
+
cleanup({
|
|
6330
|
+
event,
|
|
6331
|
+
stderr,
|
|
6332
|
+
stdout,
|
|
6333
|
+
type: Exit
|
|
6334
|
+
});
|
|
6335
|
+
};
|
|
6336
|
+
const handleError = event => {
|
|
6337
|
+
cleanup({
|
|
6338
|
+
event,
|
|
6339
|
+
stderr,
|
|
6340
|
+
stdout,
|
|
6341
|
+
type: Error$2
|
|
6342
|
+
});
|
|
6343
|
+
};
|
|
6344
|
+
if (childProcess.stdout && childProcess.stderr) {
|
|
6345
|
+
childProcess.stderr.on('data', handleStdErrData);
|
|
6346
|
+
childProcess.stdout.on('data', handleStdoutData);
|
|
6347
|
+
}
|
|
6348
|
+
childProcess.on('message', handleMessage);
|
|
6349
|
+
childProcess.on('exit', handleExit);
|
|
6350
|
+
childProcess.on('error', handleError);
|
|
6351
|
+
});
|
|
6352
|
+
return {
|
|
6353
|
+
event,
|
|
6354
|
+
stderr,
|
|
6355
|
+
stdout,
|
|
6356
|
+
type
|
|
6357
|
+
};
|
|
6358
|
+
};
|
|
6359
|
+
|
|
6360
|
+
// @ts-ignore
|
|
6361
|
+
const create$2 = async ({
|
|
6362
|
+
argv = [],
|
|
6363
|
+
env,
|
|
6364
|
+
execArgv = [],
|
|
6365
|
+
name = 'child process',
|
|
6366
|
+
path,
|
|
6367
|
+
stdio = 'inherit'
|
|
6368
|
+
}) => {
|
|
6369
|
+
try {
|
|
6370
|
+
string(path);
|
|
6371
|
+
const actualArgv = ['--ipc-type=node-forked-process', ...argv];
|
|
6372
|
+
const {
|
|
6373
|
+
fork
|
|
6374
|
+
} = await import('node:child_process');
|
|
6375
|
+
const childProcess = fork(path, actualArgv, {
|
|
6376
|
+
env,
|
|
6377
|
+
execArgv,
|
|
6378
|
+
stdio: 'pipe'
|
|
6379
|
+
});
|
|
6380
|
+
const {
|
|
6381
|
+
event,
|
|
6382
|
+
stderr,
|
|
6383
|
+
type
|
|
6384
|
+
} = await getFirstNodeChildProcessEvent(childProcess);
|
|
6385
|
+
if (type === Exit) {
|
|
6386
|
+
throw new ChildProcessError(stderr);
|
|
6387
|
+
}
|
|
6388
|
+
if (type === Error$2) {
|
|
6389
|
+
throw new IpcError(`child process had an error ${event}`);
|
|
6390
|
+
}
|
|
6391
|
+
if (stdio === 'inherit' && childProcess.stdout && childProcess.stderr) {
|
|
6392
|
+
childProcess.stdout.pipe(process.stdout);
|
|
6393
|
+
childProcess.stderr.pipe(process.stderr);
|
|
6394
|
+
}
|
|
6395
|
+
return childProcess;
|
|
6396
|
+
} catch (error) {
|
|
6397
|
+
throw new VError(error, `Failed to launch ${name}`);
|
|
6398
|
+
}
|
|
6399
|
+
};
|
|
6400
|
+
class IpcParentWithNodeForkedProcess extends Ipc {
|
|
6401
|
+
constructor(childProcess) {
|
|
6402
|
+
super(childProcess);
|
|
6403
|
+
this.pid = childProcess.pid;
|
|
5963
6404
|
}
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
view
|
|
5967
|
-
} = state;
|
|
5968
|
-
browserWindow.contentView.addChildView(view);
|
|
5969
|
-
};
|
|
5970
|
-
const addToWindow = (browserWindowId, browserViewId) => {
|
|
5971
|
-
const state = get$3(browserViewId);
|
|
5972
|
-
const {
|
|
5973
|
-
view
|
|
5974
|
-
} = state;
|
|
5975
|
-
const browserWindow = BrowserWindow.fromId(browserWindowId);
|
|
5976
|
-
if (!browserWindow) {
|
|
5977
|
-
return;
|
|
6405
|
+
getData(message) {
|
|
6406
|
+
return message;
|
|
5978
6407
|
}
|
|
5979
|
-
|
|
5980
|
-
|
|
5981
|
-
const hide = id => {
|
|
5982
|
-
const state = get$3(id);
|
|
5983
|
-
if (!state) {
|
|
5984
|
-
return;
|
|
6408
|
+
send(message) {
|
|
6409
|
+
this._rawIpc.send(message);
|
|
5985
6410
|
}
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
6000
|
-
|
|
6001
|
-
|
|
6002
|
-
|
|
6003
|
-
|
|
6004
|
-
|
|
6005
|
-
webContents.inspectElement(x, y);
|
|
6006
|
-
};
|
|
6007
|
-
|
|
6008
|
-
/**
|
|
6009
|
-
*
|
|
6010
|
-
* @param {Electron.BrowserView} view
|
|
6011
|
-
* @param {string} backgroundColor
|
|
6012
|
-
*/
|
|
6013
|
-
const setBackgroundColor = (view, backgroundColor) => {
|
|
6014
|
-
view.setBackgroundColor(backgroundColor);
|
|
6015
|
-
};
|
|
6016
|
-
|
|
6017
|
-
/**
|
|
6018
|
-
*
|
|
6019
|
-
* @param {Electron.BrowserView} view
|
|
6020
|
-
* @param {number} x
|
|
6021
|
-
* @param {number} y
|
|
6022
|
-
*/
|
|
6023
|
-
const copyImageAt = (view, x, y) => {
|
|
6024
|
-
number(x);
|
|
6025
|
-
number(y);
|
|
6026
|
-
const {
|
|
6027
|
-
webContents
|
|
6028
|
-
} = view;
|
|
6029
|
-
webContents.copyImageAt(x, y);
|
|
6411
|
+
sendAndTransfer(message) {
|
|
6412
|
+
const {
|
|
6413
|
+
newValue,
|
|
6414
|
+
transfer
|
|
6415
|
+
} = fixNodeChildProcessParameters(message);
|
|
6416
|
+
this._rawIpc.send(newValue, transfer);
|
|
6417
|
+
}
|
|
6418
|
+
dispose() {
|
|
6419
|
+
this._rawIpc.kill();
|
|
6420
|
+
}
|
|
6421
|
+
onClose(callback) {
|
|
6422
|
+
this._rawIpc.on('close', callback);
|
|
6423
|
+
}
|
|
6424
|
+
onMessage(callback) {
|
|
6425
|
+
this._rawIpc.on('message', callback);
|
|
6426
|
+
}
|
|
6427
|
+
}
|
|
6428
|
+
const wrap$2 = childProcess => {
|
|
6429
|
+
return new IpcParentWithNodeForkedProcess(childProcess);
|
|
6030
6430
|
};
|
|
6031
|
-
const
|
|
6032
|
-
|
|
6431
|
+
const IpcParentWithNodeForkedProcess$1 = {
|
|
6432
|
+
__proto__: null,
|
|
6433
|
+
create: create$2,
|
|
6434
|
+
wrap: wrap$2
|
|
6033
6435
|
};
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
*/
|
|
6040
|
-
const getStats = view => {
|
|
6041
|
-
const {
|
|
6042
|
-
webContents
|
|
6043
|
-
} = view;
|
|
6044
|
-
const canGoBack = webContents.navigationHistory.canGoBack();
|
|
6045
|
-
const canGoForward = webContents.navigationHistory.canGoForward();
|
|
6046
|
-
const url = webContents.getURL();
|
|
6047
|
-
const title = webContents.getTitle();
|
|
6436
|
+
const fixNodeWorkerParameters = value => {
|
|
6437
|
+
const transfer = getTransferrables(value);
|
|
6438
|
+
if (transfer.length === 0) {
|
|
6439
|
+
throw new IpcError('no transferrables found');
|
|
6440
|
+
}
|
|
6048
6441
|
return {
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
title,
|
|
6052
|
-
url
|
|
6442
|
+
newValue: value,
|
|
6443
|
+
transfer: transfer
|
|
6053
6444
|
};
|
|
6054
6445
|
};
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6446
|
+
const getFirstNodeWorkerEvent = worker => {
|
|
6447
|
+
return getFirstEvent(worker, {
|
|
6448
|
+
error: Error$2,
|
|
6449
|
+
exit: Exit,
|
|
6450
|
+
message: Message$1
|
|
6451
|
+
});
|
|
6058
6452
|
};
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6453
|
+
const create$1$1 = async ({
|
|
6454
|
+
argv = [],
|
|
6455
|
+
env = process.env,
|
|
6456
|
+
execArgv = [],
|
|
6457
|
+
name,
|
|
6458
|
+
path,
|
|
6459
|
+
stdio
|
|
6460
|
+
}) => {
|
|
6461
|
+
string(path);
|
|
6462
|
+
const actualArgv = ['--ipc-type=node-worker', ...argv];
|
|
6463
|
+
const actualEnv = {
|
|
6464
|
+
...env,
|
|
6465
|
+
ELECTRON_RUN_AS_NODE: '1'
|
|
6466
|
+
};
|
|
6467
|
+
const ignoreStdio = stdio === 'inherit' ? undefined : true;
|
|
6468
|
+
const {
|
|
6469
|
+
Worker
|
|
6470
|
+
} = await import('node:worker_threads');
|
|
6471
|
+
const worker = new Worker(path, {
|
|
6472
|
+
argv: actualArgv,
|
|
6473
|
+
env: actualEnv,
|
|
6474
|
+
execArgv,
|
|
6475
|
+
name,
|
|
6476
|
+
stderr: ignoreStdio,
|
|
6477
|
+
stdout: ignoreStdio
|
|
6478
|
+
});
|
|
6479
|
+
const {
|
|
6480
|
+
event,
|
|
6481
|
+
type
|
|
6482
|
+
} = await getFirstNodeWorkerEvent(worker);
|
|
6483
|
+
if (type === Exit) {
|
|
6484
|
+
throw new IpcError(`Worker exited before ipc connection was established`);
|
|
6064
6485
|
}
|
|
6065
|
-
|
|
6066
|
-
};
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
const handleMessage = event => {
|
|
6071
|
-
return handleJsonRpcMessage(event.target, event.data, execute, resolve, prepare,
|
|
6072
|
-
// @ts-ignore
|
|
6073
|
-
logError, requiresSocket);
|
|
6074
|
-
};
|
|
6075
|
-
|
|
6076
|
-
const handleIpc = ipc => {
|
|
6077
|
-
if ('addEventListener' in ipc) {
|
|
6078
|
-
ipc.addEventListener('message', handleMessage);
|
|
6079
|
-
} else if ('on' in ipc) {
|
|
6080
|
-
// deprecated
|
|
6081
|
-
ipc.on('message', handleMessage);
|
|
6486
|
+
if (type === Error$2) {
|
|
6487
|
+
throw new IpcError(`Worker threw an error before ipc connection was established: ${event}`);
|
|
6488
|
+
}
|
|
6489
|
+
if (event !== readyMessage) {
|
|
6490
|
+
throw new IpcError('unexpected first message from worker');
|
|
6082
6491
|
}
|
|
6492
|
+
return worker;
|
|
6083
6493
|
};
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
}
|
|
6088
|
-
|
|
6494
|
+
class IpcParentWithNodeWorker extends Ipc {
|
|
6495
|
+
getData(message) {
|
|
6496
|
+
return message;
|
|
6497
|
+
}
|
|
6498
|
+
send(message) {
|
|
6499
|
+
this._rawIpc.postMessage(message);
|
|
6500
|
+
}
|
|
6501
|
+
sendAndTransfer(message) {
|
|
6502
|
+
const {
|
|
6503
|
+
newValue,
|
|
6504
|
+
transfer
|
|
6505
|
+
} = fixNodeWorkerParameters(message);
|
|
6506
|
+
this._rawIpc.postMessage(newValue, transfer);
|
|
6507
|
+
}
|
|
6508
|
+
async dispose() {
|
|
6509
|
+
await this._rawIpc.terminate();
|
|
6510
|
+
}
|
|
6511
|
+
onClose(callback) {
|
|
6512
|
+
this._rawIpc.on('exit', callback);
|
|
6513
|
+
}
|
|
6514
|
+
onMessage(callback) {
|
|
6515
|
+
this._rawIpc.on('message', callback);
|
|
6089
6516
|
}
|
|
6517
|
+
}
|
|
6518
|
+
const wrap$1 = worker => {
|
|
6519
|
+
return new IpcParentWithNodeWorker(worker);
|
|
6520
|
+
};
|
|
6521
|
+
const IpcParentWithNodeWorker$1 = {
|
|
6522
|
+
__proto__: null,
|
|
6523
|
+
create: create$1$1,
|
|
6524
|
+
wrap: wrap$1
|
|
6090
6525
|
};
|
|
6091
6526
|
|
|
6092
6527
|
const getModule$1 = method => {
|
|
@@ -6179,7 +6614,7 @@ const getWindowId = webContentsId => {
|
|
|
6179
6614
|
|
|
6180
6615
|
const handleElectronMessagePort = async (messagePort, rpcId) => {
|
|
6181
6616
|
object(messagePort);
|
|
6182
|
-
const rpc = await create$
|
|
6617
|
+
const rpc = await create$8({
|
|
6183
6618
|
commandMap: commandMapRef,
|
|
6184
6619
|
messagePort: messagePort,
|
|
6185
6620
|
requiresSocket: requiresSocket
|