@lvce-editor/main-process 2.1.0 → 2.3.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 +610 -577
- package/package.json +1 -1
package/dist/mainProcessMain.js
CHANGED
|
@@ -1660,451 +1660,105 @@ const ElectronUtilityProcess$1 = 3;
|
|
|
1660
1660
|
const ElectronMessagePort$1 = 4;
|
|
1661
1661
|
const RendererProcess2 = 8;
|
|
1662
1662
|
|
|
1663
|
-
const
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
}
|
|
1670
|
-
|
|
1671
|
-
const callbacks = Object.create(null);
|
|
1672
|
-
const set$2 = (id, fn) => {
|
|
1673
|
-
callbacks[id] = fn;
|
|
1674
|
-
};
|
|
1675
|
-
const get$3 = id => {
|
|
1676
|
-
return callbacks[id];
|
|
1677
|
-
};
|
|
1678
|
-
const remove$2 = id => {
|
|
1679
|
-
delete callbacks[id];
|
|
1680
|
-
};
|
|
1681
|
-
let id = 0;
|
|
1682
|
-
const create$3$1 = () => {
|
|
1683
|
-
return ++id;
|
|
1684
|
-
};
|
|
1685
|
-
const registerPromise = () => {
|
|
1686
|
-
const id = create$3$1();
|
|
1687
|
-
const {
|
|
1688
|
-
resolve,
|
|
1689
|
-
promise
|
|
1690
|
-
} = Promise.withResolvers();
|
|
1691
|
-
set$2(id, resolve);
|
|
1692
|
-
return {
|
|
1693
|
-
id,
|
|
1694
|
-
promise
|
|
1695
|
-
};
|
|
1696
|
-
};
|
|
1697
|
-
const create$2$2 = (method, params) => {
|
|
1698
|
-
const {
|
|
1699
|
-
id,
|
|
1700
|
-
promise
|
|
1701
|
-
} = registerPromise();
|
|
1702
|
-
const message = {
|
|
1703
|
-
jsonrpc: Two,
|
|
1704
|
-
method,
|
|
1705
|
-
params,
|
|
1706
|
-
id
|
|
1707
|
-
};
|
|
1708
|
-
return {
|
|
1709
|
-
message,
|
|
1710
|
-
promise
|
|
1711
|
-
};
|
|
1663
|
+
const normalizeLine = line => {
|
|
1664
|
+
if (line.startsWith('Error: ')) {
|
|
1665
|
+
return line.slice('Error: '.length);
|
|
1666
|
+
}
|
|
1667
|
+
if (line.startsWith('VError: ')) {
|
|
1668
|
+
return line.slice('VError: '.length);
|
|
1669
|
+
}
|
|
1670
|
+
return line;
|
|
1712
1671
|
};
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1672
|
+
const getCombinedMessage = (error, message) => {
|
|
1673
|
+
const stringifiedError = normalizeLine(`${error}`);
|
|
1674
|
+
if (message) {
|
|
1675
|
+
return `${message}: ${stringifiedError}`;
|
|
1717
1676
|
}
|
|
1718
|
-
|
|
1677
|
+
return stringifiedError;
|
|
1678
|
+
};
|
|
1719
1679
|
const NewLine$2 = '\n';
|
|
1720
|
-
const
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
const
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
switch (type) {
|
|
1727
|
-
case DomException:
|
|
1728
|
-
return DOMException;
|
|
1729
|
-
case TypeError$1:
|
|
1730
|
-
return TypeError;
|
|
1731
|
-
case SyntaxError$1:
|
|
1732
|
-
return SyntaxError;
|
|
1733
|
-
case ReferenceError$1:
|
|
1734
|
-
return ReferenceError;
|
|
1735
|
-
default:
|
|
1736
|
-
return Error;
|
|
1737
|
-
}
|
|
1738
|
-
}
|
|
1739
|
-
if (message.startsWith('TypeError: ')) {
|
|
1740
|
-
return TypeError;
|
|
1680
|
+
const getNewLineIndex$1 = (string, startIndex = undefined) => {
|
|
1681
|
+
return string.indexOf(NewLine$2, startIndex);
|
|
1682
|
+
};
|
|
1683
|
+
const mergeStacks = (parent, child) => {
|
|
1684
|
+
if (!child) {
|
|
1685
|
+
return parent;
|
|
1741
1686
|
}
|
|
1742
|
-
|
|
1743
|
-
|
|
1687
|
+
const parentNewLineIndex = getNewLineIndex$1(parent);
|
|
1688
|
+
const childNewLineIndex = getNewLineIndex$1(child);
|
|
1689
|
+
if (childNewLineIndex === -1) {
|
|
1690
|
+
return parent;
|
|
1744
1691
|
}
|
|
1745
|
-
|
|
1746
|
-
|
|
1692
|
+
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
1693
|
+
const childRest = child.slice(childNewLineIndex);
|
|
1694
|
+
const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
|
|
1695
|
+
if (parentFirstLine.includes(childFirstLine)) {
|
|
1696
|
+
return parentFirstLine + childRest;
|
|
1747
1697
|
}
|
|
1748
|
-
return
|
|
1698
|
+
return child;
|
|
1749
1699
|
};
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1700
|
+
class VError extends Error {
|
|
1701
|
+
constructor(error, message) {
|
|
1702
|
+
const combinedMessage = getCombinedMessage(error, message);
|
|
1703
|
+
super(combinedMessage);
|
|
1704
|
+
this.name = 'VError';
|
|
1705
|
+
if (error instanceof Error) {
|
|
1706
|
+
this.stack = mergeStacks(this.stack, error.stack);
|
|
1707
|
+
}
|
|
1708
|
+
if (error.codeFrame) {
|
|
1709
|
+
// @ts-ignore
|
|
1710
|
+
this.codeFrame = error.codeFrame;
|
|
1711
|
+
}
|
|
1712
|
+
if (error.code) {
|
|
1713
|
+
// @ts-ignore
|
|
1714
|
+
this.code = error.code;
|
|
1759
1715
|
}
|
|
1760
|
-
return error;
|
|
1761
1716
|
}
|
|
1762
|
-
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1719
|
+
const isMessagePort = value => {
|
|
1720
|
+
return value && value instanceof MessagePort;
|
|
1763
1721
|
};
|
|
1764
|
-
const
|
|
1765
|
-
return
|
|
1722
|
+
const isMessagePortMain = value => {
|
|
1723
|
+
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
1766
1724
|
};
|
|
1767
|
-
const
|
|
1768
|
-
|
|
1769
|
-
if (parentStack.startsWith(' at')) {
|
|
1770
|
-
parentStack = error.message + NewLine$2 + parentStack;
|
|
1771
|
-
}
|
|
1772
|
-
return parentStack;
|
|
1725
|
+
const isOffscreenCanvas = value => {
|
|
1726
|
+
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
1773
1727
|
};
|
|
1774
|
-
const
|
|
1775
|
-
return
|
|
1728
|
+
const isInstanceOf = (value, constructorName) => {
|
|
1729
|
+
return value?.constructor?.name === constructorName;
|
|
1776
1730
|
};
|
|
1777
|
-
const
|
|
1778
|
-
|
|
1779
|
-
const splitLines$1 = lines => {
|
|
1780
|
-
return lines.split(NewLine$2);
|
|
1731
|
+
const isSocket = value => {
|
|
1732
|
+
return isInstanceOf(value, 'Socket');
|
|
1781
1733
|
};
|
|
1782
|
-
const
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
if (error && error.code && error.code === MethodNotFound) {
|
|
1788
|
-
const restoredError = new JsonRpcError(error.message);
|
|
1789
|
-
const parentStack = getParentStack(error);
|
|
1790
|
-
restoredError.stack = parentStack + NewLine$2 + currentStack;
|
|
1791
|
-
return restoredError;
|
|
1792
|
-
}
|
|
1793
|
-
if (error && error.message) {
|
|
1794
|
-
const restoredError = constructError(error.message, error.type, error.name);
|
|
1795
|
-
if (error.data) {
|
|
1796
|
-
if (error.data.stack && error.data.type && error.message) {
|
|
1797
|
-
restoredError.stack = error.data.type + ': ' + error.message + NewLine$2 + error.data.stack + NewLine$2 + currentStack;
|
|
1798
|
-
} else if (error.data.stack) {
|
|
1799
|
-
restoredError.stack = error.data.stack;
|
|
1800
|
-
}
|
|
1801
|
-
if (error.data.codeFrame) {
|
|
1802
|
-
// @ts-ignore
|
|
1803
|
-
restoredError.codeFrame = error.data.codeFrame;
|
|
1804
|
-
}
|
|
1805
|
-
if (error.data.code) {
|
|
1806
|
-
// @ts-ignore
|
|
1807
|
-
restoredError.code = error.data.code;
|
|
1808
|
-
}
|
|
1809
|
-
if (error.data.type) {
|
|
1810
|
-
// @ts-ignore
|
|
1811
|
-
restoredError.name = error.data.type;
|
|
1812
|
-
}
|
|
1813
|
-
} else {
|
|
1814
|
-
if (error.stack) {
|
|
1815
|
-
const lowerStack = restoredError.stack || '';
|
|
1816
|
-
// @ts-ignore
|
|
1817
|
-
const indexNewLine = getNewLineIndex$1(lowerStack);
|
|
1818
|
-
const parentStack = getParentStack(error);
|
|
1819
|
-
// @ts-ignore
|
|
1820
|
-
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
1821
|
-
}
|
|
1822
|
-
if (error.codeFrame) {
|
|
1823
|
-
// @ts-ignore
|
|
1824
|
-
restoredError.codeFrame = error.codeFrame;
|
|
1825
|
-
}
|
|
1734
|
+
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
1735
|
+
const isTransferrable = value => {
|
|
1736
|
+
for (const fn of transferrables) {
|
|
1737
|
+
if (fn(value)) {
|
|
1738
|
+
return true;
|
|
1826
1739
|
}
|
|
1827
|
-
return restoredError;
|
|
1828
1740
|
}
|
|
1829
|
-
|
|
1830
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
1831
|
-
}
|
|
1832
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
1741
|
+
return false;
|
|
1833
1742
|
};
|
|
1834
|
-
const
|
|
1835
|
-
if (
|
|
1836
|
-
|
|
1837
|
-
throw restoredError;
|
|
1838
|
-
}
|
|
1839
|
-
if ('result' in responseMessage) {
|
|
1840
|
-
return responseMessage.result;
|
|
1743
|
+
const walkValue = (value, transferrables, isTransferrable) => {
|
|
1744
|
+
if (!value) {
|
|
1745
|
+
return;
|
|
1841
1746
|
}
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
const warn = (...args) => {
|
|
1845
|
-
console.warn(...args);
|
|
1846
|
-
};
|
|
1847
|
-
const resolve = (id, response) => {
|
|
1848
|
-
const fn = get$3(id);
|
|
1849
|
-
if (!fn) {
|
|
1850
|
-
console.log(response);
|
|
1851
|
-
warn(`callback ${id} may already be disposed`);
|
|
1747
|
+
if (isTransferrable(value)) {
|
|
1748
|
+
transferrables.push(value);
|
|
1852
1749
|
return;
|
|
1853
1750
|
}
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
if (prettyError && prettyError.type) {
|
|
1860
|
-
return prettyError.type;
|
|
1751
|
+
if (Array.isArray(value)) {
|
|
1752
|
+
for (const item of value) {
|
|
1753
|
+
walkValue(item, transferrables, isTransferrable);
|
|
1754
|
+
}
|
|
1755
|
+
return;
|
|
1861
1756
|
}
|
|
1862
|
-
if (
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
const getErrorProperty = (error, prettyError) => {
|
|
1868
|
-
if (error && error.code === E_COMMAND_NOT_FOUND$1) {
|
|
1869
|
-
return {
|
|
1870
|
-
code: MethodNotFound,
|
|
1871
|
-
message: error.message,
|
|
1872
|
-
data: error.stack
|
|
1873
|
-
};
|
|
1874
|
-
}
|
|
1875
|
-
return {
|
|
1876
|
-
code: Custom,
|
|
1877
|
-
message: prettyError.message,
|
|
1878
|
-
data: {
|
|
1879
|
-
stack: prettyError.stack,
|
|
1880
|
-
codeFrame: prettyError.codeFrame,
|
|
1881
|
-
type: getErrorType(prettyError),
|
|
1882
|
-
code: prettyError.code,
|
|
1883
|
-
name: prettyError.name
|
|
1884
|
-
}
|
|
1885
|
-
};
|
|
1886
|
-
};
|
|
1887
|
-
const create$1$2 = (message, error) => {
|
|
1888
|
-
return {
|
|
1889
|
-
jsonrpc: Two,
|
|
1890
|
-
id: message.id,
|
|
1891
|
-
error
|
|
1892
|
-
};
|
|
1893
|
-
};
|
|
1894
|
-
const getErrorResponse = (message, error, preparePrettyError, logError) => {
|
|
1895
|
-
const prettyError = preparePrettyError(error);
|
|
1896
|
-
logError(error, prettyError);
|
|
1897
|
-
const errorProperty = getErrorProperty(error, prettyError);
|
|
1898
|
-
return create$1$2(message, errorProperty);
|
|
1899
|
-
};
|
|
1900
|
-
const create$5 = (message, result) => {
|
|
1901
|
-
return {
|
|
1902
|
-
jsonrpc: Two,
|
|
1903
|
-
id: message.id,
|
|
1904
|
-
result: result ?? null
|
|
1905
|
-
};
|
|
1906
|
-
};
|
|
1907
|
-
const getSuccessResponse = (message, result) => {
|
|
1908
|
-
const resultProperty = result ?? null;
|
|
1909
|
-
return create$5(message, resultProperty);
|
|
1910
|
-
};
|
|
1911
|
-
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
1912
|
-
try {
|
|
1913
|
-
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
1914
|
-
return getSuccessResponse(message, result);
|
|
1915
|
-
} catch (error) {
|
|
1916
|
-
return getErrorResponse(message, error, preparePrettyError, logError);
|
|
1917
|
-
}
|
|
1918
|
-
};
|
|
1919
|
-
const defaultPreparePrettyError = error => {
|
|
1920
|
-
return error;
|
|
1921
|
-
};
|
|
1922
|
-
const defaultLogError = () => {
|
|
1923
|
-
// ignore
|
|
1924
|
-
};
|
|
1925
|
-
const defaultRequiresSocket = () => {
|
|
1926
|
-
return false;
|
|
1927
|
-
};
|
|
1928
|
-
const defaultResolve = resolve;
|
|
1929
|
-
|
|
1930
|
-
// TODO maybe remove this in v6 or v7, only accept options object to simplify the code
|
|
1931
|
-
const normalizeParams = args => {
|
|
1932
|
-
if (args.length === 1) {
|
|
1933
|
-
const options = args[0];
|
|
1934
|
-
return {
|
|
1935
|
-
ipc: options.ipc,
|
|
1936
|
-
message: options.message,
|
|
1937
|
-
execute: options.execute,
|
|
1938
|
-
resolve: options.resolve || defaultResolve,
|
|
1939
|
-
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
1940
|
-
logError: options.logError || defaultLogError,
|
|
1941
|
-
requiresSocket: options.requiresSocket || defaultRequiresSocket
|
|
1942
|
-
};
|
|
1943
|
-
}
|
|
1944
|
-
return {
|
|
1945
|
-
ipc: args[0],
|
|
1946
|
-
message: args[1],
|
|
1947
|
-
execute: args[2],
|
|
1948
|
-
resolve: args[3],
|
|
1949
|
-
preparePrettyError: args[4],
|
|
1950
|
-
logError: args[5],
|
|
1951
|
-
requiresSocket: args[6]
|
|
1952
|
-
};
|
|
1953
|
-
};
|
|
1954
|
-
const handleJsonRpcMessage = async (...args) => {
|
|
1955
|
-
const options = normalizeParams(args);
|
|
1956
|
-
const {
|
|
1957
|
-
message,
|
|
1958
|
-
ipc,
|
|
1959
|
-
execute,
|
|
1960
|
-
resolve,
|
|
1961
|
-
preparePrettyError,
|
|
1962
|
-
logError,
|
|
1963
|
-
requiresSocket
|
|
1964
|
-
} = options;
|
|
1965
|
-
if ('id' in message) {
|
|
1966
|
-
if ('method' in message) {
|
|
1967
|
-
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
1968
|
-
try {
|
|
1969
|
-
ipc.send(response);
|
|
1970
|
-
} catch (error) {
|
|
1971
|
-
const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
|
|
1972
|
-
ipc.send(errorResponse);
|
|
1973
|
-
}
|
|
1974
|
-
return;
|
|
1975
|
-
}
|
|
1976
|
-
resolve(message.id, message);
|
|
1977
|
-
return;
|
|
1978
|
-
}
|
|
1979
|
-
if ('method' in message) {
|
|
1980
|
-
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
1981
|
-
return;
|
|
1982
|
-
}
|
|
1983
|
-
throw new JsonRpcError('unexpected message');
|
|
1984
|
-
};
|
|
1985
|
-
const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
1986
|
-
const {
|
|
1987
|
-
message,
|
|
1988
|
-
promise
|
|
1989
|
-
} = create$2$2(method, params);
|
|
1990
|
-
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
1991
|
-
ipc.sendAndTransfer(message);
|
|
1992
|
-
} else {
|
|
1993
|
-
ipc.send(message);
|
|
1994
|
-
}
|
|
1995
|
-
const responseMessage = await promise;
|
|
1996
|
-
return unwrapJsonRpcResult(responseMessage);
|
|
1997
|
-
};
|
|
1998
|
-
const send$2 = (transport, method, ...params) => {
|
|
1999
|
-
const message = create$4(method, params);
|
|
2000
|
-
transport.send(message);
|
|
2001
|
-
};
|
|
2002
|
-
const invoke$1 = (ipc, method, ...params) => {
|
|
2003
|
-
return invokeHelper(ipc, method, params, false);
|
|
2004
|
-
};
|
|
2005
|
-
const invokeAndTransfer$1 = (ipc, method, ...params) => {
|
|
2006
|
-
return invokeHelper(ipc, method, params, true);
|
|
2007
|
-
};
|
|
2008
|
-
|
|
2009
|
-
const normalizeLine = line => {
|
|
2010
|
-
if (line.startsWith('Error: ')) {
|
|
2011
|
-
return line.slice('Error: '.length);
|
|
2012
|
-
}
|
|
2013
|
-
if (line.startsWith('VError: ')) {
|
|
2014
|
-
return line.slice('VError: '.length);
|
|
2015
|
-
}
|
|
2016
|
-
return line;
|
|
2017
|
-
};
|
|
2018
|
-
const getCombinedMessage = (error, message) => {
|
|
2019
|
-
const stringifiedError = normalizeLine(`${error}`);
|
|
2020
|
-
if (message) {
|
|
2021
|
-
return `${message}: ${stringifiedError}`;
|
|
2022
|
-
}
|
|
2023
|
-
return stringifiedError;
|
|
2024
|
-
};
|
|
2025
|
-
const NewLine$1 = '\n';
|
|
2026
|
-
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
2027
|
-
return string.indexOf(NewLine$1, startIndex);
|
|
2028
|
-
};
|
|
2029
|
-
const mergeStacks = (parent, child) => {
|
|
2030
|
-
if (!child) {
|
|
2031
|
-
return parent;
|
|
2032
|
-
}
|
|
2033
|
-
const parentNewLineIndex = getNewLineIndex(parent);
|
|
2034
|
-
const childNewLineIndex = getNewLineIndex(child);
|
|
2035
|
-
if (childNewLineIndex === -1) {
|
|
2036
|
-
return parent;
|
|
2037
|
-
}
|
|
2038
|
-
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
2039
|
-
const childRest = child.slice(childNewLineIndex);
|
|
2040
|
-
const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
|
|
2041
|
-
if (parentFirstLine.includes(childFirstLine)) {
|
|
2042
|
-
return parentFirstLine + childRest;
|
|
2043
|
-
}
|
|
2044
|
-
return child;
|
|
2045
|
-
};
|
|
2046
|
-
class VError extends Error {
|
|
2047
|
-
constructor(error, message) {
|
|
2048
|
-
const combinedMessage = getCombinedMessage(error, message);
|
|
2049
|
-
super(combinedMessage);
|
|
2050
|
-
this.name = 'VError';
|
|
2051
|
-
if (error instanceof Error) {
|
|
2052
|
-
this.stack = mergeStacks(this.stack, error.stack);
|
|
2053
|
-
}
|
|
2054
|
-
if (error.codeFrame) {
|
|
2055
|
-
// @ts-ignore
|
|
2056
|
-
this.codeFrame = error.codeFrame;
|
|
2057
|
-
}
|
|
2058
|
-
if (error.code) {
|
|
2059
|
-
// @ts-ignore
|
|
2060
|
-
this.code = error.code;
|
|
2061
|
-
}
|
|
2062
|
-
}
|
|
2063
|
-
}
|
|
2064
|
-
|
|
2065
|
-
const isMessagePort = value => {
|
|
2066
|
-
return value && value instanceof MessagePort;
|
|
2067
|
-
};
|
|
2068
|
-
const isMessagePortMain = value => {
|
|
2069
|
-
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
2070
|
-
};
|
|
2071
|
-
const isOffscreenCanvas = value => {
|
|
2072
|
-
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
2073
|
-
};
|
|
2074
|
-
const isInstanceOf = (value, constructorName) => {
|
|
2075
|
-
return value?.constructor?.name === constructorName;
|
|
2076
|
-
};
|
|
2077
|
-
const isSocket = value => {
|
|
2078
|
-
return isInstanceOf(value, 'Socket');
|
|
2079
|
-
};
|
|
2080
|
-
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
2081
|
-
const isTransferrable = value => {
|
|
2082
|
-
for (const fn of transferrables) {
|
|
2083
|
-
if (fn(value)) {
|
|
2084
|
-
return true;
|
|
2085
|
-
}
|
|
2086
|
-
}
|
|
2087
|
-
return false;
|
|
2088
|
-
};
|
|
2089
|
-
const walkValue = (value, transferrables, isTransferrable) => {
|
|
2090
|
-
if (!value) {
|
|
2091
|
-
return;
|
|
2092
|
-
}
|
|
2093
|
-
if (isTransferrable(value)) {
|
|
2094
|
-
transferrables.push(value);
|
|
2095
|
-
return;
|
|
2096
|
-
}
|
|
2097
|
-
if (Array.isArray(value)) {
|
|
2098
|
-
for (const item of value) {
|
|
2099
|
-
walkValue(item, transferrables, isTransferrable);
|
|
2100
|
-
}
|
|
2101
|
-
return;
|
|
2102
|
-
}
|
|
2103
|
-
if (typeof value === 'object') {
|
|
2104
|
-
for (const property of Object.values(value)) {
|
|
2105
|
-
walkValue(property, transferrables, isTransferrable);
|
|
2106
|
-
}
|
|
2107
|
-
return;
|
|
1757
|
+
if (typeof value === 'object') {
|
|
1758
|
+
for (const property of Object.values(value)) {
|
|
1759
|
+
walkValue(property, transferrables, isTransferrable);
|
|
1760
|
+
}
|
|
1761
|
+
return;
|
|
2108
1762
|
}
|
|
2109
1763
|
};
|
|
2110
1764
|
const getTransferrables = value => {
|
|
@@ -2184,9 +1838,9 @@ class Ipc extends EventTarget {
|
|
|
2184
1838
|
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
2185
1839
|
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
2186
1840
|
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
2187
|
-
const NewLine = '\n';
|
|
2188
|
-
const joinLines = lines => {
|
|
2189
|
-
return lines.join(NewLine);
|
|
1841
|
+
const NewLine$1 = '\n';
|
|
1842
|
+
const joinLines$1 = lines => {
|
|
1843
|
+
return lines.join(NewLine$1);
|
|
2190
1844
|
};
|
|
2191
1845
|
const RE_AT = /^\s+at/;
|
|
2192
1846
|
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
|
|
@@ -2197,7 +1851,7 @@ const getDetails = lines => {
|
|
|
2197
1851
|
const index = lines.findIndex(isNormalStackLine);
|
|
2198
1852
|
if (index === -1) {
|
|
2199
1853
|
return {
|
|
2200
|
-
actualMessage: joinLines(lines),
|
|
1854
|
+
actualMessage: joinLines$1(lines),
|
|
2201
1855
|
rest: []
|
|
2202
1856
|
};
|
|
2203
1857
|
}
|
|
@@ -2212,8 +1866,8 @@ const getDetails = lines => {
|
|
|
2212
1866
|
rest: lines.slice(index, lastIndex)
|
|
2213
1867
|
};
|
|
2214
1868
|
};
|
|
2215
|
-
const splitLines = lines => {
|
|
2216
|
-
return lines.split(NewLine);
|
|
1869
|
+
const splitLines$1 = lines => {
|
|
1870
|
+
return lines.split(NewLine$1);
|
|
2217
1871
|
};
|
|
2218
1872
|
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
|
|
2219
1873
|
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
|
|
@@ -2224,7 +1878,7 @@ const isMessageCodeBlockEndIndex = line => {
|
|
|
2224
1878
|
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
2225
1879
|
};
|
|
2226
1880
|
const getMessageCodeBlock = stderr => {
|
|
2227
|
-
const lines = splitLines(stderr);
|
|
1881
|
+
const lines = splitLines$1(stderr);
|
|
2228
1882
|
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
|
|
2229
1883
|
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
2230
1884
|
const relevantLines = lines.slice(startIndex, endIndex);
|
|
@@ -2235,7 +1889,7 @@ const isModuleNotFoundMessage = line => {
|
|
|
2235
1889
|
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
2236
1890
|
};
|
|
2237
1891
|
const getModuleNotFoundError = stderr => {
|
|
2238
|
-
const lines = splitLines(stderr);
|
|
1892
|
+
const lines = splitLines$1(stderr);
|
|
2239
1893
|
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
2240
1894
|
const message = lines[messageIndex];
|
|
2241
1895
|
return {
|
|
@@ -2283,7 +1937,7 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
|
2283
1937
|
if (isModuleNotFoundError(stderr)) {
|
|
2284
1938
|
return getModuleNotFoundError(stderr);
|
|
2285
1939
|
}
|
|
2286
|
-
const lines = splitLines(stderr);
|
|
1940
|
+
const lines = splitLines$1(stderr);
|
|
2287
1941
|
const {
|
|
2288
1942
|
actualMessage,
|
|
2289
1943
|
rest
|
|
@@ -2793,10 +2447,10 @@ class ChildProcessError extends Error {
|
|
|
2793
2447
|
}
|
|
2794
2448
|
if (stack) {
|
|
2795
2449
|
// @ts-ignore
|
|
2796
|
-
const lines = splitLines(this.stack);
|
|
2450
|
+
const lines = splitLines$1(this.stack);
|
|
2797
2451
|
const [firstLine, ...stackLines] = lines;
|
|
2798
2452
|
const newStackLines = [firstLine, ...stack, ...stackLines];
|
|
2799
|
-
const newStack = joinLines(newStackLines);
|
|
2453
|
+
const newStack = joinLines$1(newStackLines);
|
|
2800
2454
|
this.stack = newStack;
|
|
2801
2455
|
}
|
|
2802
2456
|
}
|
|
@@ -2882,7 +2536,7 @@ const getFirstNodeChildProcessEvent = async childProcess => {
|
|
|
2882
2536
|
};
|
|
2883
2537
|
|
|
2884
2538
|
// @ts-ignore
|
|
2885
|
-
const create$2$
|
|
2539
|
+
const create$2$2 = async ({
|
|
2886
2540
|
path,
|
|
2887
2541
|
argv = [],
|
|
2888
2542
|
env,
|
|
@@ -2952,96 +2606,442 @@ class IpcParentWithNodeForkedProcess extends Ipc {
|
|
|
2952
2606
|
const wrap$2 = childProcess => {
|
|
2953
2607
|
return new IpcParentWithNodeForkedProcess(childProcess);
|
|
2954
2608
|
};
|
|
2955
|
-
const IpcParentWithNodeForkedProcess$1 = {
|
|
2956
|
-
__proto__: null,
|
|
2957
|
-
create: create$2$
|
|
2958
|
-
wrap: wrap$2
|
|
2609
|
+
const IpcParentWithNodeForkedProcess$1 = {
|
|
2610
|
+
__proto__: null,
|
|
2611
|
+
create: create$2$2,
|
|
2612
|
+
wrap: wrap$2
|
|
2613
|
+
};
|
|
2614
|
+
const fixNodeWorkerParameters = value => {
|
|
2615
|
+
const transfer = getTransferrables(value);
|
|
2616
|
+
if (transfer.length === 0) {
|
|
2617
|
+
throw new IpcError('no transferrables found');
|
|
2618
|
+
}
|
|
2619
|
+
return {
|
|
2620
|
+
newValue: value,
|
|
2621
|
+
transfer: transfer
|
|
2622
|
+
};
|
|
2623
|
+
};
|
|
2624
|
+
const getFirstNodeWorkerEvent = worker => {
|
|
2625
|
+
return getFirstEvent(worker, {
|
|
2626
|
+
message: Message$1,
|
|
2627
|
+
exit: Exit$1,
|
|
2628
|
+
error: Error$2
|
|
2629
|
+
});
|
|
2630
|
+
};
|
|
2631
|
+
|
|
2632
|
+
// @ts-ignore
|
|
2633
|
+
const create$1$2 = async ({
|
|
2634
|
+
path,
|
|
2635
|
+
argv = [],
|
|
2636
|
+
env = process.env,
|
|
2637
|
+
execArgv = []
|
|
2638
|
+
}) => {
|
|
2639
|
+
string(path);
|
|
2640
|
+
const actualArgv = ['--ipc-type=node-worker', ...argv];
|
|
2641
|
+
const actualEnv = {
|
|
2642
|
+
...env,
|
|
2643
|
+
ELECTRON_RUN_AS_NODE: '1'
|
|
2644
|
+
};
|
|
2645
|
+
const {
|
|
2646
|
+
Worker
|
|
2647
|
+
} = await import('node:worker_threads');
|
|
2648
|
+
const worker = new Worker(path, {
|
|
2649
|
+
argv: actualArgv,
|
|
2650
|
+
env: actualEnv,
|
|
2651
|
+
execArgv
|
|
2652
|
+
});
|
|
2653
|
+
const {
|
|
2654
|
+
type,
|
|
2655
|
+
event
|
|
2656
|
+
} = await getFirstNodeWorkerEvent(worker);
|
|
2657
|
+
if (type === Exit$1) {
|
|
2658
|
+
throw new IpcError(`Worker exited before ipc connection was established`);
|
|
2659
|
+
}
|
|
2660
|
+
if (type === Error$2) {
|
|
2661
|
+
throw new IpcError(`Worker threw an error before ipc connection was established: ${event}`);
|
|
2662
|
+
}
|
|
2663
|
+
if (event !== readyMessage) {
|
|
2664
|
+
throw new IpcError('unexpected first message from worker');
|
|
2665
|
+
}
|
|
2666
|
+
return worker;
|
|
2667
|
+
};
|
|
2668
|
+
class IpcParentWithNodeWorker extends Ipc {
|
|
2669
|
+
getData(message) {
|
|
2670
|
+
return message;
|
|
2671
|
+
}
|
|
2672
|
+
send(message) {
|
|
2673
|
+
this._rawIpc.postMessage(message);
|
|
2674
|
+
}
|
|
2675
|
+
sendAndTransfer(message) {
|
|
2676
|
+
const {
|
|
2677
|
+
newValue,
|
|
2678
|
+
transfer
|
|
2679
|
+
} = fixNodeWorkerParameters(message);
|
|
2680
|
+
this._rawIpc.postMessage(newValue, transfer);
|
|
2681
|
+
}
|
|
2682
|
+
async dispose() {
|
|
2683
|
+
await this._rawIpc.terminate();
|
|
2684
|
+
}
|
|
2685
|
+
onClose(callback) {
|
|
2686
|
+
this._rawIpc.on('exit', callback);
|
|
2687
|
+
}
|
|
2688
|
+
onMessage(callback) {
|
|
2689
|
+
this._rawIpc.on('message', callback);
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
const wrap$1 = worker => {
|
|
2693
|
+
return new IpcParentWithNodeWorker(worker);
|
|
2694
|
+
};
|
|
2695
|
+
const IpcParentWithNodeWorker$1 = {
|
|
2696
|
+
__proto__: null,
|
|
2697
|
+
create: create$1$2,
|
|
2698
|
+
wrap: wrap$1
|
|
2699
|
+
};
|
|
2700
|
+
|
|
2701
|
+
const Two = '2.0';
|
|
2702
|
+
const create$4 = (method, params) => {
|
|
2703
|
+
return {
|
|
2704
|
+
jsonrpc: Two,
|
|
2705
|
+
method,
|
|
2706
|
+
params
|
|
2707
|
+
};
|
|
2708
|
+
};
|
|
2709
|
+
const callbacks = Object.create(null);
|
|
2710
|
+
const set$2 = (id, fn) => {
|
|
2711
|
+
callbacks[id] = fn;
|
|
2712
|
+
};
|
|
2713
|
+
const get$3 = id => {
|
|
2714
|
+
return callbacks[id];
|
|
2715
|
+
};
|
|
2716
|
+
const remove$2 = id => {
|
|
2717
|
+
delete callbacks[id];
|
|
2718
|
+
};
|
|
2719
|
+
let id = 0;
|
|
2720
|
+
const create$3 = () => {
|
|
2721
|
+
return ++id;
|
|
2722
|
+
};
|
|
2723
|
+
const registerPromise = () => {
|
|
2724
|
+
const id = create$3();
|
|
2725
|
+
const {
|
|
2726
|
+
resolve,
|
|
2727
|
+
promise
|
|
2728
|
+
} = Promise.withResolvers();
|
|
2729
|
+
set$2(id, resolve);
|
|
2730
|
+
return {
|
|
2731
|
+
id,
|
|
2732
|
+
promise
|
|
2733
|
+
};
|
|
2734
|
+
};
|
|
2735
|
+
const create$2$1 = (method, params) => {
|
|
2736
|
+
const {
|
|
2737
|
+
id,
|
|
2738
|
+
promise
|
|
2739
|
+
} = registerPromise();
|
|
2740
|
+
const message = {
|
|
2741
|
+
jsonrpc: Two,
|
|
2742
|
+
method,
|
|
2743
|
+
params,
|
|
2744
|
+
id
|
|
2745
|
+
};
|
|
2746
|
+
return {
|
|
2747
|
+
message,
|
|
2748
|
+
promise
|
|
2749
|
+
};
|
|
2750
|
+
};
|
|
2751
|
+
class JsonRpcError extends Error {
|
|
2752
|
+
constructor(message) {
|
|
2753
|
+
super(message);
|
|
2754
|
+
this.name = 'JsonRpcError';
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
const NewLine = '\n';
|
|
2758
|
+
const DomException = 'DOMException';
|
|
2759
|
+
const ReferenceError$1 = 'ReferenceError';
|
|
2760
|
+
const SyntaxError$1 = 'SyntaxError';
|
|
2761
|
+
const TypeError$1 = 'TypeError';
|
|
2762
|
+
const getErrorConstructor = (message, type) => {
|
|
2763
|
+
if (type) {
|
|
2764
|
+
switch (type) {
|
|
2765
|
+
case DomException:
|
|
2766
|
+
return DOMException;
|
|
2767
|
+
case TypeError$1:
|
|
2768
|
+
return TypeError;
|
|
2769
|
+
case SyntaxError$1:
|
|
2770
|
+
return SyntaxError;
|
|
2771
|
+
case ReferenceError$1:
|
|
2772
|
+
return ReferenceError;
|
|
2773
|
+
default:
|
|
2774
|
+
return Error;
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
if (message.startsWith('TypeError: ')) {
|
|
2778
|
+
return TypeError;
|
|
2779
|
+
}
|
|
2780
|
+
if (message.startsWith('SyntaxError: ')) {
|
|
2781
|
+
return SyntaxError;
|
|
2782
|
+
}
|
|
2783
|
+
if (message.startsWith('ReferenceError: ')) {
|
|
2784
|
+
return ReferenceError;
|
|
2785
|
+
}
|
|
2786
|
+
return Error;
|
|
2787
|
+
};
|
|
2788
|
+
const constructError = (message, type, name) => {
|
|
2789
|
+
const ErrorConstructor = getErrorConstructor(message, type);
|
|
2790
|
+
if (ErrorConstructor === DOMException && name) {
|
|
2791
|
+
return new ErrorConstructor(message, name);
|
|
2792
|
+
}
|
|
2793
|
+
if (ErrorConstructor === Error) {
|
|
2794
|
+
const error = new Error(message);
|
|
2795
|
+
if (name && name !== 'VError') {
|
|
2796
|
+
error.name = name;
|
|
2797
|
+
}
|
|
2798
|
+
return error;
|
|
2799
|
+
}
|
|
2800
|
+
return new ErrorConstructor(message);
|
|
2801
|
+
};
|
|
2802
|
+
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
2803
|
+
return string.indexOf(NewLine, startIndex);
|
|
2804
|
+
};
|
|
2805
|
+
const getParentStack = error => {
|
|
2806
|
+
let parentStack = error.stack || error.data || error.message || '';
|
|
2807
|
+
if (parentStack.startsWith(' at')) {
|
|
2808
|
+
parentStack = error.message + NewLine + parentStack;
|
|
2809
|
+
}
|
|
2810
|
+
return parentStack;
|
|
2811
|
+
};
|
|
2812
|
+
const joinLines = lines => {
|
|
2813
|
+
return lines.join(NewLine);
|
|
2814
|
+
};
|
|
2815
|
+
const MethodNotFound = -32601;
|
|
2816
|
+
const Custom = -32001;
|
|
2817
|
+
const splitLines = lines => {
|
|
2818
|
+
return lines.split(NewLine);
|
|
2819
|
+
};
|
|
2820
|
+
const restoreJsonRpcError = error => {
|
|
2821
|
+
if (error && error instanceof Error) {
|
|
2822
|
+
return error;
|
|
2823
|
+
}
|
|
2824
|
+
const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
|
|
2825
|
+
if (error && error.code && error.code === MethodNotFound) {
|
|
2826
|
+
const restoredError = new JsonRpcError(error.message);
|
|
2827
|
+
const parentStack = getParentStack(error);
|
|
2828
|
+
restoredError.stack = parentStack + NewLine + currentStack;
|
|
2829
|
+
return restoredError;
|
|
2830
|
+
}
|
|
2831
|
+
if (error && error.message) {
|
|
2832
|
+
const restoredError = constructError(error.message, error.type, error.name);
|
|
2833
|
+
if (error.data) {
|
|
2834
|
+
if (error.data.stack && error.data.type && error.message) {
|
|
2835
|
+
restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
|
|
2836
|
+
} else if (error.data.stack) {
|
|
2837
|
+
restoredError.stack = error.data.stack;
|
|
2838
|
+
}
|
|
2839
|
+
if (error.data.codeFrame) {
|
|
2840
|
+
// @ts-ignore
|
|
2841
|
+
restoredError.codeFrame = error.data.codeFrame;
|
|
2842
|
+
}
|
|
2843
|
+
if (error.data.code) {
|
|
2844
|
+
// @ts-ignore
|
|
2845
|
+
restoredError.code = error.data.code;
|
|
2846
|
+
}
|
|
2847
|
+
if (error.data.type) {
|
|
2848
|
+
// @ts-ignore
|
|
2849
|
+
restoredError.name = error.data.type;
|
|
2850
|
+
}
|
|
2851
|
+
} else {
|
|
2852
|
+
if (error.stack) {
|
|
2853
|
+
const lowerStack = restoredError.stack || '';
|
|
2854
|
+
// @ts-ignore
|
|
2855
|
+
const indexNewLine = getNewLineIndex(lowerStack);
|
|
2856
|
+
const parentStack = getParentStack(error);
|
|
2857
|
+
// @ts-ignore
|
|
2858
|
+
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
2859
|
+
}
|
|
2860
|
+
if (error.codeFrame) {
|
|
2861
|
+
// @ts-ignore
|
|
2862
|
+
restoredError.codeFrame = error.codeFrame;
|
|
2863
|
+
}
|
|
2864
|
+
}
|
|
2865
|
+
return restoredError;
|
|
2866
|
+
}
|
|
2867
|
+
if (typeof error === 'string') {
|
|
2868
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
2869
|
+
}
|
|
2870
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
2871
|
+
};
|
|
2872
|
+
const unwrapJsonRpcResult = responseMessage => {
|
|
2873
|
+
if ('error' in responseMessage) {
|
|
2874
|
+
const restoredError = restoreJsonRpcError(responseMessage.error);
|
|
2875
|
+
throw restoredError;
|
|
2876
|
+
}
|
|
2877
|
+
if ('result' in responseMessage) {
|
|
2878
|
+
return responseMessage.result;
|
|
2879
|
+
}
|
|
2880
|
+
throw new JsonRpcError('unexpected response message');
|
|
2881
|
+
};
|
|
2882
|
+
const warn = (...args) => {
|
|
2883
|
+
console.warn(...args);
|
|
2884
|
+
};
|
|
2885
|
+
const resolve = (id, response) => {
|
|
2886
|
+
const fn = get$3(id);
|
|
2887
|
+
if (!fn) {
|
|
2888
|
+
console.log(response);
|
|
2889
|
+
warn(`callback ${id} may already be disposed`);
|
|
2890
|
+
return;
|
|
2891
|
+
}
|
|
2892
|
+
fn(response);
|
|
2893
|
+
remove$2(id);
|
|
2894
|
+
};
|
|
2895
|
+
const E_COMMAND_NOT_FOUND$1 = 'E_COMMAND_NOT_FOUND';
|
|
2896
|
+
const getErrorType = prettyError => {
|
|
2897
|
+
if (prettyError && prettyError.type) {
|
|
2898
|
+
return prettyError.type;
|
|
2899
|
+
}
|
|
2900
|
+
if (prettyError && prettyError.constructor && prettyError.constructor.name) {
|
|
2901
|
+
return prettyError.constructor.name;
|
|
2902
|
+
}
|
|
2903
|
+
return undefined;
|
|
2904
|
+
};
|
|
2905
|
+
const getErrorProperty = (error, prettyError) => {
|
|
2906
|
+
if (error && error.code === E_COMMAND_NOT_FOUND$1) {
|
|
2907
|
+
return {
|
|
2908
|
+
code: MethodNotFound,
|
|
2909
|
+
message: error.message,
|
|
2910
|
+
data: error.stack
|
|
2911
|
+
};
|
|
2912
|
+
}
|
|
2913
|
+
return {
|
|
2914
|
+
code: Custom,
|
|
2915
|
+
message: prettyError.message,
|
|
2916
|
+
data: {
|
|
2917
|
+
stack: prettyError.stack,
|
|
2918
|
+
codeFrame: prettyError.codeFrame,
|
|
2919
|
+
type: getErrorType(prettyError),
|
|
2920
|
+
code: prettyError.code,
|
|
2921
|
+
name: prettyError.name
|
|
2922
|
+
}
|
|
2923
|
+
};
|
|
2924
|
+
};
|
|
2925
|
+
const create$1$1 = (message, error) => {
|
|
2926
|
+
return {
|
|
2927
|
+
jsonrpc: Two,
|
|
2928
|
+
id: message.id,
|
|
2929
|
+
error
|
|
2930
|
+
};
|
|
2931
|
+
};
|
|
2932
|
+
const getErrorResponse = (message, error, preparePrettyError, logError) => {
|
|
2933
|
+
const prettyError = preparePrettyError(error);
|
|
2934
|
+
logError(error, prettyError);
|
|
2935
|
+
const errorProperty = getErrorProperty(error, prettyError);
|
|
2936
|
+
return create$1$1(message, errorProperty);
|
|
2937
|
+
};
|
|
2938
|
+
const create$5 = (message, result) => {
|
|
2939
|
+
return {
|
|
2940
|
+
jsonrpc: Two,
|
|
2941
|
+
id: message.id,
|
|
2942
|
+
result: result ?? null
|
|
2943
|
+
};
|
|
2944
|
+
};
|
|
2945
|
+
const getSuccessResponse = (message, result) => {
|
|
2946
|
+
const resultProperty = result ?? null;
|
|
2947
|
+
return create$5(message, resultProperty);
|
|
2959
2948
|
};
|
|
2960
|
-
const
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2949
|
+
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
2950
|
+
try {
|
|
2951
|
+
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
2952
|
+
return getSuccessResponse(message, result);
|
|
2953
|
+
} catch (error) {
|
|
2954
|
+
return getErrorResponse(message, error, preparePrettyError, logError);
|
|
2964
2955
|
}
|
|
2965
|
-
return {
|
|
2966
|
-
newValue: value,
|
|
2967
|
-
transfer: transfer
|
|
2968
|
-
};
|
|
2969
2956
|
};
|
|
2970
|
-
const
|
|
2971
|
-
return
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2957
|
+
const defaultPreparePrettyError = error => {
|
|
2958
|
+
return error;
|
|
2959
|
+
};
|
|
2960
|
+
const defaultLogError = () => {
|
|
2961
|
+
// ignore
|
|
2962
|
+
};
|
|
2963
|
+
const defaultRequiresSocket = () => {
|
|
2964
|
+
return false;
|
|
2976
2965
|
};
|
|
2966
|
+
const defaultResolve = resolve;
|
|
2977
2967
|
|
|
2978
|
-
//
|
|
2979
|
-
const
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2968
|
+
// TODO maybe remove this in v6 or v7, only accept options object to simplify the code
|
|
2969
|
+
const normalizeParams = args => {
|
|
2970
|
+
if (args.length === 1) {
|
|
2971
|
+
const options = args[0];
|
|
2972
|
+
return {
|
|
2973
|
+
ipc: options.ipc,
|
|
2974
|
+
message: options.message,
|
|
2975
|
+
execute: options.execute,
|
|
2976
|
+
resolve: options.resolve || defaultResolve,
|
|
2977
|
+
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
2978
|
+
logError: options.logError || defaultLogError,
|
|
2979
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket
|
|
2980
|
+
};
|
|
2981
|
+
}
|
|
2982
|
+
return {
|
|
2983
|
+
ipc: args[0],
|
|
2984
|
+
message: args[1],
|
|
2985
|
+
execute: args[2],
|
|
2986
|
+
resolve: args[3],
|
|
2987
|
+
preparePrettyError: args[4],
|
|
2988
|
+
logError: args[5],
|
|
2989
|
+
requiresSocket: args[6]
|
|
2990
2990
|
};
|
|
2991
|
+
};
|
|
2992
|
+
const handleJsonRpcMessage = async (...args) => {
|
|
2993
|
+
const options = normalizeParams(args);
|
|
2991
2994
|
const {
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
2995
|
+
message,
|
|
2996
|
+
ipc,
|
|
2997
|
+
execute,
|
|
2998
|
+
resolve,
|
|
2999
|
+
preparePrettyError,
|
|
3000
|
+
logError,
|
|
3001
|
+
requiresSocket
|
|
3002
|
+
} = options;
|
|
3003
|
+
if ('id' in message) {
|
|
3004
|
+
if ('method' in message) {
|
|
3005
|
+
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
3006
|
+
try {
|
|
3007
|
+
ipc.send(response);
|
|
3008
|
+
} catch (error) {
|
|
3009
|
+
const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
|
|
3010
|
+
ipc.send(errorResponse);
|
|
3011
|
+
}
|
|
3012
|
+
return;
|
|
3013
|
+
}
|
|
3014
|
+
resolve(message.id, message);
|
|
3015
|
+
return;
|
|
3008
3016
|
}
|
|
3009
|
-
if (
|
|
3010
|
-
|
|
3017
|
+
if ('method' in message) {
|
|
3018
|
+
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
3019
|
+
return;
|
|
3011
3020
|
}
|
|
3012
|
-
|
|
3021
|
+
throw new JsonRpcError('unexpected message');
|
|
3013
3022
|
};
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
newValue,
|
|
3024
|
-
transfer
|
|
3025
|
-
} = fixNodeWorkerParameters(message);
|
|
3026
|
-
this._rawIpc.postMessage(newValue, transfer);
|
|
3027
|
-
}
|
|
3028
|
-
async dispose() {
|
|
3029
|
-
await this._rawIpc.terminate();
|
|
3030
|
-
}
|
|
3031
|
-
onClose(callback) {
|
|
3032
|
-
this._rawIpc.on('exit', callback);
|
|
3033
|
-
}
|
|
3034
|
-
onMessage(callback) {
|
|
3035
|
-
this._rawIpc.on('message', callback);
|
|
3023
|
+
const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
3024
|
+
const {
|
|
3025
|
+
message,
|
|
3026
|
+
promise
|
|
3027
|
+
} = create$2$1(method, params);
|
|
3028
|
+
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
3029
|
+
ipc.sendAndTransfer(message);
|
|
3030
|
+
} else {
|
|
3031
|
+
ipc.send(message);
|
|
3036
3032
|
}
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
return new IpcParentWithNodeWorker(worker);
|
|
3033
|
+
const responseMessage = await promise;
|
|
3034
|
+
return unwrapJsonRpcResult(responseMessage);
|
|
3040
3035
|
};
|
|
3041
|
-
const
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3036
|
+
const send$2 = (transport, method, ...params) => {
|
|
3037
|
+
const message = create$4(method, params);
|
|
3038
|
+
transport.send(message);
|
|
3039
|
+
};
|
|
3040
|
+
const invoke$1 = (ipc, method, ...params) => {
|
|
3041
|
+
return invokeHelper(ipc, method, params, false);
|
|
3042
|
+
};
|
|
3043
|
+
const invokeAndTransfer$1 = (ipc, method, ...params) => {
|
|
3044
|
+
return invokeHelper(ipc, method, params, true);
|
|
3045
3045
|
};
|
|
3046
3046
|
|
|
3047
3047
|
const commands = Object.create(null);
|
|
@@ -3111,7 +3111,7 @@ const listen$1 = async (module, options) => {
|
|
|
3111
3111
|
const ipc = module.wrap(rawIpc);
|
|
3112
3112
|
return ipc;
|
|
3113
3113
|
};
|
|
3114
|
-
const create$
|
|
3114
|
+
const create$e = async ({
|
|
3115
3115
|
commandMap,
|
|
3116
3116
|
messagePort,
|
|
3117
3117
|
requiresSocket
|
|
@@ -3130,9 +3130,9 @@ const create$d = async ({
|
|
|
3130
3130
|
};
|
|
3131
3131
|
const ElectronMessagePortRpcClient = {
|
|
3132
3132
|
__proto__: null,
|
|
3133
|
-
create: create$
|
|
3133
|
+
create: create$e
|
|
3134
3134
|
};
|
|
3135
|
-
const create$
|
|
3135
|
+
const create$c = async ({
|
|
3136
3136
|
commandMap,
|
|
3137
3137
|
env,
|
|
3138
3138
|
argv,
|
|
@@ -3161,7 +3161,27 @@ const create$3 = async ({
|
|
|
3161
3161
|
};
|
|
3162
3162
|
const ElectronUtilityProcessRpcParent = {
|
|
3163
3163
|
__proto__: null,
|
|
3164
|
-
create: create$
|
|
3164
|
+
create: create$c
|
|
3165
|
+
};
|
|
3166
|
+
const create$b = async ({
|
|
3167
|
+
commandMap,
|
|
3168
|
+
webContents,
|
|
3169
|
+
requiresSocket
|
|
3170
|
+
}) => {
|
|
3171
|
+
// TODO create a commandMap per rpc instance
|
|
3172
|
+
register$1(commandMap);
|
|
3173
|
+
const ipc = IpcChildWithRendererProcess2$1.wrap(webContents);
|
|
3174
|
+
if (requiresSocket) {
|
|
3175
|
+
// @ts-ignore
|
|
3176
|
+
ipc.requiresSocket = requiresSocket;
|
|
3177
|
+
}
|
|
3178
|
+
handleIpc$1(ipc);
|
|
3179
|
+
const rpc = createRpc(ipc);
|
|
3180
|
+
return rpc;
|
|
3181
|
+
};
|
|
3182
|
+
const ElectronWebContentsRpcClient = {
|
|
3183
|
+
__proto__: null,
|
|
3184
|
+
create: create$b
|
|
3165
3185
|
};
|
|
3166
3186
|
|
|
3167
3187
|
const commandMapRef = Object.create(null);
|
|
@@ -3338,22 +3358,22 @@ const getOrCreate = async ({
|
|
|
3338
3358
|
return state$7.promise;
|
|
3339
3359
|
};
|
|
3340
3360
|
const send$1 = async (method, ...params) => {
|
|
3341
|
-
const
|
|
3361
|
+
const rpc = await getOrCreate({
|
|
3342
3362
|
method: ElectronUtilityProcess$1
|
|
3343
3363
|
});
|
|
3344
|
-
send
|
|
3364
|
+
rpc.send(method, ...params);
|
|
3345
3365
|
};
|
|
3346
3366
|
const invoke = async (method, ...params) => {
|
|
3347
|
-
const
|
|
3367
|
+
const rpc = await getOrCreate({
|
|
3348
3368
|
method: ElectronUtilityProcess$1
|
|
3349
3369
|
});
|
|
3350
|
-
return invoke
|
|
3370
|
+
return rpc.invoke(method, ...params);
|
|
3351
3371
|
};
|
|
3352
|
-
const invokeAndTransfer = async (
|
|
3353
|
-
const
|
|
3372
|
+
const invokeAndTransfer = async (method, ...params) => {
|
|
3373
|
+
const rpc = await getOrCreate({
|
|
3354
3374
|
method: ElectronUtilityProcess$1
|
|
3355
3375
|
});
|
|
3356
|
-
return invokeAndTransfer
|
|
3376
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
3357
3377
|
};
|
|
3358
3378
|
|
|
3359
3379
|
const handleCliArgs = async parsedArgs => {
|
|
@@ -5376,40 +5396,6 @@ const registerWebviewProtocol = async port => {
|
|
|
5376
5396
|
handle(session.protocol, WebView, handleRequest);
|
|
5377
5397
|
};
|
|
5378
5398
|
|
|
5379
|
-
const getModule$1 = method => {
|
|
5380
|
-
switch (method) {
|
|
5381
|
-
case NodeForkedProcess$1:
|
|
5382
|
-
return IpcChildWithNodeForkedProcess$1;
|
|
5383
|
-
case NodeWorker$1:
|
|
5384
|
-
return IpcChildWithNodeWorker$1;
|
|
5385
|
-
case ElectronUtilityProcess$1:
|
|
5386
|
-
return IpcChildWithElectronUtilityProcess$1;
|
|
5387
|
-
case ElectronMessagePort$1:
|
|
5388
|
-
return IpcChildWithElectronMessagePort$1;
|
|
5389
|
-
case RendererProcess2:
|
|
5390
|
-
return IpcChildWithRendererProcess2$1;
|
|
5391
|
-
default:
|
|
5392
|
-
throw new Error('unexpected ipc type');
|
|
5393
|
-
}
|
|
5394
|
-
};
|
|
5395
|
-
|
|
5396
|
-
const listen = async ({
|
|
5397
|
-
method,
|
|
5398
|
-
...params
|
|
5399
|
-
}) => {
|
|
5400
|
-
const module = getModule$1(method);
|
|
5401
|
-
// @ts-ignore
|
|
5402
|
-
const rawIpc = await module.listen(params);
|
|
5403
|
-
// @ts-ignore
|
|
5404
|
-
if (module.signal) {
|
|
5405
|
-
// @ts-ignore
|
|
5406
|
-
module.signal(rawIpc);
|
|
5407
|
-
}
|
|
5408
|
-
// @ts-ignore
|
|
5409
|
-
const ipc = module.wrap(rawIpc);
|
|
5410
|
-
return ipc;
|
|
5411
|
-
};
|
|
5412
|
-
|
|
5413
5399
|
class WindowLoadError extends VError {
|
|
5414
5400
|
constructor(error, url) {
|
|
5415
5401
|
super(error, `Failed to load url ${url}`);
|
|
@@ -5469,11 +5455,10 @@ const createAppWindow = async (windowOptions, parsedArgs, workingDirectory, titl
|
|
|
5469
5455
|
}
|
|
5470
5456
|
};
|
|
5471
5457
|
window.on('close', handleWindowClose);
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5458
|
+
await ElectronWebContentsRpcClient.create({
|
|
5459
|
+
webContents: window.webContents,
|
|
5460
|
+
commandMap: commandMapRef
|
|
5475
5461
|
});
|
|
5476
|
-
handleIpc(ipc);
|
|
5477
5462
|
await loadUrl(window, url);
|
|
5478
5463
|
};
|
|
5479
5464
|
|
|
@@ -5488,27 +5473,27 @@ const crashMainProcess$1 = () => {
|
|
|
5488
5473
|
setTimeout(handleTimeout, 0);
|
|
5489
5474
|
};
|
|
5490
5475
|
|
|
5491
|
-
const transferMessagePortMain = async (
|
|
5476
|
+
const transferMessagePortMain = async (rpc, port, ...params) => {
|
|
5492
5477
|
try {
|
|
5493
|
-
await invokeAndTransfer
|
|
5478
|
+
await rpc.invokeAndTransfer('HandleElectronMessagePort.handleElectronMessagePort', port, ...params);
|
|
5494
5479
|
} catch (error) {
|
|
5495
5480
|
throw new VError(error, `Failed to send message port to utility process`);
|
|
5496
5481
|
}
|
|
5497
5482
|
};
|
|
5498
5483
|
|
|
5499
|
-
const connectIpc$2 = async (
|
|
5500
|
-
await transferMessagePortMain(
|
|
5484
|
+
const connectIpc$2 = async (rpc, browserWindowPort, ...params) => {
|
|
5485
|
+
await transferMessagePortMain(rpc, browserWindowPort, ...params);
|
|
5501
5486
|
};
|
|
5502
5487
|
|
|
5503
|
-
const transferMessagePort = async (
|
|
5488
|
+
const transferMessagePort = async (rpc, port, ...params) => {
|
|
5504
5489
|
try {
|
|
5505
|
-
await invokeAndTransfer
|
|
5490
|
+
await rpc.invokeAndTransfer('HandleNodeMessagePort.handleNodeMessagePort', port, ...params);
|
|
5506
5491
|
} catch (error) {
|
|
5507
5492
|
throw new VError(error, `Failed to send message port to worker thread`);
|
|
5508
5493
|
}
|
|
5509
5494
|
};
|
|
5510
5495
|
|
|
5511
|
-
const connectIpc$1 = async (
|
|
5496
|
+
const connectIpc$1 = async (rpc, browserWindowPort, ...params) => {
|
|
5512
5497
|
const messageChannel = new MessageChannel();
|
|
5513
5498
|
const {
|
|
5514
5499
|
port1,
|
|
@@ -5522,11 +5507,11 @@ const connectIpc$1 = async (ipc, browserWindowPort, ...params) => {
|
|
|
5522
5507
|
// console.log('send message to browser window', message)
|
|
5523
5508
|
browserWindowPort.postMessage(message);
|
|
5524
5509
|
});
|
|
5525
|
-
await transferMessagePort(
|
|
5510
|
+
await transferMessagePort(rpc, port1, ...params);
|
|
5526
5511
|
browserWindowPort.start();
|
|
5527
5512
|
};
|
|
5528
5513
|
|
|
5529
|
-
const getModule = method => {
|
|
5514
|
+
const getModule$1 = method => {
|
|
5530
5515
|
switch (method) {
|
|
5531
5516
|
case NodeWorker:
|
|
5532
5517
|
return connectIpc$1;
|
|
@@ -5536,9 +5521,9 @@ const getModule = method => {
|
|
|
5536
5521
|
throw new Error('unexpected ipc type');
|
|
5537
5522
|
}
|
|
5538
5523
|
};
|
|
5539
|
-
const connectIpc = async (method,
|
|
5540
|
-
const connectIpc = getModule(method);
|
|
5541
|
-
return connectIpc(
|
|
5524
|
+
const connectIpc = async (method, rpc, browserWindowPort, ipcId) => {
|
|
5525
|
+
const connectIpc = getModule$1(method);
|
|
5526
|
+
return connectIpc(rpc, browserWindowPort, ipcId);
|
|
5542
5527
|
};
|
|
5543
5528
|
|
|
5544
5529
|
// TODO maybe handle critical (first render) request via ipcMain
|
|
@@ -5561,7 +5546,7 @@ const handlePort = async (browserWindowPort, ipcId) => {
|
|
|
5561
5546
|
FOLDER: ''
|
|
5562
5547
|
}
|
|
5563
5548
|
});
|
|
5564
|
-
await connectIpc(method, sharedProcess
|
|
5549
|
+
await connectIpc(method, sharedProcess, browserWindowPort, ipcId);
|
|
5565
5550
|
};
|
|
5566
5551
|
|
|
5567
5552
|
// TODO reverse order of parameters: make ports first
|
|
@@ -5647,6 +5632,19 @@ const createPidMap = () => {
|
|
|
5647
5632
|
return pidWindowMap;
|
|
5648
5633
|
};
|
|
5649
5634
|
|
|
5635
|
+
const rpcs = Object.create(null);
|
|
5636
|
+
const set$3 = (id, rpc) => {
|
|
5637
|
+
rpcs[id] = rpc;
|
|
5638
|
+
};
|
|
5639
|
+
|
|
5640
|
+
const createUtilityProcessRpc = async options => {
|
|
5641
|
+
const rpc = await ElectronUtilityProcessRpcParent.create({
|
|
5642
|
+
commandMap: commandMapRef,
|
|
5643
|
+
...options
|
|
5644
|
+
});
|
|
5645
|
+
set$3(options.rpcId, rpc);
|
|
5646
|
+
};
|
|
5647
|
+
|
|
5650
5648
|
const serializeDeskopCapturerSource = source => {
|
|
5651
5649
|
return {
|
|
5652
5650
|
display_id: source.display_id,
|
|
@@ -6944,6 +6942,40 @@ const getStats$1 = view => {
|
|
|
6944
6942
|
};
|
|
6945
6943
|
};
|
|
6946
6944
|
|
|
6945
|
+
const getModule = method => {
|
|
6946
|
+
switch (method) {
|
|
6947
|
+
case NodeForkedProcess$1:
|
|
6948
|
+
return IpcChildWithNodeForkedProcess$1;
|
|
6949
|
+
case NodeWorker$1:
|
|
6950
|
+
return IpcChildWithNodeWorker$1;
|
|
6951
|
+
case ElectronUtilityProcess$1:
|
|
6952
|
+
return IpcChildWithElectronUtilityProcess$1;
|
|
6953
|
+
case ElectronMessagePort$1:
|
|
6954
|
+
return IpcChildWithElectronMessagePort$1;
|
|
6955
|
+
case RendererProcess2:
|
|
6956
|
+
return IpcChildWithRendererProcess2$1;
|
|
6957
|
+
default:
|
|
6958
|
+
throw new Error('unexpected ipc type');
|
|
6959
|
+
}
|
|
6960
|
+
};
|
|
6961
|
+
|
|
6962
|
+
const listen = async ({
|
|
6963
|
+
method,
|
|
6964
|
+
...params
|
|
6965
|
+
}) => {
|
|
6966
|
+
const module = getModule(method);
|
|
6967
|
+
// @ts-ignore
|
|
6968
|
+
const rawIpc = await module.listen(params);
|
|
6969
|
+
// @ts-ignore
|
|
6970
|
+
if (module.signal) {
|
|
6971
|
+
// @ts-ignore
|
|
6972
|
+
module.signal(rawIpc);
|
|
6973
|
+
}
|
|
6974
|
+
// @ts-ignore
|
|
6975
|
+
const ipc = module.wrap(rawIpc);
|
|
6976
|
+
return ipc;
|
|
6977
|
+
};
|
|
6978
|
+
|
|
6947
6979
|
const open2 = async (options, url) => {
|
|
6948
6980
|
const allOptions = {
|
|
6949
6981
|
...options,
|
|
@@ -7124,9 +7156,10 @@ const commandMap = {
|
|
|
7124
7156
|
'AppWindow.createAppWindow': createAppWindow,
|
|
7125
7157
|
'Beep.beep': beep$1,
|
|
7126
7158
|
'Crash.crashMainProcess': crashMainProcess$1,
|
|
7127
|
-
'DesktopCapturer.getSources': getSources,
|
|
7128
7159
|
'CreateMessagePort.createMessagePort': createMessagePort,
|
|
7129
7160
|
'CreatePidMap.createPidMap': createPidMap,
|
|
7161
|
+
'CreateUtilityProcessRpc.createUtilityProcessRpc': createUtilityProcessRpc,
|
|
7162
|
+
'DesktopCapturer.getSources': getSources,
|
|
7130
7163
|
'ElectronApplicationMenu.setItems': setItems,
|
|
7131
7164
|
'ElectronBeep.beep': beep,
|
|
7132
7165
|
'ElectronContentTracing.startRecording': startRecording,
|