@lvce-editor/main-process 6.33.5 → 6.35.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 +154 -24
- package/package.json +1 -1
package/dist/mainProcessMain.js
CHANGED
|
@@ -9,7 +9,7 @@ import { mkdirSync, createWriteStream, readFileSync, openAsBlob, existsSync, wri
|
|
|
9
9
|
import * as NodePath from 'node:path';
|
|
10
10
|
import { dirname as dirname$1, join as join$1, isAbsolute } from 'node:path';
|
|
11
11
|
import { homedir, tmpdir } from 'node:os';
|
|
12
|
-
import { readFile } from 'node:fs/promises';
|
|
12
|
+
import { readFile, mkdir, writeFile } from 'node:fs/promises';
|
|
13
13
|
import { MessageChannel } from 'node:worker_threads';
|
|
14
14
|
import { DatabaseSync } from 'node:sqlite';
|
|
15
15
|
|
|
@@ -2823,7 +2823,7 @@ const callbacks = Object.create(null);
|
|
|
2823
2823
|
const set$2 = (id, fn) => {
|
|
2824
2824
|
callbacks[id] = fn;
|
|
2825
2825
|
};
|
|
2826
|
-
const get$
|
|
2826
|
+
const get$5 = id => {
|
|
2827
2827
|
return callbacks[id];
|
|
2828
2828
|
};
|
|
2829
2829
|
const remove$2 = id => {
|
|
@@ -3047,7 +3047,7 @@ const warn = (...args) => {
|
|
|
3047
3047
|
console.warn(...args);
|
|
3048
3048
|
};
|
|
3049
3049
|
const resolve = (id, response) => {
|
|
3050
|
-
const fn = get$
|
|
3050
|
+
const fn = get$5(id);
|
|
3051
3051
|
if (!fn) {
|
|
3052
3052
|
console.log(response);
|
|
3053
3053
|
warn(`callback ${id} may already be disposed`);
|
|
@@ -4118,7 +4118,7 @@ const hasWebContents = id => {
|
|
|
4118
4118
|
* @param {number} id
|
|
4119
4119
|
* @returns {{browserWindow: Electron.BrowserWindow, view: Electron.WebContentsView}}
|
|
4120
4120
|
*/
|
|
4121
|
-
const get$
|
|
4121
|
+
const get$4 = id => {
|
|
4122
4122
|
return state$2.views[id];
|
|
4123
4123
|
};
|
|
4124
4124
|
const getAll = () => {
|
|
@@ -4906,7 +4906,7 @@ const state$1 = {
|
|
|
4906
4906
|
const has = () => {
|
|
4907
4907
|
return Boolean(state$1.session);
|
|
4908
4908
|
};
|
|
4909
|
-
const get$
|
|
4909
|
+
const get$3 = () => {
|
|
4910
4910
|
if (!state$1.session) {
|
|
4911
4911
|
throw new Error('session is not defined');
|
|
4912
4912
|
}
|
|
@@ -4931,11 +4931,11 @@ const create$2 = rpc => {
|
|
|
4931
4931
|
return handleRequest;
|
|
4932
4932
|
};
|
|
4933
4933
|
|
|
4934
|
-
const get$
|
|
4934
|
+
const get$2 = () => {
|
|
4935
4935
|
if (!has()) {
|
|
4936
4936
|
set$1(createElectronSession());
|
|
4937
4937
|
}
|
|
4938
|
-
return get$
|
|
4938
|
+
return get$3();
|
|
4939
4939
|
};
|
|
4940
4940
|
const registerWebviewProtocol = async port => {
|
|
4941
4941
|
object(port);
|
|
@@ -4944,7 +4944,7 @@ const registerWebviewProtocol = async port => {
|
|
|
4944
4944
|
messagePort: port,
|
|
4945
4945
|
requiresSocket: requiresSocket
|
|
4946
4946
|
});
|
|
4947
|
-
const session = get$
|
|
4947
|
+
const session = get$2();
|
|
4948
4948
|
const handleRequest = create$2(rpc);
|
|
4949
4949
|
handle(session.protocol, WebView, handleRequest);
|
|
4950
4950
|
};
|
|
@@ -5032,7 +5032,7 @@ const addDevDiagnostics = window => {
|
|
|
5032
5032
|
|
|
5033
5033
|
// TODO avoid mixing BrowserWindow, childprocess and various lifecycle methods in one file -> separate concerns
|
|
5034
5034
|
const createAppWindow = async (windowOptions, parsedArgs, workingDirectory, titleBarItems, url) => {
|
|
5035
|
-
const session = get$
|
|
5035
|
+
const session = get$2();
|
|
5036
5036
|
mark(WillCreateCodeWindow);
|
|
5037
5037
|
const window = new BrowserWindow({
|
|
5038
5038
|
...windowOptions,
|
|
@@ -5219,7 +5219,7 @@ const rpcs = Object.create(null);
|
|
|
5219
5219
|
const set = (id, rpc) => {
|
|
5220
5220
|
rpcs[id] = rpc;
|
|
5221
5221
|
};
|
|
5222
|
-
const get = id => {
|
|
5222
|
+
const get$1 = id => {
|
|
5223
5223
|
return rpcs[id];
|
|
5224
5224
|
};
|
|
5225
5225
|
|
|
@@ -6240,7 +6240,7 @@ const handleWebContentsViewZoomKeyBinding = (webContentsId, input) => {
|
|
|
6240
6240
|
if (delta === 0) {
|
|
6241
6241
|
return false;
|
|
6242
6242
|
}
|
|
6243
|
-
const state = get$
|
|
6243
|
+
const state = get$4(webContentsId);
|
|
6244
6244
|
if (!state) {
|
|
6245
6245
|
return false;
|
|
6246
6246
|
}
|
|
@@ -6505,13 +6505,12 @@ const detach = (webContents, listener) => {
|
|
|
6505
6505
|
webContents.setWindowOpenHandler(null);
|
|
6506
6506
|
};
|
|
6507
6507
|
const handler = ({
|
|
6508
|
+
disposition,
|
|
6508
6509
|
url
|
|
6509
6510
|
}) => {
|
|
6510
|
-
|
|
6511
|
-
void openExternal(url);
|
|
6512
|
-
}
|
|
6511
|
+
const messages = shouldOpenExternal(url) ? [['handleWindowOpen', url, disposition]] : [];
|
|
6513
6512
|
return {
|
|
6514
|
-
messages
|
|
6513
|
+
messages,
|
|
6515
6514
|
result: {
|
|
6516
6515
|
action: Deny
|
|
6517
6516
|
}
|
|
@@ -6742,7 +6741,7 @@ const attach = webContents => {
|
|
|
6742
6741
|
};
|
|
6743
6742
|
|
|
6744
6743
|
const send = (method, ...params) => {
|
|
6745
|
-
const rpc = get(EmbedsProcess);
|
|
6744
|
+
const rpc = get$1(EmbedsProcess);
|
|
6746
6745
|
if (!rpc) {
|
|
6747
6746
|
return;
|
|
6748
6747
|
}
|
|
@@ -6804,7 +6803,7 @@ const createWebContentsView = async () => {
|
|
|
6804
6803
|
const attachEventListeners = webContentsId => {
|
|
6805
6804
|
number(webContentsId);
|
|
6806
6805
|
const webContents = Electron.webContents.fromId(webContentsId);
|
|
6807
|
-
const state = get$
|
|
6806
|
+
const state = get$4(webContentsId);
|
|
6808
6807
|
if (!webContents || !state) {
|
|
6809
6808
|
return;
|
|
6810
6809
|
}
|
|
@@ -6813,7 +6812,7 @@ const attachEventListeners = webContentsId => {
|
|
|
6813
6812
|
const disposeWebContentsView = browserViewId => {
|
|
6814
6813
|
console.log('[main process] dispose browser view', browserViewId);
|
|
6815
6814
|
cancelForWebContents(browserViewId);
|
|
6816
|
-
const instance = get$
|
|
6815
|
+
const instance = get$4(browserViewId);
|
|
6817
6816
|
if (!instance) {
|
|
6818
6817
|
return;
|
|
6819
6818
|
}
|
|
@@ -6832,7 +6831,7 @@ const webContentsViewErrorPath = join(root, 'packages', 'main-process', 'pages',
|
|
|
6832
6831
|
|
|
6833
6832
|
const wrapBrowserViewCommand = fn => {
|
|
6834
6833
|
const wrappedCommand = (id, ...args) => {
|
|
6835
|
-
const state = get$
|
|
6834
|
+
const state = get$4(id);
|
|
6836
6835
|
if (!state) {
|
|
6837
6836
|
console.log(`[main process] no browser view with id ${id}`);
|
|
6838
6837
|
return;
|
|
@@ -6988,7 +6987,7 @@ const cancelNavigation = view => {
|
|
|
6988
6987
|
};
|
|
6989
6988
|
const show = id => {
|
|
6990
6989
|
// console.log('[main-process] show browser view', id)
|
|
6991
|
-
const state = get$
|
|
6990
|
+
const state = get$4(id);
|
|
6992
6991
|
if (!state) {
|
|
6993
6992
|
return;
|
|
6994
6993
|
}
|
|
@@ -6999,7 +6998,7 @@ const show = id => {
|
|
|
6999
6998
|
browserWindow.contentView.addChildView(view);
|
|
7000
6999
|
};
|
|
7001
7000
|
const addToWindow = (browserWindowId, browserViewId) => {
|
|
7002
|
-
const state = get$
|
|
7001
|
+
const state = get$4(browserViewId);
|
|
7003
7002
|
const {
|
|
7004
7003
|
view
|
|
7005
7004
|
} = state;
|
|
@@ -7010,7 +7009,7 @@ const addToWindow = (browserWindowId, browserViewId) => {
|
|
|
7010
7009
|
browserWindow.contentView.addChildView(view);
|
|
7011
7010
|
};
|
|
7012
7011
|
const hide = id => {
|
|
7013
|
-
const state = get$
|
|
7012
|
+
const state = get$4(id);
|
|
7014
7013
|
if (!state) {
|
|
7015
7014
|
return;
|
|
7016
7015
|
}
|
|
@@ -7185,7 +7184,7 @@ const open2 = async (options, url) => {
|
|
|
7185
7184
|
...options,
|
|
7186
7185
|
webPreferences: {
|
|
7187
7186
|
...options.webPreferences,
|
|
7188
|
-
session: get$
|
|
7187
|
+
session: get$2()
|
|
7189
7188
|
}
|
|
7190
7189
|
};
|
|
7191
7190
|
const processExplorerWindow = new BrowserWindow(allOptions);
|
|
@@ -7516,6 +7515,133 @@ const getMainProcessId = () => {
|
|
|
7516
7515
|
return process.pid;
|
|
7517
7516
|
};
|
|
7518
7517
|
|
|
7518
|
+
const storagePath = join(configDir, 'secrets.json');
|
|
7519
|
+
const pendingOperations = [];
|
|
7520
|
+
let isRunning = false;
|
|
7521
|
+
const runPendingOperations = async () => {
|
|
7522
|
+
if (isRunning) {
|
|
7523
|
+
return;
|
|
7524
|
+
}
|
|
7525
|
+
isRunning = true;
|
|
7526
|
+
let operation;
|
|
7527
|
+
while (operation = pendingOperations.shift()) {
|
|
7528
|
+
await operation();
|
|
7529
|
+
}
|
|
7530
|
+
isRunning = false;
|
|
7531
|
+
};
|
|
7532
|
+
const runExclusive = operation => {
|
|
7533
|
+
return new Promise((resolve, reject) => {
|
|
7534
|
+
pendingOperations.push(async () => {
|
|
7535
|
+
try {
|
|
7536
|
+
resolve(await operation());
|
|
7537
|
+
} catch (error) {
|
|
7538
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
7539
|
+
}
|
|
7540
|
+
});
|
|
7541
|
+
void runPendingOperations();
|
|
7542
|
+
});
|
|
7543
|
+
};
|
|
7544
|
+
const isRecord = value => {
|
|
7545
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
7546
|
+
};
|
|
7547
|
+
const normalizeStoredSecrets = value => {
|
|
7548
|
+
if (!isRecord(value)) {
|
|
7549
|
+
return {};
|
|
7550
|
+
}
|
|
7551
|
+
const storedSecrets = {};
|
|
7552
|
+
for (const [extensionId, extensionValue] of Object.entries(value)) {
|
|
7553
|
+
if (!isRecord(extensionValue)) {
|
|
7554
|
+
continue;
|
|
7555
|
+
}
|
|
7556
|
+
const extensionSecrets = {};
|
|
7557
|
+
for (const [key, encrypted] of Object.entries(extensionValue)) {
|
|
7558
|
+
if (typeof encrypted === 'string') {
|
|
7559
|
+
extensionSecrets[key] = encrypted;
|
|
7560
|
+
}
|
|
7561
|
+
}
|
|
7562
|
+
if (Object.keys(extensionSecrets).length > 0) {
|
|
7563
|
+
storedSecrets[extensionId] = extensionSecrets;
|
|
7564
|
+
}
|
|
7565
|
+
}
|
|
7566
|
+
return storedSecrets;
|
|
7567
|
+
};
|
|
7568
|
+
const readStoredSecrets = async () => {
|
|
7569
|
+
try {
|
|
7570
|
+
const content = await readFile(storagePath, 'utf8');
|
|
7571
|
+
return normalizeStoredSecrets(JSON.parse(content));
|
|
7572
|
+
} catch (error) {
|
|
7573
|
+
if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
|
|
7574
|
+
return {};
|
|
7575
|
+
}
|
|
7576
|
+
throw error;
|
|
7577
|
+
}
|
|
7578
|
+
};
|
|
7579
|
+
const writeStoredSecrets = async storedSecrets => {
|
|
7580
|
+
await mkdir(dirname(storagePath), {
|
|
7581
|
+
recursive: true
|
|
7582
|
+
});
|
|
7583
|
+
await writeFile(storagePath, `${JSON.stringify(storedSecrets, undefined, 2)}\n`, {
|
|
7584
|
+
encoding: 'utf8',
|
|
7585
|
+
mode: 0o600
|
|
7586
|
+
});
|
|
7587
|
+
};
|
|
7588
|
+
const deleteSecret = (extensionId, key) => {
|
|
7589
|
+
string(extensionId);
|
|
7590
|
+
string(key);
|
|
7591
|
+
return runExclusive(async () => {
|
|
7592
|
+
const storedSecrets = await readStoredSecrets();
|
|
7593
|
+
const extensionSecrets = storedSecrets[extensionId];
|
|
7594
|
+
if (!extensionSecrets || typeof extensionSecrets[key] !== 'string') {
|
|
7595
|
+
return;
|
|
7596
|
+
}
|
|
7597
|
+
const nextExtensionSecrets = {
|
|
7598
|
+
...extensionSecrets
|
|
7599
|
+
};
|
|
7600
|
+
delete nextExtensionSecrets[key];
|
|
7601
|
+
if (Object.keys(nextExtensionSecrets).length === 0) {
|
|
7602
|
+
delete storedSecrets[extensionId];
|
|
7603
|
+
} else {
|
|
7604
|
+
storedSecrets[extensionId] = nextExtensionSecrets;
|
|
7605
|
+
}
|
|
7606
|
+
await writeStoredSecrets(storedSecrets);
|
|
7607
|
+
});
|
|
7608
|
+
};
|
|
7609
|
+
const get = (extensionId, key) => {
|
|
7610
|
+
string(extensionId);
|
|
7611
|
+
string(key);
|
|
7612
|
+
return runExclusive(async () => {
|
|
7613
|
+
const storedSecrets = await readStoredSecrets();
|
|
7614
|
+
const encrypted = storedSecrets[extensionId]?.[key];
|
|
7615
|
+
if (typeof encrypted !== 'string') {
|
|
7616
|
+
return undefined;
|
|
7617
|
+
}
|
|
7618
|
+
return decrypt(encrypted);
|
|
7619
|
+
});
|
|
7620
|
+
};
|
|
7621
|
+
const list = () => {
|
|
7622
|
+
return runExclusive(async () => {
|
|
7623
|
+
const storedSecrets = await readStoredSecrets();
|
|
7624
|
+
return Object.entries(storedSecrets).flatMap(([extensionId, extensionSecrets]) => Object.keys(extensionSecrets).map(key => ({
|
|
7625
|
+
extensionId,
|
|
7626
|
+
key
|
|
7627
|
+
})));
|
|
7628
|
+
});
|
|
7629
|
+
};
|
|
7630
|
+
const store = (extensionId, key, value) => {
|
|
7631
|
+
string(extensionId);
|
|
7632
|
+
string(key);
|
|
7633
|
+
string(value);
|
|
7634
|
+
return runExclusive(async () => {
|
|
7635
|
+
const encrypted = encrypt(value);
|
|
7636
|
+
const storedSecrets = await readStoredSecrets();
|
|
7637
|
+
storedSecrets[extensionId] = {
|
|
7638
|
+
...storedSecrets[extensionId],
|
|
7639
|
+
[key]: encrypted
|
|
7640
|
+
};
|
|
7641
|
+
await writeStoredSecrets(storedSecrets);
|
|
7642
|
+
});
|
|
7643
|
+
};
|
|
7644
|
+
|
|
7519
7645
|
const {
|
|
7520
7646
|
create
|
|
7521
7647
|
} = IpcParentWithElectronUtilityProcess$1$1;
|
|
@@ -7574,7 +7700,7 @@ const sendTo = async (port, name, ipcId) => {
|
|
|
7574
7700
|
// TODO use rpc id, and then use rpc.invokeAndtransfer
|
|
7575
7701
|
const sendTo2 = async (port, targetRpcId, sourceRpcId) => {
|
|
7576
7702
|
object(port);
|
|
7577
|
-
const rpc = get(targetRpcId);
|
|
7703
|
+
const rpc = get$1(targetRpcId);
|
|
7578
7704
|
if (!rpc) {
|
|
7579
7705
|
throw new Error(`rpc ${targetRpcId} not found`);
|
|
7580
7706
|
}
|
|
@@ -7688,6 +7814,10 @@ const commandMap = {
|
|
|
7688
7814
|
'Process.writeStderr': writeStderr,
|
|
7689
7815
|
'Process.writeStdout': writeStdout,
|
|
7690
7816
|
'ProcessId.getMainProcessId': getMainProcessId,
|
|
7817
|
+
'SecretStorage.delete': deleteSecret,
|
|
7818
|
+
'SecretStorage.get': get,
|
|
7819
|
+
'SecretStorage.list': list,
|
|
7820
|
+
'SecretStorage.store': store,
|
|
7691
7821
|
'TemporaryMessagePort.createPortTuple': createPortTuple,
|
|
7692
7822
|
'TemporaryMessagePort.dispose': dispose,
|
|
7693
7823
|
'TemporaryMessagePort.sendTo': sendTo,
|