@lvce-editor/main-process 2.4.0 → 2.5.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 +174 -190
- package/package.json +1 -1
package/dist/mainProcessMain.js
CHANGED
|
@@ -5,6 +5,7 @@ import { inspect } from 'node:util';
|
|
|
5
5
|
import { spawn } from 'node:child_process';
|
|
6
6
|
import { MessageChannel } from 'node:worker_threads';
|
|
7
7
|
import { createWriteStream, readFileSync } from 'node:fs';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
8
9
|
import * as NodePath from 'node:path';
|
|
9
10
|
import { dirname } from 'node:path';
|
|
10
11
|
import require$$1 from 'tty';
|
|
@@ -12,7 +13,6 @@ import require$$1$1 from 'util';
|
|
|
12
13
|
import require$$0 from 'os';
|
|
13
14
|
import { Console } from 'node:console';
|
|
14
15
|
import { tmpdir, homedir } from 'node:os';
|
|
15
|
-
import { fileURLToPath } from 'node:url';
|
|
16
16
|
|
|
17
17
|
function escapeStringRegexp(string) {
|
|
18
18
|
if (typeof string !== 'string') {
|
|
@@ -757,7 +757,7 @@ const getNewLineIndex$2 = (string, startIndex = undefined) => {
|
|
|
757
757
|
|
|
758
758
|
// TODO disable logging via environment variable, don't enable logging during tests
|
|
759
759
|
|
|
760
|
-
const state$
|
|
760
|
+
const state$7 = {
|
|
761
761
|
console: undefined
|
|
762
762
|
};
|
|
763
763
|
const createConsole = () => {
|
|
@@ -767,8 +767,8 @@ const createConsole = () => {
|
|
|
767
767
|
return logger;
|
|
768
768
|
};
|
|
769
769
|
const getOrCreateLogger = () => {
|
|
770
|
-
state$
|
|
771
|
-
return state$
|
|
770
|
+
state$7.console ||= createConsole();
|
|
771
|
+
return state$7.console;
|
|
772
772
|
};
|
|
773
773
|
const info = (...args) => {
|
|
774
774
|
const logger = getOrCreateLogger();
|
|
@@ -2707,7 +2707,7 @@ const create$4 = (method, params) => {
|
|
|
2707
2707
|
};
|
|
2708
2708
|
};
|
|
2709
2709
|
const callbacks = Object.create(null);
|
|
2710
|
-
const set$
|
|
2710
|
+
const set$1 = (id, fn) => {
|
|
2711
2711
|
callbacks[id] = fn;
|
|
2712
2712
|
};
|
|
2713
2713
|
const get$4 = id => {
|
|
@@ -2726,7 +2726,7 @@ const registerPromise = () => {
|
|
|
2726
2726
|
resolve,
|
|
2727
2727
|
promise
|
|
2728
2728
|
} = Promise.withResolvers();
|
|
2729
|
-
set$
|
|
2729
|
+
set$1(id, resolve);
|
|
2730
2730
|
return {
|
|
2731
2731
|
id,
|
|
2732
2732
|
promise
|
|
@@ -3337,7 +3337,7 @@ const launchSharedProcess = async ({
|
|
|
3337
3337
|
return sharedProcessRpc;
|
|
3338
3338
|
};
|
|
3339
3339
|
|
|
3340
|
-
const state$
|
|
3340
|
+
const state$6 = {
|
|
3341
3341
|
/**
|
|
3342
3342
|
* @type {any}
|
|
3343
3343
|
*/
|
|
@@ -3348,14 +3348,14 @@ const getOrCreate = async ({
|
|
|
3348
3348
|
method,
|
|
3349
3349
|
env = {}
|
|
3350
3350
|
}) => {
|
|
3351
|
-
if (!state$
|
|
3351
|
+
if (!state$6.promise) {
|
|
3352
3352
|
// @ts-ignore
|
|
3353
|
-
state$
|
|
3353
|
+
state$6.promise = launchSharedProcess({
|
|
3354
3354
|
method,
|
|
3355
3355
|
env
|
|
3356
3356
|
});
|
|
3357
3357
|
}
|
|
3358
|
-
return state$
|
|
3358
|
+
return state$6.promise;
|
|
3359
3359
|
};
|
|
3360
3360
|
const send$1 = async (method, ...params) => {
|
|
3361
3361
|
const rpc = await getOrCreate({
|
|
@@ -4478,14 +4478,14 @@ const createTitleBar = items => {
|
|
|
4478
4478
|
|
|
4479
4479
|
const PHASE_DEFAULT = 0;
|
|
4480
4480
|
const PHASE_SHUTDOWN = -1;
|
|
4481
|
-
const state$
|
|
4481
|
+
const state$5 = {
|
|
4482
4482
|
phase: PHASE_DEFAULT
|
|
4483
4483
|
};
|
|
4484
4484
|
const isShutDown = () => {
|
|
4485
|
-
return state$
|
|
4485
|
+
return state$5.phase === PHASE_SHUTDOWN;
|
|
4486
4486
|
};
|
|
4487
4487
|
const setShutDown = () => {
|
|
4488
|
-
state$
|
|
4488
|
+
state$5.phase = PHASE_SHUTDOWN;
|
|
4489
4489
|
};
|
|
4490
4490
|
|
|
4491
4491
|
// TODO move this function to shared process
|
|
@@ -4782,21 +4782,21 @@ const BeforeInputEvent = 'before-input-event';
|
|
|
4782
4782
|
const Allow = 'allow';
|
|
4783
4783
|
const Deny = 'deny';
|
|
4784
4784
|
|
|
4785
|
-
const state$
|
|
4785
|
+
const state$4 = {
|
|
4786
4786
|
views: Object.create(null),
|
|
4787
4787
|
fallThroughKeyBindings: [],
|
|
4788
4788
|
canceled: Object.create(null)
|
|
4789
4789
|
};
|
|
4790
4790
|
const add$1 = (id, browserWindow, view) => {
|
|
4791
4791
|
// state
|
|
4792
|
-
state$
|
|
4792
|
+
state$4.views[id] = {
|
|
4793
4793
|
browserWindow,
|
|
4794
4794
|
view
|
|
4795
4795
|
};
|
|
4796
4796
|
};
|
|
4797
4797
|
const hasWebContents = id => {
|
|
4798
4798
|
number(id);
|
|
4799
|
-
return id in state$
|
|
4799
|
+
return id in state$4.views;
|
|
4800
4800
|
};
|
|
4801
4801
|
/**
|
|
4802
4802
|
*
|
|
@@ -4804,19 +4804,19 @@ const hasWebContents = id => {
|
|
|
4804
4804
|
* @returns {{browserWindow: Electron.BrowserWindow, view: Electron.WebContentsView}}
|
|
4805
4805
|
*/
|
|
4806
4806
|
const get$3 = id => {
|
|
4807
|
-
return state$
|
|
4807
|
+
return state$4.views[id];
|
|
4808
4808
|
};
|
|
4809
4809
|
const remove$1 = id => {
|
|
4810
|
-
delete state$
|
|
4810
|
+
delete state$4.views[id];
|
|
4811
4811
|
};
|
|
4812
4812
|
const setFallthroughKeyBindings = fallthroughKeyBindings => {
|
|
4813
|
-
state$
|
|
4813
|
+
state$4.fallThroughKeyBindings = fallthroughKeyBindings;
|
|
4814
4814
|
};
|
|
4815
4815
|
const getFallthroughKeyBindings = () => {
|
|
4816
|
-
return state$
|
|
4816
|
+
return state$4.fallThroughKeyBindings;
|
|
4817
4817
|
};
|
|
4818
4818
|
const setCanceled = id => {
|
|
4819
|
-
state$
|
|
4819
|
+
state$4.canceled[id] = true;
|
|
4820
4820
|
};
|
|
4821
4821
|
|
|
4822
4822
|
const shouldAllowNavigation = webContentsId => {
|
|
@@ -4829,6 +4829,7 @@ const shouldAllowNavigation = webContentsId => {
|
|
|
4829
4829
|
const handleWebContentsWindowOpen = ({
|
|
4830
4830
|
url
|
|
4831
4831
|
}) => {
|
|
4832
|
+
// @ts-ignore
|
|
4832
4833
|
void undefined(url);
|
|
4833
4834
|
return {
|
|
4834
4835
|
action: Deny
|
|
@@ -4891,13 +4892,6 @@ const privilegedSchems = [{
|
|
|
4891
4892
|
}
|
|
4892
4893
|
}];
|
|
4893
4894
|
|
|
4894
|
-
/**
|
|
4895
|
-
*
|
|
4896
|
-
* @param {Electron.Protocol} protocol
|
|
4897
|
-
* @param {string} name
|
|
4898
|
-
* @param {(request: GlobalRequest) => Promise<GlobalResponse>} handleRequest
|
|
4899
|
-
* @returns
|
|
4900
|
-
*/
|
|
4901
4895
|
const handle = (protocol, name, handleRequest) => {
|
|
4902
4896
|
if (isProtocolHandleApiSupported(protocol)) {
|
|
4903
4897
|
protocol.handle(name, handleRequest);
|
|
@@ -4905,12 +4899,6 @@ const handle = (protocol, name, handleRequest) => {
|
|
|
4905
4899
|
}
|
|
4906
4900
|
throw new Error('protocol.handle api is not supported');
|
|
4907
4901
|
};
|
|
4908
|
-
|
|
4909
|
-
/**
|
|
4910
|
-
*
|
|
4911
|
-
* @param {Electron.Protocol} protocol
|
|
4912
|
-
* @returns
|
|
4913
|
-
*/
|
|
4914
4902
|
const enable = protocol => {
|
|
4915
4903
|
protocol.registerSchemesAsPrivileged(privilegedSchems);
|
|
4916
4904
|
};
|
|
@@ -5123,7 +5111,7 @@ const getModuleId = commandId => {
|
|
|
5123
5111
|
}
|
|
5124
5112
|
};
|
|
5125
5113
|
|
|
5126
|
-
const state$
|
|
5114
|
+
const state$3 = {
|
|
5127
5115
|
commands: Object.create(null),
|
|
5128
5116
|
pendingModules: Object.create(null),
|
|
5129
5117
|
async load(moduleId) {}
|
|
@@ -5143,21 +5131,21 @@ const initializeModule = module => {
|
|
|
5143
5131
|
throw new Error(`module ${module.name || '<unnamed module>'} is missing commands`);
|
|
5144
5132
|
};
|
|
5145
5133
|
const getOrLoadModule = moduleId => {
|
|
5146
|
-
if (!state$
|
|
5147
|
-
const importPromise = state$
|
|
5148
|
-
state$
|
|
5134
|
+
if (!state$3.pendingModules[moduleId]) {
|
|
5135
|
+
const importPromise = state$3.load(moduleId);
|
|
5136
|
+
state$3.pendingModules[moduleId] = importPromise.then(initializeModule);
|
|
5149
5137
|
}
|
|
5150
|
-
return state$
|
|
5138
|
+
return state$3.pendingModules[moduleId];
|
|
5151
5139
|
};
|
|
5152
5140
|
const loadCommand = command => getOrLoadModule(getModuleId(command));
|
|
5153
5141
|
const register = (commandId, listener) => {
|
|
5154
|
-
state$
|
|
5142
|
+
state$3.commands[commandId] = listener;
|
|
5155
5143
|
};
|
|
5156
5144
|
const hasThrown = new Set();
|
|
5157
5145
|
const loadThenExecute = async (command, ...args) => {
|
|
5158
5146
|
await loadCommand(command);
|
|
5159
5147
|
// TODO can skip then block in prod (only to prevent endless loop in dev)
|
|
5160
|
-
if (!(command in state$
|
|
5148
|
+
if (!(command in state$3.commands)) {
|
|
5161
5149
|
if (hasThrown.has(command)) {
|
|
5162
5150
|
return;
|
|
5163
5151
|
}
|
|
@@ -5167,13 +5155,13 @@ const loadThenExecute = async (command, ...args) => {
|
|
|
5167
5155
|
return execute(command, ...args);
|
|
5168
5156
|
};
|
|
5169
5157
|
const execute = (command, ...args) => {
|
|
5170
|
-
if (command in state$
|
|
5171
|
-
return state$
|
|
5158
|
+
if (command in state$3.commands) {
|
|
5159
|
+
return state$3.commands[command](...args);
|
|
5172
5160
|
}
|
|
5173
5161
|
return loadThenExecute(command, ...args);
|
|
5174
5162
|
};
|
|
5175
5163
|
const setLoad = load => {
|
|
5176
|
-
state$
|
|
5164
|
+
state$3.load = load;
|
|
5177
5165
|
};
|
|
5178
5166
|
|
|
5179
5167
|
const ClipBoardRead = 'clipboard-read';
|
|
@@ -5265,110 +5253,32 @@ const createElectronSession = () => {
|
|
|
5265
5253
|
return session;
|
|
5266
5254
|
};
|
|
5267
5255
|
|
|
5268
|
-
const state$
|
|
5256
|
+
const state$2 = {
|
|
5269
5257
|
session: undefined
|
|
5270
5258
|
};
|
|
5271
5259
|
const has = () => {
|
|
5272
|
-
return Boolean(state$
|
|
5260
|
+
return Boolean(state$2.session);
|
|
5273
5261
|
};
|
|
5274
5262
|
const get$2 = () => {
|
|
5275
|
-
if (!state$
|
|
5263
|
+
if (!state$2.session) {
|
|
5276
5264
|
throw new Error('session is not defined');
|
|
5277
5265
|
}
|
|
5278
|
-
return state$
|
|
5279
|
-
};
|
|
5280
|
-
const set$1 = value => {
|
|
5281
|
-
state$3.session = value;
|
|
5282
|
-
};
|
|
5283
|
-
|
|
5284
|
-
const printPrettyError = (prettyError, prefix = '') => {
|
|
5285
|
-
error(`${prefix}${prettyError.type}: ${prettyError.message}\n\n${prettyError.codeFrame}\n\n${prettyError.stack}\n`);
|
|
5266
|
+
return state$2.session;
|
|
5286
5267
|
};
|
|
5287
|
-
|
|
5288
|
-
|
|
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);
|
|
5268
|
+
const set = value => {
|
|
5269
|
+
state$2.session = value;
|
|
5295
5270
|
};
|
|
5296
5271
|
|
|
5297
|
-
const
|
|
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
|
-
|
|
5313
|
-
const NodeWorker = 1;
|
|
5314
|
-
const NodeForkedProcess = 2;
|
|
5315
|
-
const ElectronUtilityProcess = 3;
|
|
5316
|
-
const ElectronMessagePort = 4;
|
|
5317
|
-
|
|
5318
|
-
const getModule$2 = method => {
|
|
5319
|
-
switch (method) {
|
|
5320
|
-
case NodeWorker:
|
|
5321
|
-
return IpcParentWithNodeWorker$1;
|
|
5322
|
-
case NodeForkedProcess:
|
|
5323
|
-
return IpcParentWithNodeForkedProcess$1;
|
|
5324
|
-
case ElectronUtilityProcess:
|
|
5325
|
-
return Promise.resolve().then(function () { return IpcParentWithElectronUtilityProcess; });
|
|
5326
|
-
case ElectronMessagePort:
|
|
5327
|
-
return IpcParentWithElectronMessagePort$1;
|
|
5328
|
-
default:
|
|
5329
|
-
throw new Error(`unexpected ipc type ${method}`);
|
|
5330
|
-
}
|
|
5331
|
-
};
|
|
5332
|
-
|
|
5333
|
-
/**
|
|
5334
|
-
*
|
|
5335
|
-
* @param {*} param0
|
|
5336
|
-
* @returns {Promise<any>}
|
|
5337
|
-
*/
|
|
5338
|
-
const create$2 = async ({
|
|
5339
|
-
method,
|
|
5340
|
-
...options
|
|
5341
|
-
}) => {
|
|
5342
|
-
const module = await getModule$2(method);
|
|
5343
|
-
// @ts-ignore
|
|
5344
|
-
const rawIpc = await module.create(options);
|
|
5345
|
-
// @ts-ignore
|
|
5346
|
-
if (module.effects) {
|
|
5347
|
-
// @ts-ignore
|
|
5348
|
-
module.effects({
|
|
5349
|
-
rawIpc,
|
|
5350
|
-
...options
|
|
5351
|
-
});
|
|
5352
|
-
}
|
|
5353
|
-
if (options.noReturn) {
|
|
5354
|
-
return undefined;
|
|
5355
|
-
}
|
|
5356
|
-
// @ts-ignore
|
|
5357
|
-
const ipc = module.wrap(rawIpc);
|
|
5358
|
-
return ipc;
|
|
5359
|
-
};
|
|
5360
|
-
|
|
5361
|
-
const create$1 = ipc => {
|
|
5272
|
+
const create$2 = rpc => {
|
|
5362
5273
|
const handleRequest = async request => {
|
|
5363
5274
|
const {
|
|
5364
5275
|
method,
|
|
5365
5276
|
url
|
|
5366
5277
|
} = request;
|
|
5367
|
-
console.log('got request', method, url);
|
|
5368
5278
|
const {
|
|
5369
5279
|
body,
|
|
5370
5280
|
init
|
|
5371
|
-
} = await invoke
|
|
5281
|
+
} = await rpc.invoke('WebViewProtocol.getResponse', method, url);
|
|
5372
5282
|
return new Response(body, init);
|
|
5373
5283
|
};
|
|
5374
5284
|
return handleRequest;
|
|
@@ -5376,23 +5286,19 @@ const create$1 = ipc => {
|
|
|
5376
5286
|
|
|
5377
5287
|
const get$1 = () => {
|
|
5378
5288
|
if (!has()) {
|
|
5379
|
-
set
|
|
5289
|
+
set(createElectronSession());
|
|
5380
5290
|
}
|
|
5381
5291
|
return get$2();
|
|
5382
5292
|
};
|
|
5383
5293
|
const registerWebviewProtocol = async port => {
|
|
5384
5294
|
object(port);
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5295
|
+
const rpc = await ElectronMessagePortRpcClient.create({
|
|
5296
|
+
commandMap: {},
|
|
5297
|
+
messagePort: port,
|
|
5298
|
+
requiresSocket: requiresSocket
|
|
5389
5299
|
});
|
|
5390
|
-
console.log('do register protocol');
|
|
5391
|
-
handleIpc(ipc);
|
|
5392
|
-
port.start();
|
|
5393
5300
|
const session = get$1();
|
|
5394
|
-
const handleRequest = create$
|
|
5395
|
-
// @ts-ignore
|
|
5301
|
+
const handleRequest = create$2(rpc);
|
|
5396
5302
|
handle(session.protocol, WebView, handleRequest);
|
|
5397
5303
|
};
|
|
5398
5304
|
|
|
@@ -5511,7 +5417,12 @@ const connectIpc$1 = async (rpc, browserWindowPort, ...params) => {
|
|
|
5511
5417
|
browserWindowPort.start();
|
|
5512
5418
|
};
|
|
5513
5419
|
|
|
5514
|
-
const
|
|
5420
|
+
const NodeWorker = 1;
|
|
5421
|
+
const NodeForkedProcess = 2;
|
|
5422
|
+
const ElectronUtilityProcess = 3;
|
|
5423
|
+
const ElectronMessagePort = 4;
|
|
5424
|
+
|
|
5425
|
+
const getModule$2 = method => {
|
|
5515
5426
|
switch (method) {
|
|
5516
5427
|
case NodeWorker:
|
|
5517
5428
|
return connectIpc$1;
|
|
@@ -5522,7 +5433,7 @@ const getModule$1 = method => {
|
|
|
5522
5433
|
}
|
|
5523
5434
|
};
|
|
5524
5435
|
const connectIpc = async (method, rpc, browserWindowPort, ipcId) => {
|
|
5525
|
-
const connectIpc = getModule$
|
|
5436
|
+
const connectIpc = getModule$2(method);
|
|
5526
5437
|
return connectIpc(rpc, browserWindowPort, ipcId);
|
|
5527
5438
|
};
|
|
5528
5439
|
|
|
@@ -5558,27 +5469,27 @@ const createMessagePort = async (ipcId, port, webContentsId) => {
|
|
|
5558
5469
|
return webContentsId;
|
|
5559
5470
|
};
|
|
5560
5471
|
|
|
5561
|
-
const state$
|
|
5472
|
+
const state$1 = {
|
|
5562
5473
|
all: Object.create(null)
|
|
5563
5474
|
};
|
|
5564
5475
|
const add = (pid, process, name) => {
|
|
5565
5476
|
number(pid);
|
|
5566
5477
|
object(process);
|
|
5567
5478
|
string(name);
|
|
5568
|
-
state$
|
|
5479
|
+
state$1.all[pid] = {
|
|
5569
5480
|
process,
|
|
5570
5481
|
name
|
|
5571
5482
|
};
|
|
5572
5483
|
};
|
|
5573
5484
|
const remove = pid => {
|
|
5574
5485
|
number(pid);
|
|
5575
|
-
delete state$
|
|
5486
|
+
delete state$1.all[pid];
|
|
5576
5487
|
};
|
|
5577
5488
|
const getAll = () => {
|
|
5578
|
-
return Object.entries(state$
|
|
5489
|
+
return Object.entries(state$1.all);
|
|
5579
5490
|
};
|
|
5580
5491
|
const getByName = name => {
|
|
5581
|
-
for (const value of Object.values(state$
|
|
5492
|
+
for (const value of Object.values(state$1.all)) {
|
|
5582
5493
|
// @ts-ignore
|
|
5583
5494
|
if (value.name === name) {
|
|
5584
5495
|
// @ts-ignore
|
|
@@ -5645,7 +5556,8 @@ const createUtilityProcessRpc = async options => {
|
|
|
5645
5556
|
commandMap: commandMapRef,
|
|
5646
5557
|
...options
|
|
5647
5558
|
});
|
|
5648
|
-
|
|
5559
|
+
const rpcId = options.targetRpcId || options.rpcId || options.ipcId;
|
|
5560
|
+
set$3(rpcId, rpc);
|
|
5649
5561
|
};
|
|
5650
5562
|
|
|
5651
5563
|
const serializeDeskopCapturerSource = source => {
|
|
@@ -6596,7 +6508,7 @@ const filter = {
|
|
|
6596
6508
|
urls: ['<all_urls>']
|
|
6597
6509
|
};
|
|
6598
6510
|
|
|
6599
|
-
const state
|
|
6511
|
+
const state = {
|
|
6600
6512
|
session: undefined
|
|
6601
6513
|
};
|
|
6602
6514
|
const isAllowedPermission = permission => {
|
|
@@ -6629,24 +6541,16 @@ const createSession = () => {
|
|
|
6629
6541
|
return session;
|
|
6630
6542
|
};
|
|
6631
6543
|
const getSession = () => {
|
|
6632
|
-
state
|
|
6633
|
-
return state
|
|
6544
|
+
state.session ||= createSession();
|
|
6545
|
+
return state.session;
|
|
6634
6546
|
};
|
|
6635
6547
|
|
|
6636
|
-
const state = {
|
|
6637
|
-
ipc: undefined
|
|
6638
|
-
};
|
|
6639
|
-
const set = ipc => {
|
|
6640
|
-
state.ipc = ipc;
|
|
6641
|
-
};
|
|
6642
6548
|
const send = (method, ...params) => {
|
|
6643
|
-
const
|
|
6644
|
-
|
|
6645
|
-
} = state;
|
|
6646
|
-
if (!ipc) {
|
|
6549
|
+
const rpc = get(EmbedsProcess);
|
|
6550
|
+
if (!rpc) {
|
|
6647
6551
|
return;
|
|
6648
6552
|
}
|
|
6649
|
-
send
|
|
6553
|
+
return rpc.send(method, ...params);
|
|
6650
6554
|
};
|
|
6651
6555
|
|
|
6652
6556
|
// TODO use electron 30 webcontentsview api
|
|
@@ -6945,7 +6849,36 @@ const getStats$1 = view => {
|
|
|
6945
6849
|
};
|
|
6946
6850
|
};
|
|
6947
6851
|
|
|
6948
|
-
const
|
|
6852
|
+
const printPrettyError = (prettyError, prefix = '') => {
|
|
6853
|
+
error(`${prefix}${prettyError.type}: ${prettyError.message}\n\n${prettyError.codeFrame}\n\n${prettyError.stack}\n`);
|
|
6854
|
+
};
|
|
6855
|
+
|
|
6856
|
+
const logError = (error, prettyError) => {
|
|
6857
|
+
printPrettyError(prettyError, '[main-process] ');
|
|
6858
|
+
};
|
|
6859
|
+
const handleMessage = event => {
|
|
6860
|
+
return handleJsonRpcMessage(event.target, event.data, execute, resolve, prepare,
|
|
6861
|
+
// @ts-ignore
|
|
6862
|
+
logError, requiresSocket);
|
|
6863
|
+
};
|
|
6864
|
+
|
|
6865
|
+
const handleIpc = ipc => {
|
|
6866
|
+
if ('addEventListener' in ipc) {
|
|
6867
|
+
ipc.addEventListener('message', handleMessage);
|
|
6868
|
+
} else if ('on' in ipc) {
|
|
6869
|
+
// deprecated
|
|
6870
|
+
ipc.on('message', handleMessage);
|
|
6871
|
+
}
|
|
6872
|
+
};
|
|
6873
|
+
const unhandleIpc = ipc => {
|
|
6874
|
+
if ('removeEventListener' in ipc) {
|
|
6875
|
+
ipc.removeEventListener('message', handleMessage);
|
|
6876
|
+
} else if ('off' in ipc) {
|
|
6877
|
+
ipc.off('message', handleMessage);
|
|
6878
|
+
}
|
|
6879
|
+
};
|
|
6880
|
+
|
|
6881
|
+
const getModule$1 = method => {
|
|
6949
6882
|
switch (method) {
|
|
6950
6883
|
case NodeForkedProcess$1:
|
|
6951
6884
|
return IpcChildWithNodeForkedProcess$1;
|
|
@@ -6966,7 +6899,7 @@ const listen = async ({
|
|
|
6966
6899
|
method,
|
|
6967
6900
|
...params
|
|
6968
6901
|
}) => {
|
|
6969
|
-
const module = getModule(method);
|
|
6902
|
+
const module = getModule$1(method);
|
|
6970
6903
|
// @ts-ignore
|
|
6971
6904
|
const rawIpc = await module.listen(params);
|
|
6972
6905
|
// @ts-ignore
|
|
@@ -7033,18 +6966,62 @@ const getWindowId = webContentsId => {
|
|
|
7033
6966
|
return browserWindow.id;
|
|
7034
6967
|
};
|
|
7035
6968
|
|
|
7036
|
-
const handleElectronMessagePort = async (messagePort,
|
|
6969
|
+
const handleElectronMessagePort = async (messagePort, rpcId) => {
|
|
7037
6970
|
object(messagePort);
|
|
7038
|
-
const
|
|
7039
|
-
|
|
7040
|
-
|
|
6971
|
+
const rpc = await ElectronMessagePortRpcClient.create({
|
|
6972
|
+
messagePort: messagePort,
|
|
6973
|
+
commandMap: commandMapRef,
|
|
6974
|
+
requiresSocket: requiresSocket
|
|
7041
6975
|
});
|
|
7042
|
-
|
|
7043
|
-
|
|
7044
|
-
set(ipc);
|
|
6976
|
+
if (rpcId) {
|
|
6977
|
+
set$3(rpcId, rpc);
|
|
7045
6978
|
}
|
|
7046
6979
|
};
|
|
7047
6980
|
|
|
6981
|
+
const getModule = method => {
|
|
6982
|
+
switch (method) {
|
|
6983
|
+
case NodeWorker:
|
|
6984
|
+
return IpcParentWithNodeWorker$1;
|
|
6985
|
+
case NodeForkedProcess:
|
|
6986
|
+
return IpcParentWithNodeForkedProcess$1;
|
|
6987
|
+
case ElectronUtilityProcess:
|
|
6988
|
+
return Promise.resolve().then(function () { return IpcParentWithElectronUtilityProcess; });
|
|
6989
|
+
case ElectronMessagePort:
|
|
6990
|
+
return IpcParentWithElectronMessagePort$1;
|
|
6991
|
+
default:
|
|
6992
|
+
throw new Error(`unexpected ipc type ${method}`);
|
|
6993
|
+
}
|
|
6994
|
+
};
|
|
6995
|
+
|
|
6996
|
+
/**
|
|
6997
|
+
*
|
|
6998
|
+
* @param {*} param0
|
|
6999
|
+
* @returns {Promise<any>}
|
|
7000
|
+
* @deprecated
|
|
7001
|
+
*/
|
|
7002
|
+
const create$1 = async ({
|
|
7003
|
+
method,
|
|
7004
|
+
...options
|
|
7005
|
+
}) => {
|
|
7006
|
+
const module = await getModule(method);
|
|
7007
|
+
// @ts-ignore
|
|
7008
|
+
const rawIpc = await module.create(options);
|
|
7009
|
+
// @ts-ignore
|
|
7010
|
+
if (module.effects) {
|
|
7011
|
+
// @ts-ignore
|
|
7012
|
+
module.effects({
|
|
7013
|
+
rawIpc,
|
|
7014
|
+
...options
|
|
7015
|
+
});
|
|
7016
|
+
}
|
|
7017
|
+
if (options.noReturn) {
|
|
7018
|
+
return undefined;
|
|
7019
|
+
}
|
|
7020
|
+
// @ts-ignore
|
|
7021
|
+
const ipc = module.wrap(rawIpc);
|
|
7022
|
+
return ipc;
|
|
7023
|
+
};
|
|
7024
|
+
|
|
7048
7025
|
const shouldOpenExternal = url => {
|
|
7049
7026
|
if (url.startsWith('http:') || url.startsWith('https:')) {
|
|
7050
7027
|
return true;
|
|
@@ -7130,6 +7107,10 @@ const createPortTuple = async (id1, id2) => {
|
|
|
7130
7107
|
} = getPortTuple();
|
|
7131
7108
|
await invokeAndTransfer('TemporaryMessagePort.handlePorts', port1, port2, id1, id2);
|
|
7132
7109
|
};
|
|
7110
|
+
|
|
7111
|
+
/**
|
|
7112
|
+
* @deprecated
|
|
7113
|
+
*/
|
|
7133
7114
|
const sendTo = async (port, name, ipcId) => {
|
|
7134
7115
|
string(name);
|
|
7135
7116
|
object(port);
|
|
@@ -7142,10 +7123,13 @@ const sendTo = async (port, name, ipcId) => {
|
|
|
7142
7123
|
};
|
|
7143
7124
|
|
|
7144
7125
|
// TODO use rpc id, and then use rpc.invokeAndtransfer
|
|
7145
|
-
const sendTo2 = async (port,
|
|
7126
|
+
const sendTo2 = async (port, targetRpcId, sourceRpcId) => {
|
|
7146
7127
|
object(port);
|
|
7147
|
-
const rpc = get(
|
|
7148
|
-
|
|
7128
|
+
const rpc = get(targetRpcId);
|
|
7129
|
+
if (!rpc) {
|
|
7130
|
+
throw new Error(`rpc ${targetRpcId} not found`);
|
|
7131
|
+
}
|
|
7132
|
+
await rpc.invokeAndTransfer('HandleElectronMessagePort.handleElectronMessagePort', port, sourceRpcId);
|
|
7149
7133
|
};
|
|
7150
7134
|
|
|
7151
7135
|
// todo dispose the rpc by rpc id
|
|
@@ -7200,21 +7184,21 @@ const commandMap = {
|
|
|
7200
7184
|
'ElectronWebContentsView.createWebContentsView': createWebContentsView,
|
|
7201
7185
|
'ElectronWebContentsView.disposeWebContentsView': disposeWebContentsView,
|
|
7202
7186
|
'ElectronWebContentsViewFunctions.addToWindow': addToWindow,
|
|
7203
|
-
'ElectronWebContentsViewFunctions.backward': backward,
|
|
7204
|
-
'ElectronWebContentsViewFunctions.cancelNavigation': cancelNavigation,
|
|
7205
|
-
'ElectronWebContentsViewFunctions.copyImageAt': copyImageAt,
|
|
7206
|
-
'ElectronWebContentsViewFunctions.focus': focus,
|
|
7207
|
-
'ElectronWebContentsViewFunctions.forward': forward,
|
|
7208
|
-
'ElectronWebContentsViewFunctions.getStats': getStats$1,
|
|
7187
|
+
'ElectronWebContentsViewFunctions.backward': wrapBrowserViewCommand(backward),
|
|
7188
|
+
'ElectronWebContentsViewFunctions.cancelNavigation': wrapBrowserViewCommand(cancelNavigation),
|
|
7189
|
+
'ElectronWebContentsViewFunctions.copyImageAt': wrapBrowserViewCommand(copyImageAt),
|
|
7190
|
+
'ElectronWebContentsViewFunctions.focus': wrapBrowserViewCommand(focus),
|
|
7191
|
+
'ElectronWebContentsViewFunctions.forward': wrapBrowserViewCommand(forward),
|
|
7192
|
+
'ElectronWebContentsViewFunctions.getStats': wrapBrowserViewCommand(getStats$1),
|
|
7209
7193
|
'ElectronWebContentsViewFunctions.hide': hide,
|
|
7210
|
-
'ElectronWebContentsViewFunctions.inspectElement': inspectElement,
|
|
7211
|
-
'ElectronWebContentsViewFunctions.openDevtools': openDevtools,
|
|
7212
|
-
'ElectronWebContentsViewFunctions.reload': reload,
|
|
7213
|
-
'ElectronWebContentsViewFunctions.resizeBrowserView': resizeBrowserView,
|
|
7214
|
-
'ElectronWebContentsViewFunctions.setBackgroundColor': setBackgroundColor,
|
|
7215
|
-
'ElectronWebContentsViewFunctions.setFallthroughKeyBindings': setFallThroughKeyBindings,
|
|
7216
|
-
'ElectronWebContentsViewFunctions.setIframeSrc': setIframeSrc,
|
|
7217
|
-
'ElectronWebContentsViewFunctions.setIframeSrcFallback': setIframeSrcFallback,
|
|
7194
|
+
'ElectronWebContentsViewFunctions.inspectElement': wrapBrowserViewCommand(inspectElement),
|
|
7195
|
+
'ElectronWebContentsViewFunctions.openDevtools': wrapBrowserViewCommand(openDevtools),
|
|
7196
|
+
'ElectronWebContentsViewFunctions.reload': wrapBrowserViewCommand(wrapBrowserViewCommand(reload)),
|
|
7197
|
+
'ElectronWebContentsViewFunctions.resizeBrowserView': wrapBrowserViewCommand(resizeBrowserView),
|
|
7198
|
+
'ElectronWebContentsViewFunctions.setBackgroundColor': wrapBrowserViewCommand(setBackgroundColor),
|
|
7199
|
+
'ElectronWebContentsViewFunctions.setFallthroughKeyBindings': wrapBrowserViewCommand(setFallThroughKeyBindings),
|
|
7200
|
+
'ElectronWebContentsViewFunctions.setIframeSrc': wrapBrowserViewCommand(setIframeSrc),
|
|
7201
|
+
'ElectronWebContentsViewFunctions.setIframeSrcFallback': wrapBrowserViewCommand(setIframeSrcFallback),
|
|
7218
7202
|
'ElectronWebContentsViewFunctions.show': show,
|
|
7219
7203
|
'ElectronWindow.executeWebContentsFunction': executeWebContentsFunction,
|
|
7220
7204
|
'ElectronWindow.executeWindowFunction': executeWindowFunction,
|
|
@@ -7224,7 +7208,7 @@ const commandMap = {
|
|
|
7224
7208
|
'Exit.exit': exit,
|
|
7225
7209
|
'GetWindowId.getWindowId': getWindowId,
|
|
7226
7210
|
'HandleElectronMessagePort.handleElectronMessagePort': handleElectronMessagePort,
|
|
7227
|
-
'IpcParent.create': create$
|
|
7211
|
+
'IpcParent.create': create$1,
|
|
7228
7212
|
'OpenExternal.openExternal': openExternal,
|
|
7229
7213
|
'Process.getArgv': getArgv,
|
|
7230
7214
|
'Process.getChromeVersion': getChromeVersion,
|
|
@@ -7692,7 +7676,7 @@ const ElectronWindowProcessExplorer_ipc = {
|
|
|
7692
7676
|
|
|
7693
7677
|
const name$c = 'IpcParent';
|
|
7694
7678
|
const Commands$c = {
|
|
7695
|
-
create: create$
|
|
7679
|
+
create: create$1
|
|
7696
7680
|
};
|
|
7697
7681
|
|
|
7698
7682
|
const IpcParent_ipc = {
|