@lvce-editor/main-process 6.33.4 → 6.34.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 +151 -20
- package/package.json +2 -2
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
|
}
|
|
@@ -6742,7 +6742,7 @@ const attach = webContents => {
|
|
|
6742
6742
|
};
|
|
6743
6743
|
|
|
6744
6744
|
const send = (method, ...params) => {
|
|
6745
|
-
const rpc = get(EmbedsProcess);
|
|
6745
|
+
const rpc = get$1(EmbedsProcess);
|
|
6746
6746
|
if (!rpc) {
|
|
6747
6747
|
return;
|
|
6748
6748
|
}
|
|
@@ -6804,7 +6804,7 @@ const createWebContentsView = async () => {
|
|
|
6804
6804
|
const attachEventListeners = webContentsId => {
|
|
6805
6805
|
number(webContentsId);
|
|
6806
6806
|
const webContents = Electron.webContents.fromId(webContentsId);
|
|
6807
|
-
const state = get$
|
|
6807
|
+
const state = get$4(webContentsId);
|
|
6808
6808
|
if (!webContents || !state) {
|
|
6809
6809
|
return;
|
|
6810
6810
|
}
|
|
@@ -6813,7 +6813,7 @@ const attachEventListeners = webContentsId => {
|
|
|
6813
6813
|
const disposeWebContentsView = browserViewId => {
|
|
6814
6814
|
console.log('[main process] dispose browser view', browserViewId);
|
|
6815
6815
|
cancelForWebContents(browserViewId);
|
|
6816
|
-
const instance = get$
|
|
6816
|
+
const instance = get$4(browserViewId);
|
|
6817
6817
|
if (!instance) {
|
|
6818
6818
|
return;
|
|
6819
6819
|
}
|
|
@@ -6832,7 +6832,7 @@ const webContentsViewErrorPath = join(root, 'packages', 'main-process', 'pages',
|
|
|
6832
6832
|
|
|
6833
6833
|
const wrapBrowserViewCommand = fn => {
|
|
6834
6834
|
const wrappedCommand = (id, ...args) => {
|
|
6835
|
-
const state = get$
|
|
6835
|
+
const state = get$4(id);
|
|
6836
6836
|
if (!state) {
|
|
6837
6837
|
console.log(`[main process] no browser view with id ${id}`);
|
|
6838
6838
|
return;
|
|
@@ -6988,7 +6988,7 @@ const cancelNavigation = view => {
|
|
|
6988
6988
|
};
|
|
6989
6989
|
const show = id => {
|
|
6990
6990
|
// console.log('[main-process] show browser view', id)
|
|
6991
|
-
const state = get$
|
|
6991
|
+
const state = get$4(id);
|
|
6992
6992
|
if (!state) {
|
|
6993
6993
|
return;
|
|
6994
6994
|
}
|
|
@@ -6999,7 +6999,7 @@ const show = id => {
|
|
|
6999
6999
|
browserWindow.contentView.addChildView(view);
|
|
7000
7000
|
};
|
|
7001
7001
|
const addToWindow = (browserWindowId, browserViewId) => {
|
|
7002
|
-
const state = get$
|
|
7002
|
+
const state = get$4(browserViewId);
|
|
7003
7003
|
const {
|
|
7004
7004
|
view
|
|
7005
7005
|
} = state;
|
|
@@ -7010,7 +7010,7 @@ const addToWindow = (browserWindowId, browserViewId) => {
|
|
|
7010
7010
|
browserWindow.contentView.addChildView(view);
|
|
7011
7011
|
};
|
|
7012
7012
|
const hide = id => {
|
|
7013
|
-
const state = get$
|
|
7013
|
+
const state = get$4(id);
|
|
7014
7014
|
if (!state) {
|
|
7015
7015
|
return;
|
|
7016
7016
|
}
|
|
@@ -7185,7 +7185,7 @@ const open2 = async (options, url) => {
|
|
|
7185
7185
|
...options,
|
|
7186
7186
|
webPreferences: {
|
|
7187
7187
|
...options.webPreferences,
|
|
7188
|
-
session: get$
|
|
7188
|
+
session: get$2()
|
|
7189
7189
|
}
|
|
7190
7190
|
};
|
|
7191
7191
|
const processExplorerWindow = new BrowserWindow(allOptions);
|
|
@@ -7516,6 +7516,133 @@ const getMainProcessId = () => {
|
|
|
7516
7516
|
return process.pid;
|
|
7517
7517
|
};
|
|
7518
7518
|
|
|
7519
|
+
const storagePath = join(configDir, 'secrets.json');
|
|
7520
|
+
const pendingOperations = [];
|
|
7521
|
+
let isRunning = false;
|
|
7522
|
+
const runPendingOperations = async () => {
|
|
7523
|
+
if (isRunning) {
|
|
7524
|
+
return;
|
|
7525
|
+
}
|
|
7526
|
+
isRunning = true;
|
|
7527
|
+
let operation;
|
|
7528
|
+
while (operation = pendingOperations.shift()) {
|
|
7529
|
+
await operation();
|
|
7530
|
+
}
|
|
7531
|
+
isRunning = false;
|
|
7532
|
+
};
|
|
7533
|
+
const runExclusive = operation => {
|
|
7534
|
+
return new Promise((resolve, reject) => {
|
|
7535
|
+
pendingOperations.push(async () => {
|
|
7536
|
+
try {
|
|
7537
|
+
resolve(await operation());
|
|
7538
|
+
} catch (error) {
|
|
7539
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
7540
|
+
}
|
|
7541
|
+
});
|
|
7542
|
+
void runPendingOperations();
|
|
7543
|
+
});
|
|
7544
|
+
};
|
|
7545
|
+
const isRecord = value => {
|
|
7546
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
7547
|
+
};
|
|
7548
|
+
const normalizeStoredSecrets = value => {
|
|
7549
|
+
if (!isRecord(value)) {
|
|
7550
|
+
return {};
|
|
7551
|
+
}
|
|
7552
|
+
const storedSecrets = {};
|
|
7553
|
+
for (const [extensionId, extensionValue] of Object.entries(value)) {
|
|
7554
|
+
if (!isRecord(extensionValue)) {
|
|
7555
|
+
continue;
|
|
7556
|
+
}
|
|
7557
|
+
const extensionSecrets = {};
|
|
7558
|
+
for (const [key, encrypted] of Object.entries(extensionValue)) {
|
|
7559
|
+
if (typeof encrypted === 'string') {
|
|
7560
|
+
extensionSecrets[key] = encrypted;
|
|
7561
|
+
}
|
|
7562
|
+
}
|
|
7563
|
+
if (Object.keys(extensionSecrets).length > 0) {
|
|
7564
|
+
storedSecrets[extensionId] = extensionSecrets;
|
|
7565
|
+
}
|
|
7566
|
+
}
|
|
7567
|
+
return storedSecrets;
|
|
7568
|
+
};
|
|
7569
|
+
const readStoredSecrets = async () => {
|
|
7570
|
+
try {
|
|
7571
|
+
const content = await readFile(storagePath, 'utf8');
|
|
7572
|
+
return normalizeStoredSecrets(JSON.parse(content));
|
|
7573
|
+
} catch (error) {
|
|
7574
|
+
if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
|
|
7575
|
+
return {};
|
|
7576
|
+
}
|
|
7577
|
+
throw error;
|
|
7578
|
+
}
|
|
7579
|
+
};
|
|
7580
|
+
const writeStoredSecrets = async storedSecrets => {
|
|
7581
|
+
await mkdir(dirname(storagePath), {
|
|
7582
|
+
recursive: true
|
|
7583
|
+
});
|
|
7584
|
+
await writeFile(storagePath, `${JSON.stringify(storedSecrets, undefined, 2)}\n`, {
|
|
7585
|
+
encoding: 'utf8',
|
|
7586
|
+
mode: 0o600
|
|
7587
|
+
});
|
|
7588
|
+
};
|
|
7589
|
+
const deleteSecret = (extensionId, key) => {
|
|
7590
|
+
string(extensionId);
|
|
7591
|
+
string(key);
|
|
7592
|
+
return runExclusive(async () => {
|
|
7593
|
+
const storedSecrets = await readStoredSecrets();
|
|
7594
|
+
const extensionSecrets = storedSecrets[extensionId];
|
|
7595
|
+
if (!extensionSecrets || typeof extensionSecrets[key] !== 'string') {
|
|
7596
|
+
return;
|
|
7597
|
+
}
|
|
7598
|
+
const nextExtensionSecrets = {
|
|
7599
|
+
...extensionSecrets
|
|
7600
|
+
};
|
|
7601
|
+
delete nextExtensionSecrets[key];
|
|
7602
|
+
if (Object.keys(nextExtensionSecrets).length === 0) {
|
|
7603
|
+
delete storedSecrets[extensionId];
|
|
7604
|
+
} else {
|
|
7605
|
+
storedSecrets[extensionId] = nextExtensionSecrets;
|
|
7606
|
+
}
|
|
7607
|
+
await writeStoredSecrets(storedSecrets);
|
|
7608
|
+
});
|
|
7609
|
+
};
|
|
7610
|
+
const get = (extensionId, key) => {
|
|
7611
|
+
string(extensionId);
|
|
7612
|
+
string(key);
|
|
7613
|
+
return runExclusive(async () => {
|
|
7614
|
+
const storedSecrets = await readStoredSecrets();
|
|
7615
|
+
const encrypted = storedSecrets[extensionId]?.[key];
|
|
7616
|
+
if (typeof encrypted !== 'string') {
|
|
7617
|
+
return undefined;
|
|
7618
|
+
}
|
|
7619
|
+
return decrypt(encrypted);
|
|
7620
|
+
});
|
|
7621
|
+
};
|
|
7622
|
+
const list = () => {
|
|
7623
|
+
return runExclusive(async () => {
|
|
7624
|
+
const storedSecrets = await readStoredSecrets();
|
|
7625
|
+
return Object.entries(storedSecrets).flatMap(([extensionId, extensionSecrets]) => Object.keys(extensionSecrets).map(key => ({
|
|
7626
|
+
extensionId,
|
|
7627
|
+
key
|
|
7628
|
+
})));
|
|
7629
|
+
});
|
|
7630
|
+
};
|
|
7631
|
+
const store = (extensionId, key, value) => {
|
|
7632
|
+
string(extensionId);
|
|
7633
|
+
string(key);
|
|
7634
|
+
string(value);
|
|
7635
|
+
return runExclusive(async () => {
|
|
7636
|
+
const encrypted = encrypt(value);
|
|
7637
|
+
const storedSecrets = await readStoredSecrets();
|
|
7638
|
+
storedSecrets[extensionId] = {
|
|
7639
|
+
...storedSecrets[extensionId],
|
|
7640
|
+
[key]: encrypted
|
|
7641
|
+
};
|
|
7642
|
+
await writeStoredSecrets(storedSecrets);
|
|
7643
|
+
});
|
|
7644
|
+
};
|
|
7645
|
+
|
|
7519
7646
|
const {
|
|
7520
7647
|
create
|
|
7521
7648
|
} = IpcParentWithElectronUtilityProcess$1$1;
|
|
@@ -7574,7 +7701,7 @@ const sendTo = async (port, name, ipcId) => {
|
|
|
7574
7701
|
// TODO use rpc id, and then use rpc.invokeAndtransfer
|
|
7575
7702
|
const sendTo2 = async (port, targetRpcId, sourceRpcId) => {
|
|
7576
7703
|
object(port);
|
|
7577
|
-
const rpc = get(targetRpcId);
|
|
7704
|
+
const rpc = get$1(targetRpcId);
|
|
7578
7705
|
if (!rpc) {
|
|
7579
7706
|
throw new Error(`rpc ${targetRpcId} not found`);
|
|
7580
7707
|
}
|
|
@@ -7688,6 +7815,10 @@ const commandMap = {
|
|
|
7688
7815
|
'Process.writeStderr': writeStderr,
|
|
7689
7816
|
'Process.writeStdout': writeStdout,
|
|
7690
7817
|
'ProcessId.getMainProcessId': getMainProcessId,
|
|
7818
|
+
'SecretStorage.delete': deleteSecret,
|
|
7819
|
+
'SecretStorage.get': get,
|
|
7820
|
+
'SecretStorage.list': list,
|
|
7821
|
+
'SecretStorage.store': store,
|
|
7691
7822
|
'TemporaryMessagePort.createPortTuple': createPortTuple,
|
|
7692
7823
|
'TemporaryMessagePort.dispose': dispose,
|
|
7693
7824
|
'TemporaryMessagePort.sendTo': sendTo,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/main-process",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.34.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"lvce-editor",
|
|
6
6
|
"electron"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"type": "module",
|
|
15
15
|
"main": "dist/mainProcessMain.js",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"electron": "
|
|
17
|
+
"electron": "44.0.0"
|
|
18
18
|
},
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=22"
|