@lvce-editor/main-process 2.0.0 → 2.2.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 +883 -882
- 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,
|
|
@@ -2954,7 +2608,7 @@ const wrap$2 = childProcess => {
|
|
|
2954
2608
|
};
|
|
2955
2609
|
const IpcParentWithNodeForkedProcess$1 = {
|
|
2956
2610
|
__proto__: null,
|
|
2957
|
-
create: create$2$
|
|
2611
|
+
create: create$2$2,
|
|
2958
2612
|
wrap: wrap$2
|
|
2959
2613
|
};
|
|
2960
2614
|
const fixNodeWorkerParameters = value => {
|
|
@@ -2976,7 +2630,7 @@ const getFirstNodeWorkerEvent = worker => {
|
|
|
2976
2630
|
};
|
|
2977
2631
|
|
|
2978
2632
|
// @ts-ignore
|
|
2979
|
-
const create$1$
|
|
2633
|
+
const create$1$2 = async ({
|
|
2980
2634
|
path,
|
|
2981
2635
|
argv = [],
|
|
2982
2636
|
env = process.env,
|
|
@@ -3006,42 +2660,388 @@ const create$1$1 = async ({
|
|
|
3006
2660
|
if (type === Error$2) {
|
|
3007
2661
|
throw new IpcError(`Worker threw an error before ipc connection was established: ${event}`);
|
|
3008
2662
|
}
|
|
3009
|
-
if (event !== readyMessage) {
|
|
3010
|
-
throw new IpcError('unexpected first message from worker');
|
|
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);
|
|
2948
|
+
};
|
|
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);
|
|
2955
|
+
}
|
|
2956
|
+
};
|
|
2957
|
+
const defaultPreparePrettyError = error => {
|
|
2958
|
+
return error;
|
|
2959
|
+
};
|
|
2960
|
+
const defaultLogError = () => {
|
|
2961
|
+
// ignore
|
|
2962
|
+
};
|
|
2963
|
+
const defaultRequiresSocket = () => {
|
|
2964
|
+
return false;
|
|
2965
|
+
};
|
|
2966
|
+
const defaultResolve = resolve;
|
|
2967
|
+
|
|
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
|
+
};
|
|
2991
|
+
};
|
|
2992
|
+
const handleJsonRpcMessage = async (...args) => {
|
|
2993
|
+
const options = normalizeParams(args);
|
|
2994
|
+
const {
|
|
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;
|
|
3016
|
+
}
|
|
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,
|
|
@@ -3151,258 +3151,54 @@ const create$3 = async ({
|
|
|
3151
3151
|
name
|
|
3152
3152
|
});
|
|
3153
3153
|
const ipc = IpcParentWithElectronUtilityProcess$1$1.wrap(rawIpc);
|
|
3154
|
-
if (requiresSocket) {
|
|
3155
|
-
// @ts-ignore
|
|
3156
|
-
ipc.requiresSocket = requiresSocket;
|
|
3157
|
-
}
|
|
3158
|
-
handleIpc$1(ipc);
|
|
3159
|
-
const rpc = createRpc(ipc);
|
|
3160
|
-
return rpc;
|
|
3161
|
-
};
|
|
3162
|
-
const ElectronUtilityProcessRpcParent = {
|
|
3163
|
-
__proto__: null,
|
|
3164
|
-
create: create$3
|
|
3165
|
-
};
|
|
3166
|
-
|
|
3167
|
-
const commandMapRef = Object.create(null);
|
|
3168
|
-
|
|
3169
|
-
const getPortTuple = () => {
|
|
3170
|
-
const {
|
|
3171
|
-
port1,
|
|
3172
|
-
port2
|
|
3173
|
-
} = new MessageChannelMain();
|
|
3174
|
-
return {
|
|
3175
|
-
port1,
|
|
3176
|
-
port2
|
|
3177
|
-
};
|
|
3178
|
-
};
|
|
3179
|
-
|
|
3180
|
-
const getSharedProcessArgv = isProduction => {
|
|
3181
|
-
return [];
|
|
3182
|
-
};
|
|
3183
|
-
|
|
3184
|
-
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
3185
|
-
const E_MODULE_NOT_FOUND = 'E_MODULE_NOT_FOUND';
|
|
3186
|
-
|
|
3187
|
-
class CommandNotFoundError extends Error {
|
|
3188
|
-
constructor(id) {
|
|
3189
|
-
super(`command ${id} not found`);
|
|
3190
|
-
this.name = 'CommandNotFoundError';
|
|
3191
|
-
// @ts-ignore
|
|
3192
|
-
this.code = E_COMMAND_NOT_FOUND;
|
|
3193
|
-
}
|
|
3194
|
-
}
|
|
3195
|
-
|
|
3196
|
-
const App = 1;
|
|
3197
|
-
const AppWindow = 2;
|
|
3198
|
-
const Beep = 3;
|
|
3199
|
-
const Developer = 4;
|
|
3200
|
-
const Dialog = 5;
|
|
3201
|
-
const ElectronWindowProcessExplorer = 6;
|
|
3202
|
-
const Window = 7;
|
|
3203
|
-
const ElectronShell = 8;
|
|
3204
|
-
const ElectronPowerSaveBlocker = 9;
|
|
3205
|
-
const ElectronSafeStorage = 10;
|
|
3206
|
-
const ElectronContentTracing = 11;
|
|
3207
|
-
const ElectronNetLog = 12;
|
|
3208
|
-
const ElectronBrowserView = 13;
|
|
3209
|
-
const ElectronBrowserViewQuickPick = 14;
|
|
3210
|
-
const ElectronContextMenu = 16;
|
|
3211
|
-
const ElectronClipBoard = 17;
|
|
3212
|
-
const ElectronApplicationMenu = 18;
|
|
3213
|
-
const Process = 19;
|
|
3214
|
-
const ElectronNet = 20;
|
|
3215
|
-
const ElectronBrowserViewSuggestions = 21;
|
|
3216
|
-
const CreatePidMap = 22;
|
|
3217
|
-
const OpenExternal$1 = 23;
|
|
3218
|
-
const Platform = 25;
|
|
3219
|
-
const GetWindowId = 26;
|
|
3220
|
-
const DesktopCapturer = 27;
|
|
3221
|
-
const Trash = 28;
|
|
3222
|
-
const IpcParent = 29;
|
|
3223
|
-
const Crash = 30;
|
|
3224
|
-
const Exit = 31;
|
|
3225
|
-
const ElectronScreen = 32;
|
|
3226
|
-
const TemporaryMessagePort = 34;
|
|
3227
|
-
const ElectronWebContents = 35;
|
|
3228
|
-
const ElectronWebContentsView = 36;
|
|
3229
|
-
const ElectronWebContentsViewFunctions = 37;
|
|
3230
|
-
const CreateMessagePort = 38;
|
|
3231
|
-
const HandleElectronMessagePort = 39;
|
|
3232
|
-
const ElectronSession = 40;
|
|
3233
|
-
|
|
3234
|
-
const getPrefix = commandId => {
|
|
3235
|
-
return commandId.slice(0, commandId.indexOf('.'));
|
|
3236
|
-
};
|
|
3237
|
-
const getModuleId = commandId => {
|
|
3238
|
-
const prefix = getPrefix(commandId);
|
|
3239
|
-
switch (prefix) {
|
|
3240
|
-
case 'Crash':
|
|
3241
|
-
return Crash;
|
|
3242
|
-
case 'ElectronApp':
|
|
3243
|
-
case 'App':
|
|
3244
|
-
return App;
|
|
3245
|
-
case 'Beep':
|
|
3246
|
-
return Beep;
|
|
3247
|
-
case 'ElectronWindow':
|
|
3248
|
-
return Window;
|
|
3249
|
-
case 'ElectronDeveloper':
|
|
3250
|
-
return Developer;
|
|
3251
|
-
case 'AppWindow':
|
|
3252
|
-
return AppWindow;
|
|
3253
|
-
case 'ElectronWindowProcessExplorer':
|
|
3254
|
-
return ElectronWindowProcessExplorer;
|
|
3255
|
-
case 'ElectronDialog':
|
|
3256
|
-
return Dialog;
|
|
3257
|
-
case 'ElectronBeep':
|
|
3258
|
-
return Beep;
|
|
3259
|
-
case 'ElectronShell':
|
|
3260
|
-
return ElectronShell;
|
|
3261
|
-
case 'ElectronPowerSaveBlocker':
|
|
3262
|
-
return ElectronPowerSaveBlocker;
|
|
3263
|
-
case 'ElectronSafeStorage':
|
|
3264
|
-
return ElectronSafeStorage;
|
|
3265
|
-
case 'ElectronContentTracing':
|
|
3266
|
-
return ElectronContentTracing;
|
|
3267
|
-
case 'ElectronNetLog':
|
|
3268
|
-
return ElectronNetLog;
|
|
3269
|
-
case 'ElectronBrowserView':
|
|
3270
|
-
return ElectronBrowserView;
|
|
3271
|
-
case 'ElectronBrowserViewQuickPick':
|
|
3272
|
-
return ElectronBrowserViewQuickPick;
|
|
3273
|
-
case 'ElectronContextMenu':
|
|
3274
|
-
return ElectronContextMenu;
|
|
3275
|
-
case 'ElectronClipBoard':
|
|
3276
|
-
return ElectronClipBoard;
|
|
3277
|
-
case 'ElectronApplicationMenu':
|
|
3278
|
-
return ElectronApplicationMenu;
|
|
3279
|
-
case 'Process':
|
|
3280
|
-
return Process;
|
|
3281
|
-
case 'ElectronNet':
|
|
3282
|
-
return ElectronNet;
|
|
3283
|
-
case 'ElectronBrowserViewSuggestions':
|
|
3284
|
-
return ElectronBrowserViewSuggestions;
|
|
3285
|
-
case 'CreatePidMap':
|
|
3286
|
-
return CreatePidMap;
|
|
3287
|
-
case 'OpenExternal':
|
|
3288
|
-
return OpenExternal$1;
|
|
3289
|
-
case 'Platform':
|
|
3290
|
-
return Platform;
|
|
3291
|
-
case 'GetWindowId':
|
|
3292
|
-
return GetWindowId;
|
|
3293
|
-
case 'DesktopCapturer':
|
|
3294
|
-
return DesktopCapturer;
|
|
3295
|
-
case 'Trash':
|
|
3296
|
-
return Trash;
|
|
3297
|
-
case 'IpcParent':
|
|
3298
|
-
return IpcParent;
|
|
3299
|
-
case 'Exit':
|
|
3300
|
-
return Exit;
|
|
3301
|
-
case 'ElectronScreen':
|
|
3302
|
-
return ElectronScreen;
|
|
3303
|
-
case 'TemporaryMessagePort':
|
|
3304
|
-
return TemporaryMessagePort;
|
|
3305
|
-
case 'ElectronWebContents':
|
|
3306
|
-
return ElectronWebContents;
|
|
3307
|
-
case 'ElectronWebContentsView':
|
|
3308
|
-
return ElectronWebContentsView;
|
|
3309
|
-
case 'ElectronWebContentsViewFunctions':
|
|
3310
|
-
return ElectronWebContentsViewFunctions;
|
|
3311
|
-
case 'CreateMessagePort':
|
|
3312
|
-
return CreateMessagePort;
|
|
3313
|
-
case 'HandleElectronMessagePort':
|
|
3314
|
-
return HandleElectronMessagePort;
|
|
3315
|
-
case 'ElectronSession':
|
|
3316
|
-
return ElectronSession;
|
|
3317
|
-
default:
|
|
3318
|
-
throw new CommandNotFoundError(commandId);
|
|
3319
|
-
}
|
|
3320
|
-
};
|
|
3321
|
-
|
|
3322
|
-
const state$7 = {
|
|
3323
|
-
commands: Object.create(null),
|
|
3324
|
-
pendingModules: Object.create(null),
|
|
3325
|
-
async load(moduleId) {}
|
|
3326
|
-
};
|
|
3327
|
-
const initializeModule = module => {
|
|
3328
|
-
if (module.Commands) {
|
|
3329
|
-
for (const [key, value] of Object.entries(module.Commands)) {
|
|
3330
|
-
if (module.name) {
|
|
3331
|
-
const actualKey = `${module.name}.${key}`;
|
|
3332
|
-
register(actualKey, value);
|
|
3333
|
-
} else {
|
|
3334
|
-
register(key, value);
|
|
3335
|
-
}
|
|
3336
|
-
}
|
|
3337
|
-
return;
|
|
3338
|
-
}
|
|
3339
|
-
throw new Error(`module ${module.name || '<unnamed module>'} is missing commands`);
|
|
3340
|
-
};
|
|
3341
|
-
const getOrLoadModule = moduleId => {
|
|
3342
|
-
if (!state$7.pendingModules[moduleId]) {
|
|
3343
|
-
const importPromise = state$7.load(moduleId);
|
|
3344
|
-
state$7.pendingModules[moduleId] = importPromise.then(initializeModule);
|
|
3345
|
-
}
|
|
3346
|
-
return state$7.pendingModules[moduleId];
|
|
3347
|
-
};
|
|
3348
|
-
const loadCommand = command => getOrLoadModule(getModuleId(command));
|
|
3349
|
-
const register = (commandId, listener) => {
|
|
3350
|
-
state$7.commands[commandId] = listener;
|
|
3351
|
-
};
|
|
3352
|
-
const hasThrown = new Set();
|
|
3353
|
-
const loadThenExecute = async (command, ...args) => {
|
|
3354
|
-
await loadCommand(command);
|
|
3355
|
-
// TODO can skip then block in prod (only to prevent endless loop in dev)
|
|
3356
|
-
if (!(command in state$7.commands)) {
|
|
3357
|
-
if (hasThrown.has(command)) {
|
|
3358
|
-
return;
|
|
3359
|
-
}
|
|
3360
|
-
hasThrown.add(command);
|
|
3361
|
-
throw new Error(`Command did not register "${command}"`);
|
|
3154
|
+
if (requiresSocket) {
|
|
3155
|
+
// @ts-ignore
|
|
3156
|
+
ipc.requiresSocket = requiresSocket;
|
|
3362
3157
|
}
|
|
3363
|
-
|
|
3158
|
+
handleIpc$1(ipc);
|
|
3159
|
+
const rpc = createRpc(ipc);
|
|
3160
|
+
return rpc;
|
|
3364
3161
|
};
|
|
3365
|
-
const
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
}
|
|
3369
|
-
return loadThenExecute(command, ...args);
|
|
3162
|
+
const ElectronUtilityProcessRpcParent = {
|
|
3163
|
+
__proto__: null,
|
|
3164
|
+
create: create$c
|
|
3370
3165
|
};
|
|
3371
|
-
const
|
|
3372
|
-
|
|
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;
|
|
3373
3181
|
};
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3182
|
+
const ElectronWebContentsRpcClient = {
|
|
3183
|
+
__proto__: null,
|
|
3184
|
+
create: create$b
|
|
3377
3185
|
};
|
|
3378
3186
|
|
|
3379
|
-
const
|
|
3380
|
-
return false;
|
|
3381
|
-
};
|
|
3187
|
+
const commandMapRef = Object.create(null);
|
|
3382
3188
|
|
|
3383
|
-
const
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3189
|
+
const getPortTuple = () => {
|
|
3190
|
+
const {
|
|
3191
|
+
port1,
|
|
3192
|
+
port2
|
|
3193
|
+
} = new MessageChannelMain();
|
|
3194
|
+
return {
|
|
3195
|
+
port1,
|
|
3196
|
+
port2
|
|
3197
|
+
};
|
|
3390
3198
|
};
|
|
3391
3199
|
|
|
3392
|
-
const
|
|
3393
|
-
|
|
3394
|
-
ipc.addEventListener('message', handleMessage);
|
|
3395
|
-
} else if ('on' in ipc) {
|
|
3396
|
-
// deprecated
|
|
3397
|
-
ipc.on('message', handleMessage);
|
|
3398
|
-
}
|
|
3399
|
-
};
|
|
3400
|
-
const unhandleIpc = ipc => {
|
|
3401
|
-
if ('removeEventListener' in ipc) {
|
|
3402
|
-
ipc.removeEventListener('message', handleMessage);
|
|
3403
|
-
} else if ('off' in ipc) {
|
|
3404
|
-
ipc.off('message', handleMessage);
|
|
3405
|
-
}
|
|
3200
|
+
const getSharedProcessArgv = isProduction => {
|
|
3201
|
+
return [];
|
|
3406
3202
|
};
|
|
3407
3203
|
|
|
3408
3204
|
const EmbedsProcess = 2;
|
|
@@ -3478,15 +3274,8 @@ const getSharedProcessPath = () => {
|
|
|
3478
3274
|
return join(root, 'packages', 'shared-process', 'src', 'sharedProcessMain.ts');
|
|
3479
3275
|
};
|
|
3480
3276
|
|
|
3481
|
-
const
|
|
3482
|
-
|
|
3483
|
-
* @type{any|undefined}
|
|
3484
|
-
*/
|
|
3485
|
-
sharedProcess: undefined,
|
|
3486
|
-
/**
|
|
3487
|
-
* @type {any}
|
|
3488
|
-
*/
|
|
3489
|
-
promise: undefined
|
|
3277
|
+
const requiresSocket = () => {
|
|
3278
|
+
return false;
|
|
3490
3279
|
};
|
|
3491
3280
|
|
|
3492
3281
|
const handleChildError = error => {
|
|
@@ -3529,7 +3318,6 @@ const launchSharedProcess = async ({
|
|
|
3529
3318
|
sharedProcess._rawIpc.on('exit', handleChildExit);
|
|
3530
3319
|
// @ts-ignore
|
|
3531
3320
|
sharedProcess._rawIpc.on('disconnect', handleChildDisconnect);
|
|
3532
|
-
handleIpc(sharedProcess);
|
|
3533
3321
|
|
|
3534
3322
|
// create secondary ipc to support transferring objects
|
|
3535
3323
|
// from shared process to main process
|
|
@@ -3545,43 +3333,47 @@ const launchSharedProcess = async ({
|
|
|
3545
3333
|
requiresSocket: requiresSocket,
|
|
3546
3334
|
messagePort: port1
|
|
3547
3335
|
});
|
|
3548
|
-
|
|
3549
|
-
// @ts-ignore
|
|
3550
|
-
state$6.sharedProcess = sharedProcess;
|
|
3551
3336
|
mark(DidStartSharedProcess);
|
|
3552
|
-
return
|
|
3337
|
+
return sharedProcessRpc;
|
|
3338
|
+
};
|
|
3339
|
+
|
|
3340
|
+
const state$7 = {
|
|
3341
|
+
/**
|
|
3342
|
+
* @type {any}
|
|
3343
|
+
*/
|
|
3344
|
+
promise: undefined
|
|
3553
3345
|
};
|
|
3554
3346
|
|
|
3555
3347
|
const getOrCreate = async ({
|
|
3556
3348
|
method,
|
|
3557
3349
|
env = {}
|
|
3558
3350
|
}) => {
|
|
3559
|
-
if (!state$
|
|
3351
|
+
if (!state$7.promise) {
|
|
3560
3352
|
// @ts-ignore
|
|
3561
|
-
state$
|
|
3353
|
+
state$7.promise = launchSharedProcess({
|
|
3562
3354
|
method,
|
|
3563
3355
|
env
|
|
3564
3356
|
});
|
|
3565
3357
|
}
|
|
3566
|
-
return state$
|
|
3358
|
+
return state$7.promise;
|
|
3567
3359
|
};
|
|
3568
3360
|
const send$1 = async (method, ...params) => {
|
|
3569
|
-
const
|
|
3361
|
+
const rpc = await getOrCreate({
|
|
3570
3362
|
method: ElectronUtilityProcess$1
|
|
3571
3363
|
});
|
|
3572
|
-
send
|
|
3364
|
+
rpc.send(method, ...params);
|
|
3573
3365
|
};
|
|
3574
3366
|
const invoke = async (method, ...params) => {
|
|
3575
|
-
const
|
|
3367
|
+
const rpc = await getOrCreate({
|
|
3576
3368
|
method: ElectronUtilityProcess$1
|
|
3577
3369
|
});
|
|
3578
|
-
return invoke
|
|
3370
|
+
return rpc.invoke(method, ...params);
|
|
3579
3371
|
};
|
|
3580
|
-
const invokeAndTransfer = async (
|
|
3581
|
-
const
|
|
3372
|
+
const invokeAndTransfer = async (method, ...params) => {
|
|
3373
|
+
const rpc = await getOrCreate({
|
|
3582
3374
|
method: ElectronUtilityProcess$1
|
|
3583
3375
|
});
|
|
3584
|
-
return invokeAndTransfer
|
|
3376
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
3585
3377
|
};
|
|
3586
3378
|
|
|
3587
3379
|
const handleCliArgs = async parsedArgs => {
|
|
@@ -4686,14 +4478,14 @@ const createTitleBar = items => {
|
|
|
4686
4478
|
|
|
4687
4479
|
const PHASE_DEFAULT = 0;
|
|
4688
4480
|
const PHASE_SHUTDOWN = -1;
|
|
4689
|
-
const state$
|
|
4481
|
+
const state$6 = {
|
|
4690
4482
|
phase: PHASE_DEFAULT
|
|
4691
4483
|
};
|
|
4692
4484
|
const isShutDown = () => {
|
|
4693
|
-
return state$
|
|
4485
|
+
return state$6.phase === PHASE_SHUTDOWN;
|
|
4694
4486
|
};
|
|
4695
4487
|
const setShutDown = () => {
|
|
4696
|
-
state$
|
|
4488
|
+
state$6.phase = PHASE_SHUTDOWN;
|
|
4697
4489
|
};
|
|
4698
4490
|
|
|
4699
4491
|
// TODO move this function to shared process
|
|
@@ -4990,21 +4782,21 @@ const BeforeInputEvent = 'before-input-event';
|
|
|
4990
4782
|
const Allow = 'allow';
|
|
4991
4783
|
const Deny = 'deny';
|
|
4992
4784
|
|
|
4993
|
-
const state$
|
|
4785
|
+
const state$5 = {
|
|
4994
4786
|
views: Object.create(null),
|
|
4995
4787
|
fallThroughKeyBindings: [],
|
|
4996
4788
|
canceled: Object.create(null)
|
|
4997
4789
|
};
|
|
4998
4790
|
const add$1 = (id, browserWindow, view) => {
|
|
4999
4791
|
// state
|
|
5000
|
-
state$
|
|
4792
|
+
state$5.views[id] = {
|
|
5001
4793
|
browserWindow,
|
|
5002
4794
|
view
|
|
5003
4795
|
};
|
|
5004
4796
|
};
|
|
5005
4797
|
const hasWebContents = id => {
|
|
5006
4798
|
number(id);
|
|
5007
|
-
return id in state$
|
|
4799
|
+
return id in state$5.views;
|
|
5008
4800
|
};
|
|
5009
4801
|
/**
|
|
5010
4802
|
*
|
|
@@ -5012,19 +4804,19 @@ const hasWebContents = id => {
|
|
|
5012
4804
|
* @returns {{browserWindow: Electron.BrowserWindow, view: Electron.WebContentsView}}
|
|
5013
4805
|
*/
|
|
5014
4806
|
const get$2 = id => {
|
|
5015
|
-
return state$
|
|
4807
|
+
return state$5.views[id];
|
|
5016
4808
|
};
|
|
5017
4809
|
const remove$1 = id => {
|
|
5018
|
-
delete state$
|
|
4810
|
+
delete state$5.views[id];
|
|
5019
4811
|
};
|
|
5020
4812
|
const setFallthroughKeyBindings = fallthroughKeyBindings => {
|
|
5021
|
-
state$
|
|
4813
|
+
state$5.fallThroughKeyBindings = fallthroughKeyBindings;
|
|
5022
4814
|
};
|
|
5023
4815
|
const getFallthroughKeyBindings = () => {
|
|
5024
|
-
return state$
|
|
4816
|
+
return state$5.fallThroughKeyBindings;
|
|
5025
4817
|
};
|
|
5026
4818
|
const setCanceled = id => {
|
|
5027
|
-
state$
|
|
4819
|
+
state$5.canceled[id] = true;
|
|
5028
4820
|
};
|
|
5029
4821
|
|
|
5030
4822
|
const shouldAllowNavigation = webContentsId => {
|
|
@@ -5148,49 +4940,240 @@ const hydrate = async () => {
|
|
|
5148
4940
|
// before being able to test multi-window behavior
|
|
5149
4941
|
// see https://github.com/microsoft/playwright/issues/12345
|
|
5150
4942
|
|
|
5151
|
-
const parsedCliArgs = parseCliArgs(argv);
|
|
5152
|
-
const moduleId = canHandleFastCliArgs(parsedCliArgs);
|
|
5153
|
-
if (moduleId) {
|
|
5154
|
-
await handleFastCliArgs(moduleId, parsedCliArgs);
|
|
4943
|
+
const parsedCliArgs = parseCliArgs(argv);
|
|
4944
|
+
const moduleId = canHandleFastCliArgs(parsedCliArgs);
|
|
4945
|
+
if (moduleId) {
|
|
4946
|
+
await handleFastCliArgs(moduleId, parsedCliArgs);
|
|
4947
|
+
return;
|
|
4948
|
+
}
|
|
4949
|
+
if (isLinux && chromeUserDataPath) {
|
|
4950
|
+
setUserDataPath(chromeUserDataPath);
|
|
4951
|
+
setSessionDataPath(chromeUserDataPath);
|
|
4952
|
+
setCrashDumpsPath(chromeUserDataPath);
|
|
4953
|
+
setLogsPath(chromeUserDataPath);
|
|
4954
|
+
}
|
|
4955
|
+
const hasLock = requestSingleInstanceLock(argv);
|
|
4956
|
+
if (!hasLock) {
|
|
4957
|
+
debug('[info] quitting because no lock');
|
|
4958
|
+
exit();
|
|
4959
|
+
return;
|
|
4960
|
+
}
|
|
4961
|
+
|
|
4962
|
+
// TODO tree shake out the .env.DEV check: reading from env variables is expensive
|
|
4963
|
+
if (process.stdout.isTTY && !parsedCliArgs.wait && !process.env.DEV) {
|
|
4964
|
+
spawn(execPath, argv.slice(1), {
|
|
4965
|
+
detached: true,
|
|
4966
|
+
stdio: 'ignore'
|
|
4967
|
+
});
|
|
4968
|
+
exit$1(Success);
|
|
4969
|
+
}
|
|
4970
|
+
|
|
4971
|
+
// command line switches
|
|
4972
|
+
enable$1(parsedCliArgs);
|
|
4973
|
+
|
|
4974
|
+
// protocol
|
|
4975
|
+
enable(Electron.protocol);
|
|
4976
|
+
|
|
4977
|
+
// app
|
|
4978
|
+
on(WindowAllClosed, handleWindowAllClosed);
|
|
4979
|
+
on(BeforeQuit, handleBeforeQuit);
|
|
4980
|
+
on(WebContentsCreated, handleWebContentsCreated);
|
|
4981
|
+
on(SecondInstance, handleSecondInstance);
|
|
4982
|
+
await whenReady();
|
|
4983
|
+
mark(AppReady);
|
|
4984
|
+
await handleReady(parsedCliArgs, cwd());
|
|
4985
|
+
debug('[info] app window created');
|
|
4986
|
+
};
|
|
4987
|
+
|
|
4988
|
+
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
4989
|
+
const E_MODULE_NOT_FOUND = 'E_MODULE_NOT_FOUND';
|
|
4990
|
+
|
|
4991
|
+
class CommandNotFoundError extends Error {
|
|
4992
|
+
constructor(id) {
|
|
4993
|
+
super(`command ${id} not found`);
|
|
4994
|
+
this.name = 'CommandNotFoundError';
|
|
4995
|
+
// @ts-ignore
|
|
4996
|
+
this.code = E_COMMAND_NOT_FOUND;
|
|
4997
|
+
}
|
|
4998
|
+
}
|
|
4999
|
+
|
|
5000
|
+
const App = 1;
|
|
5001
|
+
const AppWindow = 2;
|
|
5002
|
+
const Beep = 3;
|
|
5003
|
+
const Developer = 4;
|
|
5004
|
+
const Dialog = 5;
|
|
5005
|
+
const ElectronWindowProcessExplorer = 6;
|
|
5006
|
+
const Window = 7;
|
|
5007
|
+
const ElectronShell = 8;
|
|
5008
|
+
const ElectronPowerSaveBlocker = 9;
|
|
5009
|
+
const ElectronSafeStorage = 10;
|
|
5010
|
+
const ElectronContentTracing = 11;
|
|
5011
|
+
const ElectronNetLog = 12;
|
|
5012
|
+
const ElectronBrowserView = 13;
|
|
5013
|
+
const ElectronBrowserViewQuickPick = 14;
|
|
5014
|
+
const ElectronContextMenu = 16;
|
|
5015
|
+
const ElectronClipBoard = 17;
|
|
5016
|
+
const ElectronApplicationMenu = 18;
|
|
5017
|
+
const Process = 19;
|
|
5018
|
+
const ElectronNet = 20;
|
|
5019
|
+
const ElectronBrowserViewSuggestions = 21;
|
|
5020
|
+
const CreatePidMap = 22;
|
|
5021
|
+
const OpenExternal$1 = 23;
|
|
5022
|
+
const Platform = 25;
|
|
5023
|
+
const GetWindowId = 26;
|
|
5024
|
+
const DesktopCapturer = 27;
|
|
5025
|
+
const Trash = 28;
|
|
5026
|
+
const IpcParent = 29;
|
|
5027
|
+
const Crash = 30;
|
|
5028
|
+
const Exit = 31;
|
|
5029
|
+
const ElectronScreen = 32;
|
|
5030
|
+
const TemporaryMessagePort = 34;
|
|
5031
|
+
const ElectronWebContents = 35;
|
|
5032
|
+
const ElectronWebContentsView = 36;
|
|
5033
|
+
const ElectronWebContentsViewFunctions = 37;
|
|
5034
|
+
const CreateMessagePort = 38;
|
|
5035
|
+
const HandleElectronMessagePort = 39;
|
|
5036
|
+
const ElectronSession = 40;
|
|
5037
|
+
|
|
5038
|
+
const getPrefix = commandId => {
|
|
5039
|
+
return commandId.slice(0, commandId.indexOf('.'));
|
|
5040
|
+
};
|
|
5041
|
+
const getModuleId = commandId => {
|
|
5042
|
+
const prefix = getPrefix(commandId);
|
|
5043
|
+
switch (prefix) {
|
|
5044
|
+
case 'Crash':
|
|
5045
|
+
return Crash;
|
|
5046
|
+
case 'ElectronApp':
|
|
5047
|
+
case 'App':
|
|
5048
|
+
return App;
|
|
5049
|
+
case 'Beep':
|
|
5050
|
+
return Beep;
|
|
5051
|
+
case 'ElectronWindow':
|
|
5052
|
+
return Window;
|
|
5053
|
+
case 'ElectronDeveloper':
|
|
5054
|
+
return Developer;
|
|
5055
|
+
case 'AppWindow':
|
|
5056
|
+
return AppWindow;
|
|
5057
|
+
case 'ElectronWindowProcessExplorer':
|
|
5058
|
+
return ElectronWindowProcessExplorer;
|
|
5059
|
+
case 'ElectronDialog':
|
|
5060
|
+
return Dialog;
|
|
5061
|
+
case 'ElectronBeep':
|
|
5062
|
+
return Beep;
|
|
5063
|
+
case 'ElectronShell':
|
|
5064
|
+
return ElectronShell;
|
|
5065
|
+
case 'ElectronPowerSaveBlocker':
|
|
5066
|
+
return ElectronPowerSaveBlocker;
|
|
5067
|
+
case 'ElectronSafeStorage':
|
|
5068
|
+
return ElectronSafeStorage;
|
|
5069
|
+
case 'ElectronContentTracing':
|
|
5070
|
+
return ElectronContentTracing;
|
|
5071
|
+
case 'ElectronNetLog':
|
|
5072
|
+
return ElectronNetLog;
|
|
5073
|
+
case 'ElectronBrowserView':
|
|
5074
|
+
return ElectronBrowserView;
|
|
5075
|
+
case 'ElectronBrowserViewQuickPick':
|
|
5076
|
+
return ElectronBrowserViewQuickPick;
|
|
5077
|
+
case 'ElectronContextMenu':
|
|
5078
|
+
return ElectronContextMenu;
|
|
5079
|
+
case 'ElectronClipBoard':
|
|
5080
|
+
return ElectronClipBoard;
|
|
5081
|
+
case 'ElectronApplicationMenu':
|
|
5082
|
+
return ElectronApplicationMenu;
|
|
5083
|
+
case 'Process':
|
|
5084
|
+
return Process;
|
|
5085
|
+
case 'ElectronNet':
|
|
5086
|
+
return ElectronNet;
|
|
5087
|
+
case 'ElectronBrowserViewSuggestions':
|
|
5088
|
+
return ElectronBrowserViewSuggestions;
|
|
5089
|
+
case 'CreatePidMap':
|
|
5090
|
+
return CreatePidMap;
|
|
5091
|
+
case 'OpenExternal':
|
|
5092
|
+
return OpenExternal$1;
|
|
5093
|
+
case 'Platform':
|
|
5094
|
+
return Platform;
|
|
5095
|
+
case 'GetWindowId':
|
|
5096
|
+
return GetWindowId;
|
|
5097
|
+
case 'DesktopCapturer':
|
|
5098
|
+
return DesktopCapturer;
|
|
5099
|
+
case 'Trash':
|
|
5100
|
+
return Trash;
|
|
5101
|
+
case 'IpcParent':
|
|
5102
|
+
return IpcParent;
|
|
5103
|
+
case 'Exit':
|
|
5104
|
+
return Exit;
|
|
5105
|
+
case 'ElectronScreen':
|
|
5106
|
+
return ElectronScreen;
|
|
5107
|
+
case 'TemporaryMessagePort':
|
|
5108
|
+
return TemporaryMessagePort;
|
|
5109
|
+
case 'ElectronWebContents':
|
|
5110
|
+
return ElectronWebContents;
|
|
5111
|
+
case 'ElectronWebContentsView':
|
|
5112
|
+
return ElectronWebContentsView;
|
|
5113
|
+
case 'ElectronWebContentsViewFunctions':
|
|
5114
|
+
return ElectronWebContentsViewFunctions;
|
|
5115
|
+
case 'CreateMessagePort':
|
|
5116
|
+
return CreateMessagePort;
|
|
5117
|
+
case 'HandleElectronMessagePort':
|
|
5118
|
+
return HandleElectronMessagePort;
|
|
5119
|
+
case 'ElectronSession':
|
|
5120
|
+
return ElectronSession;
|
|
5121
|
+
default:
|
|
5122
|
+
throw new CommandNotFoundError(commandId);
|
|
5123
|
+
}
|
|
5124
|
+
};
|
|
5125
|
+
|
|
5126
|
+
const state$4 = {
|
|
5127
|
+
commands: Object.create(null),
|
|
5128
|
+
pendingModules: Object.create(null),
|
|
5129
|
+
async load(moduleId) {}
|
|
5130
|
+
};
|
|
5131
|
+
const initializeModule = module => {
|
|
5132
|
+
if (module.Commands) {
|
|
5133
|
+
for (const [key, value] of Object.entries(module.Commands)) {
|
|
5134
|
+
if (module.name) {
|
|
5135
|
+
const actualKey = `${module.name}.${key}`;
|
|
5136
|
+
register(actualKey, value);
|
|
5137
|
+
} else {
|
|
5138
|
+
register(key, value);
|
|
5139
|
+
}
|
|
5140
|
+
}
|
|
5155
5141
|
return;
|
|
5156
5142
|
}
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5143
|
+
throw new Error(`module ${module.name || '<unnamed module>'} is missing commands`);
|
|
5144
|
+
};
|
|
5145
|
+
const getOrLoadModule = moduleId => {
|
|
5146
|
+
if (!state$4.pendingModules[moduleId]) {
|
|
5147
|
+
const importPromise = state$4.load(moduleId);
|
|
5148
|
+
state$4.pendingModules[moduleId] = importPromise.then(initializeModule);
|
|
5162
5149
|
}
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5150
|
+
return state$4.pendingModules[moduleId];
|
|
5151
|
+
};
|
|
5152
|
+
const loadCommand = command => getOrLoadModule(getModuleId(command));
|
|
5153
|
+
const register = (commandId, listener) => {
|
|
5154
|
+
state$4.commands[commandId] = listener;
|
|
5155
|
+
};
|
|
5156
|
+
const hasThrown = new Set();
|
|
5157
|
+
const loadThenExecute = async (command, ...args) => {
|
|
5158
|
+
await loadCommand(command);
|
|
5159
|
+
// TODO can skip then block in prod (only to prevent endless loop in dev)
|
|
5160
|
+
if (!(command in state$4.commands)) {
|
|
5161
|
+
if (hasThrown.has(command)) {
|
|
5162
|
+
return;
|
|
5163
|
+
}
|
|
5164
|
+
hasThrown.add(command);
|
|
5165
|
+
throw new Error(`Command did not register "${command}"`);
|
|
5168
5166
|
}
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
stdio: 'ignore'
|
|
5175
|
-
});
|
|
5176
|
-
exit$1(Success);
|
|
5167
|
+
return execute(command, ...args);
|
|
5168
|
+
};
|
|
5169
|
+
const execute = (command, ...args) => {
|
|
5170
|
+
if (command in state$4.commands) {
|
|
5171
|
+
return state$4.commands[command](...args);
|
|
5177
5172
|
}
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
// protocol
|
|
5183
|
-
enable(Electron.protocol);
|
|
5184
|
-
|
|
5185
|
-
// app
|
|
5186
|
-
on(WindowAllClosed, handleWindowAllClosed);
|
|
5187
|
-
on(BeforeQuit, handleBeforeQuit);
|
|
5188
|
-
on(WebContentsCreated, handleWebContentsCreated);
|
|
5189
|
-
on(SecondInstance, handleSecondInstance);
|
|
5190
|
-
await whenReady();
|
|
5191
|
-
mark(AppReady);
|
|
5192
|
-
await handleReady(parsedCliArgs, cwd());
|
|
5193
|
-
debug('[info] app window created');
|
|
5173
|
+
return loadThenExecute(command, ...args);
|
|
5174
|
+
};
|
|
5175
|
+
const setLoad = load => {
|
|
5176
|
+
state$4.load = load;
|
|
5194
5177
|
};
|
|
5195
5178
|
|
|
5196
5179
|
const ClipBoardRead = 'clipboard-read';
|
|
@@ -5298,6 +5281,35 @@ const set$1 = value => {
|
|
|
5298
5281
|
state$3.session = value;
|
|
5299
5282
|
};
|
|
5300
5283
|
|
|
5284
|
+
const printPrettyError = (prettyError, prefix = '') => {
|
|
5285
|
+
error(`${prefix}${prettyError.type}: ${prettyError.message}\n\n${prettyError.codeFrame}\n\n${prettyError.stack}\n`);
|
|
5286
|
+
};
|
|
5287
|
+
|
|
5288
|
+
const logError = (error, prettyError) => {
|
|
5289
|
+
printPrettyError(prettyError, '[main-process] ');
|
|
5290
|
+
};
|
|
5291
|
+
const handleMessage = event => {
|
|
5292
|
+
return handleJsonRpcMessage(event.target, event.data, execute, resolve, prepare,
|
|
5293
|
+
// @ts-ignore
|
|
5294
|
+
logError, requiresSocket);
|
|
5295
|
+
};
|
|
5296
|
+
|
|
5297
|
+
const handleIpc = ipc => {
|
|
5298
|
+
if ('addEventListener' in ipc) {
|
|
5299
|
+
ipc.addEventListener('message', handleMessage);
|
|
5300
|
+
} else if ('on' in ipc) {
|
|
5301
|
+
// deprecated
|
|
5302
|
+
ipc.on('message', handleMessage);
|
|
5303
|
+
}
|
|
5304
|
+
};
|
|
5305
|
+
const unhandleIpc = ipc => {
|
|
5306
|
+
if ('removeEventListener' in ipc) {
|
|
5307
|
+
ipc.removeEventListener('message', handleMessage);
|
|
5308
|
+
} else if ('off' in ipc) {
|
|
5309
|
+
ipc.off('message', handleMessage);
|
|
5310
|
+
}
|
|
5311
|
+
};
|
|
5312
|
+
|
|
5301
5313
|
const NodeWorker = 1;
|
|
5302
5314
|
const NodeForkedProcess = 2;
|
|
5303
5315
|
const ElectronUtilityProcess = 3;
|
|
@@ -5384,40 +5396,6 @@ const registerWebviewProtocol = async port => {
|
|
|
5384
5396
|
handle(session.protocol, WebView, handleRequest);
|
|
5385
5397
|
};
|
|
5386
5398
|
|
|
5387
|
-
const getModule$1 = method => {
|
|
5388
|
-
switch (method) {
|
|
5389
|
-
case NodeForkedProcess$1:
|
|
5390
|
-
return IpcChildWithNodeForkedProcess$1;
|
|
5391
|
-
case NodeWorker$1:
|
|
5392
|
-
return IpcChildWithNodeWorker$1;
|
|
5393
|
-
case ElectronUtilityProcess$1:
|
|
5394
|
-
return IpcChildWithElectronUtilityProcess$1;
|
|
5395
|
-
case ElectronMessagePort$1:
|
|
5396
|
-
return IpcChildWithElectronMessagePort$1;
|
|
5397
|
-
case RendererProcess2:
|
|
5398
|
-
return IpcChildWithRendererProcess2$1;
|
|
5399
|
-
default:
|
|
5400
|
-
throw new Error('unexpected ipc type');
|
|
5401
|
-
}
|
|
5402
|
-
};
|
|
5403
|
-
|
|
5404
|
-
const listen = async ({
|
|
5405
|
-
method,
|
|
5406
|
-
...params
|
|
5407
|
-
}) => {
|
|
5408
|
-
const module = getModule$1(method);
|
|
5409
|
-
// @ts-ignore
|
|
5410
|
-
const rawIpc = await module.listen(params);
|
|
5411
|
-
// @ts-ignore
|
|
5412
|
-
if (module.signal) {
|
|
5413
|
-
// @ts-ignore
|
|
5414
|
-
module.signal(rawIpc);
|
|
5415
|
-
}
|
|
5416
|
-
// @ts-ignore
|
|
5417
|
-
const ipc = module.wrap(rawIpc);
|
|
5418
|
-
return ipc;
|
|
5419
|
-
};
|
|
5420
|
-
|
|
5421
5399
|
class WindowLoadError extends VError {
|
|
5422
5400
|
constructor(error, url) {
|
|
5423
5401
|
super(error, `Failed to load url ${url}`);
|
|
@@ -5477,11 +5455,10 @@ const createAppWindow = async (windowOptions, parsedArgs, workingDirectory, titl
|
|
|
5477
5455
|
}
|
|
5478
5456
|
};
|
|
5479
5457
|
window.on('close', handleWindowClose);
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5458
|
+
await ElectronWebContentsRpcClient.create({
|
|
5459
|
+
webContents: window.webContents,
|
|
5460
|
+
commandMap: commandMapRef
|
|
5483
5461
|
});
|
|
5484
|
-
handleIpc(ipc);
|
|
5485
5462
|
await loadUrl(window, url);
|
|
5486
5463
|
};
|
|
5487
5464
|
|
|
@@ -5496,19 +5473,57 @@ const crashMainProcess$1 = () => {
|
|
|
5496
5473
|
setTimeout(handleTimeout, 0);
|
|
5497
5474
|
};
|
|
5498
5475
|
|
|
5499
|
-
const
|
|
5476
|
+
const transferMessagePortMain = async (rpc, port, ...params) => {
|
|
5477
|
+
try {
|
|
5478
|
+
await rpc.invokeAndTransfer('HandleElectronMessagePort.handleElectronMessagePort', port, ...params);
|
|
5479
|
+
} catch (error) {
|
|
5480
|
+
throw new VError(error, `Failed to send message port to utility process`);
|
|
5481
|
+
}
|
|
5482
|
+
};
|
|
5483
|
+
|
|
5484
|
+
const connectIpc$2 = async (rpc, browserWindowPort, ...params) => {
|
|
5485
|
+
await transferMessagePortMain(rpc, browserWindowPort, ...params);
|
|
5486
|
+
};
|
|
5487
|
+
|
|
5488
|
+
const transferMessagePort = async (rpc, port, ...params) => {
|
|
5489
|
+
try {
|
|
5490
|
+
await rpc.invokeAndTransfer('HandleNodeMessagePort.handleNodeMessagePort', port, ...params);
|
|
5491
|
+
} catch (error) {
|
|
5492
|
+
throw new VError(error, `Failed to send message port to worker thread`);
|
|
5493
|
+
}
|
|
5494
|
+
};
|
|
5495
|
+
|
|
5496
|
+
const connectIpc$1 = async (rpc, browserWindowPort, ...params) => {
|
|
5497
|
+
const messageChannel = new MessageChannel();
|
|
5498
|
+
const {
|
|
5499
|
+
port1,
|
|
5500
|
+
port2
|
|
5501
|
+
} = messageChannel;
|
|
5502
|
+
browserWindowPort.on('message', event => {
|
|
5503
|
+
// console.log('got message from browser window', event.data)
|
|
5504
|
+
port2.postMessage(event.data);
|
|
5505
|
+
});
|
|
5506
|
+
port2.on('message', message => {
|
|
5507
|
+
// console.log('send message to browser window', message)
|
|
5508
|
+
browserWindowPort.postMessage(message);
|
|
5509
|
+
});
|
|
5510
|
+
await transferMessagePort(rpc, port1, ...params);
|
|
5511
|
+
browserWindowPort.start();
|
|
5512
|
+
};
|
|
5513
|
+
|
|
5514
|
+
const getModule$1 = method => {
|
|
5500
5515
|
switch (method) {
|
|
5501
5516
|
case NodeWorker:
|
|
5502
|
-
return
|
|
5517
|
+
return connectIpc$1;
|
|
5503
5518
|
case ElectronUtilityProcess:
|
|
5504
|
-
return
|
|
5519
|
+
return connectIpc$2;
|
|
5505
5520
|
default:
|
|
5506
5521
|
throw new Error('unexpected ipc type');
|
|
5507
5522
|
}
|
|
5508
5523
|
};
|
|
5509
|
-
const connectIpc
|
|
5510
|
-
const
|
|
5511
|
-
return
|
|
5524
|
+
const connectIpc = async (method, rpc, browserWindowPort, ipcId) => {
|
|
5525
|
+
const connectIpc = getModule$1(method);
|
|
5526
|
+
return connectIpc(rpc, browserWindowPort, ipcId);
|
|
5512
5527
|
};
|
|
5513
5528
|
|
|
5514
5529
|
// TODO maybe handle critical (first render) request via ipcMain
|
|
@@ -5531,7 +5546,7 @@ const handlePort = async (browserWindowPort, ipcId) => {
|
|
|
5531
5546
|
FOLDER: ''
|
|
5532
5547
|
}
|
|
5533
5548
|
});
|
|
5534
|
-
await connectIpc
|
|
5549
|
+
await connectIpc(method, sharedProcess, browserWindowPort, ipcId);
|
|
5535
5550
|
};
|
|
5536
5551
|
|
|
5537
5552
|
// TODO reverse order of parameters: make ports first
|
|
@@ -6914,6 +6929,40 @@ const getStats$1 = view => {
|
|
|
6914
6929
|
};
|
|
6915
6930
|
};
|
|
6916
6931
|
|
|
6932
|
+
const getModule = method => {
|
|
6933
|
+
switch (method) {
|
|
6934
|
+
case NodeForkedProcess$1:
|
|
6935
|
+
return IpcChildWithNodeForkedProcess$1;
|
|
6936
|
+
case NodeWorker$1:
|
|
6937
|
+
return IpcChildWithNodeWorker$1;
|
|
6938
|
+
case ElectronUtilityProcess$1:
|
|
6939
|
+
return IpcChildWithElectronUtilityProcess$1;
|
|
6940
|
+
case ElectronMessagePort$1:
|
|
6941
|
+
return IpcChildWithElectronMessagePort$1;
|
|
6942
|
+
case RendererProcess2:
|
|
6943
|
+
return IpcChildWithRendererProcess2$1;
|
|
6944
|
+
default:
|
|
6945
|
+
throw new Error('unexpected ipc type');
|
|
6946
|
+
}
|
|
6947
|
+
};
|
|
6948
|
+
|
|
6949
|
+
const listen = async ({
|
|
6950
|
+
method,
|
|
6951
|
+
...params
|
|
6952
|
+
}) => {
|
|
6953
|
+
const module = getModule(method);
|
|
6954
|
+
// @ts-ignore
|
|
6955
|
+
const rawIpc = await module.listen(params);
|
|
6956
|
+
// @ts-ignore
|
|
6957
|
+
if (module.signal) {
|
|
6958
|
+
// @ts-ignore
|
|
6959
|
+
module.signal(rawIpc);
|
|
6960
|
+
}
|
|
6961
|
+
// @ts-ignore
|
|
6962
|
+
const ipc = module.wrap(rawIpc);
|
|
6963
|
+
return ipc;
|
|
6964
|
+
};
|
|
6965
|
+
|
|
6917
6966
|
const open2 = async (options, url) => {
|
|
6918
6967
|
const allOptions = {
|
|
6919
6968
|
...options,
|
|
@@ -7280,54 +7329,6 @@ const index = {
|
|
|
7280
7329
|
default: isDev
|
|
7281
7330
|
};
|
|
7282
7331
|
|
|
7283
|
-
const transferMessagePort = async (ipc, port, ...params) => {
|
|
7284
|
-
try {
|
|
7285
|
-
await invokeAndTransfer$1(ipc, 'HandleNodeMessagePort.handleNodeMessagePort', port, ...params);
|
|
7286
|
-
} catch (error) {
|
|
7287
|
-
throw new VError(error, `Failed to send message port to worker thread`);
|
|
7288
|
-
}
|
|
7289
|
-
};
|
|
7290
|
-
|
|
7291
|
-
const connectIpc$1 = async (ipc, browserWindowPort, ...params) => {
|
|
7292
|
-
const messageChannel = new MessageChannel();
|
|
7293
|
-
const {
|
|
7294
|
-
port1,
|
|
7295
|
-
port2
|
|
7296
|
-
} = messageChannel;
|
|
7297
|
-
browserWindowPort.on('message', event => {
|
|
7298
|
-
// console.log('got message from browser window', event.data)
|
|
7299
|
-
port2.postMessage(event.data);
|
|
7300
|
-
});
|
|
7301
|
-
port2.on('message', message => {
|
|
7302
|
-
// console.log('send message to browser window', message)
|
|
7303
|
-
browserWindowPort.postMessage(message);
|
|
7304
|
-
});
|
|
7305
|
-
await transferMessagePort(ipc, port1, ...params);
|
|
7306
|
-
browserWindowPort.start();
|
|
7307
|
-
};
|
|
7308
|
-
|
|
7309
|
-
const ConnectIpcNodeWorker = {
|
|
7310
|
-
__proto__: null,
|
|
7311
|
-
connectIpc: connectIpc$1
|
|
7312
|
-
};
|
|
7313
|
-
|
|
7314
|
-
const transferMessagePortMain = async (ipc, port, ...params) => {
|
|
7315
|
-
try {
|
|
7316
|
-
await invokeAndTransfer$1(ipc, 'HandleElectronMessagePort.handleElectronMessagePort', port, ...params);
|
|
7317
|
-
} catch (error) {
|
|
7318
|
-
throw new VError(error, `Failed to send message port to utility process`);
|
|
7319
|
-
}
|
|
7320
|
-
};
|
|
7321
|
-
|
|
7322
|
-
const connectIpc = async (ipc, browserWindowPort, ...params) => {
|
|
7323
|
-
await transferMessagePortMain(ipc, browserWindowPort, ...params);
|
|
7324
|
-
};
|
|
7325
|
-
|
|
7326
|
-
const ConnectIpcElectronUtilityProcess = {
|
|
7327
|
-
__proto__: null,
|
|
7328
|
-
connectIpc
|
|
7329
|
-
};
|
|
7330
|
-
|
|
7331
7332
|
const name$w = 'App';
|
|
7332
7333
|
const Commands$w = {};
|
|
7333
7334
|
|