@lvce-editor/main-process 6.27.1 → 6.28.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 +84 -58
- package/package.json +1 -1
package/dist/mainProcessMain.js
CHANGED
|
@@ -7,7 +7,7 @@ import { spawn } from 'node:child_process';
|
|
|
7
7
|
import { Console } from 'node:console';
|
|
8
8
|
import { mkdirSync, createWriteStream, readFileSync, openAsBlob, existsSync, writeFileSync, rmSync, openSync, writeSync, closeSync } from 'node:fs';
|
|
9
9
|
import * as NodePath from 'node:path';
|
|
10
|
-
import { dirname, join as join$1, isAbsolute } from 'node:path';
|
|
10
|
+
import { dirname as dirname$1, join as join$1, isAbsolute } from 'node:path';
|
|
11
11
|
import { homedir, tmpdir } from 'node:os';
|
|
12
12
|
import { readFile } from 'node:fs/promises';
|
|
13
13
|
import { pbkdf2Sync, createDecipheriv, createHash } from 'node:crypto';
|
|
@@ -784,8 +784,11 @@ const getNewLineIndex$2 = (string, startIndex = undefined) => {
|
|
|
784
784
|
const join = (...paths) => {
|
|
785
785
|
return NodePath.join(...paths);
|
|
786
786
|
};
|
|
787
|
+
const dirname = path => {
|
|
788
|
+
return NodePath.dirname(path);
|
|
789
|
+
};
|
|
787
790
|
|
|
788
|
-
const __dirname$1 = dirname(fileURLToPath(import.meta.url));
|
|
791
|
+
const __dirname$1 = dirname$1(fileURLToPath(import.meta.url));
|
|
789
792
|
const root = process.env.LVCE_ROOT || join(__dirname$1, '../../../../..');
|
|
790
793
|
|
|
791
794
|
const {
|
|
@@ -819,58 +822,62 @@ const getSharedProcessPath = () => {
|
|
|
819
822
|
};
|
|
820
823
|
|
|
821
824
|
const createFileLogger = fileName => {
|
|
822
|
-
|
|
825
|
+
const logFile = join(logsDir, fileName);
|
|
826
|
+
mkdirSync(dirname(logFile), {
|
|
823
827
|
recursive: true
|
|
824
828
|
});
|
|
825
|
-
const logFile = join(logsDir, fileName);
|
|
826
829
|
const writeStream = createWriteStream(logFile);
|
|
827
|
-
|
|
830
|
+
const logger = new Console(writeStream);
|
|
831
|
+
logger.dispose = () => {
|
|
832
|
+
writeStream.end();
|
|
833
|
+
};
|
|
834
|
+
return logger;
|
|
828
835
|
};
|
|
829
836
|
|
|
830
837
|
// TODO disable logging via environment variable, don't enable logging during tests
|
|
831
838
|
|
|
832
|
-
const state$
|
|
839
|
+
const state$6 = {
|
|
833
840
|
console: undefined
|
|
834
841
|
};
|
|
835
842
|
const createConsole = () => {
|
|
836
843
|
return createFileLogger('log-main-process.txt');
|
|
837
844
|
};
|
|
838
|
-
const getOrCreateLogger
|
|
839
|
-
state$
|
|
840
|
-
return state$
|
|
845
|
+
const getOrCreateLogger = () => {
|
|
846
|
+
state$6.console ||= createConsole();
|
|
847
|
+
return state$6.console;
|
|
841
848
|
};
|
|
842
849
|
const info = (...args) => {
|
|
843
|
-
const logger = getOrCreateLogger
|
|
850
|
+
const logger = getOrCreateLogger();
|
|
844
851
|
logger.info(...args);
|
|
845
852
|
console.info(...args);
|
|
846
853
|
};
|
|
847
854
|
const error = (...args) => {
|
|
848
|
-
const logger = getOrCreateLogger
|
|
855
|
+
const logger = getOrCreateLogger();
|
|
849
856
|
logger.error(...args);
|
|
850
857
|
console.error(...args);
|
|
851
858
|
};
|
|
852
859
|
process.stdout.on('close', () => {
|
|
853
|
-
const logger = getOrCreateLogger
|
|
860
|
+
const logger = getOrCreateLogger();
|
|
854
861
|
logger.info('stdout closed');
|
|
855
862
|
});
|
|
856
863
|
process.stdout.on('exit', () => {
|
|
857
|
-
const logger = getOrCreateLogger
|
|
864
|
+
const logger = getOrCreateLogger();
|
|
858
865
|
logger.info('stdout exited');
|
|
859
866
|
});
|
|
860
867
|
process.stderr.on('close', () => {
|
|
861
|
-
const logger = getOrCreateLogger
|
|
868
|
+
const logger = getOrCreateLogger();
|
|
862
869
|
logger.info('stderr closed');
|
|
863
870
|
});
|
|
864
871
|
process.stderr.on('exit', () => {
|
|
865
|
-
const logger = getOrCreateLogger
|
|
872
|
+
const logger = getOrCreateLogger();
|
|
866
873
|
logger.info('stderr exited');
|
|
867
874
|
});
|
|
868
875
|
process.stdout.on('error', error => {
|
|
869
|
-
const logger = getOrCreateLogger
|
|
876
|
+
const logger = getOrCreateLogger();
|
|
870
877
|
logger.error(`[main-process] stdout error: ${error.stack}`);
|
|
871
878
|
});
|
|
872
879
|
process.stderr.on('error', error => {
|
|
873
|
-
const logger = getOrCreateLogger
|
|
880
|
+
const logger = getOrCreateLogger();
|
|
874
881
|
logger.error(`[main-process] stderr error: ${error.stack}`);
|
|
875
882
|
});
|
|
876
883
|
|
|
@@ -3428,27 +3435,27 @@ const formatUtilityProcessName = name => {
|
|
|
3428
3435
|
return camelCase(name);
|
|
3429
3436
|
};
|
|
3430
3437
|
|
|
3431
|
-
const state$
|
|
3438
|
+
const state$5 = {
|
|
3432
3439
|
all: Object.create(null)
|
|
3433
3440
|
};
|
|
3434
3441
|
const add$2 = (pid, process, name) => {
|
|
3435
3442
|
number(pid);
|
|
3436
3443
|
object(process);
|
|
3437
3444
|
string(name);
|
|
3438
|
-
state$
|
|
3445
|
+
state$5.all[pid] = {
|
|
3439
3446
|
name,
|
|
3440
3447
|
process
|
|
3441
3448
|
};
|
|
3442
3449
|
};
|
|
3443
3450
|
const remove$1 = pid => {
|
|
3444
3451
|
number(pid);
|
|
3445
|
-
delete state$
|
|
3452
|
+
delete state$5.all[pid];
|
|
3446
3453
|
};
|
|
3447
3454
|
const getAll = () => {
|
|
3448
|
-
return Object.entries(state$
|
|
3455
|
+
return Object.entries(state$5.all);
|
|
3449
3456
|
};
|
|
3450
3457
|
const getByName = name => {
|
|
3451
|
-
for (const value of Object.values(state$
|
|
3458
|
+
for (const value of Object.values(state$5.all)) {
|
|
3452
3459
|
// @ts-ignore
|
|
3453
3460
|
if (value.name === name) {
|
|
3454
3461
|
// @ts-ignore
|
|
@@ -3605,7 +3612,7 @@ const launchSharedProcess = async ({
|
|
|
3605
3612
|
return sharedProcessRpc;
|
|
3606
3613
|
};
|
|
3607
3614
|
|
|
3608
|
-
const state$
|
|
3615
|
+
const state$4 = {
|
|
3609
3616
|
/**
|
|
3610
3617
|
* @type {any}
|
|
3611
3618
|
*/
|
|
@@ -3616,14 +3623,14 @@ const getOrCreate = async ({
|
|
|
3616
3623
|
env = {},
|
|
3617
3624
|
method
|
|
3618
3625
|
}) => {
|
|
3619
|
-
if (!state$
|
|
3626
|
+
if (!state$4.promise) {
|
|
3620
3627
|
// @ts-ignore
|
|
3621
|
-
state$
|
|
3628
|
+
state$4.promise = launchSharedProcess({
|
|
3622
3629
|
env,
|
|
3623
3630
|
method
|
|
3624
3631
|
});
|
|
3625
3632
|
}
|
|
3626
|
-
return state$
|
|
3633
|
+
return state$4.promise;
|
|
3627
3634
|
};
|
|
3628
3635
|
const send$1 = async (method, ...params) => {
|
|
3629
3636
|
const rpc = await getOrCreate({
|
|
@@ -3788,14 +3795,14 @@ const createTitleBar = items => {
|
|
|
3788
3795
|
|
|
3789
3796
|
const PHASE_DEFAULT = 0;
|
|
3790
3797
|
const PHASE_SHUTDOWN = -1;
|
|
3791
|
-
const state$
|
|
3798
|
+
const state$3 = {
|
|
3792
3799
|
phase: PHASE_DEFAULT
|
|
3793
3800
|
};
|
|
3794
3801
|
const isShutDown = () => {
|
|
3795
|
-
return state$
|
|
3802
|
+
return state$3.phase === PHASE_SHUTDOWN;
|
|
3796
3803
|
};
|
|
3797
3804
|
const setShutDown = () => {
|
|
3798
|
-
state$
|
|
3805
|
+
state$3.phase = PHASE_SHUTDOWN;
|
|
3799
3806
|
};
|
|
3800
3807
|
|
|
3801
3808
|
// TODO move this function to shared process
|
|
@@ -4094,21 +4101,21 @@ const openExternal = async url => {
|
|
|
4094
4101
|
await shell.openExternal(url);
|
|
4095
4102
|
};
|
|
4096
4103
|
|
|
4097
|
-
const state$
|
|
4104
|
+
const state$2 = {
|
|
4098
4105
|
canceled: Object.create(null),
|
|
4099
4106
|
fallThroughKeyBindings: [],
|
|
4100
4107
|
views: Object.create(null)
|
|
4101
4108
|
};
|
|
4102
4109
|
const add$1 = (id, browserWindow, view) => {
|
|
4103
4110
|
// state
|
|
4104
|
-
state$
|
|
4111
|
+
state$2.views[id] = {
|
|
4105
4112
|
browserWindow,
|
|
4106
4113
|
view
|
|
4107
4114
|
};
|
|
4108
4115
|
};
|
|
4109
4116
|
const hasWebContents = id => {
|
|
4110
4117
|
number(id);
|
|
4111
|
-
return id in state$
|
|
4118
|
+
return id in state$2.views;
|
|
4112
4119
|
};
|
|
4113
4120
|
/**
|
|
4114
4121
|
*
|
|
@@ -4116,19 +4123,19 @@ const hasWebContents = id => {
|
|
|
4116
4123
|
* @returns {{browserWindow: Electron.BrowserWindow, view: Electron.WebContentsView}}
|
|
4117
4124
|
*/
|
|
4118
4125
|
const get$3 = id => {
|
|
4119
|
-
return state$
|
|
4126
|
+
return state$2.views[id];
|
|
4120
4127
|
};
|
|
4121
4128
|
const remove = id => {
|
|
4122
|
-
delete state$
|
|
4129
|
+
delete state$2.views[id];
|
|
4123
4130
|
};
|
|
4124
4131
|
const setFallthroughKeyBindings = fallthroughKeyBindings => {
|
|
4125
|
-
state$
|
|
4132
|
+
state$2.fallThroughKeyBindings = fallthroughKeyBindings;
|
|
4126
4133
|
};
|
|
4127
4134
|
const getFallthroughKeyBindings = () => {
|
|
4128
|
-
return state$
|
|
4135
|
+
return state$2.fallThroughKeyBindings;
|
|
4129
4136
|
};
|
|
4130
4137
|
const setCanceled = id => {
|
|
4131
|
-
state$
|
|
4138
|
+
state$2.canceled[id] = true;
|
|
4132
4139
|
};
|
|
4133
4140
|
|
|
4134
4141
|
const shouldAllowNavigation = webContentsId => {
|
|
@@ -4660,6 +4667,33 @@ const load = async (path, env = process.env) => {
|
|
|
4660
4667
|
}
|
|
4661
4668
|
};
|
|
4662
4669
|
|
|
4670
|
+
const createWindowCloseHandler = (window, rpc, onError, dispose = () => {}) => {
|
|
4671
|
+
let closePending = false;
|
|
4672
|
+
const handleWindowClose = event => {
|
|
4673
|
+
event.preventDefault();
|
|
4674
|
+
if (closePending) {
|
|
4675
|
+
return;
|
|
4676
|
+
}
|
|
4677
|
+
closePending = true;
|
|
4678
|
+
void (async () => {
|
|
4679
|
+
try {
|
|
4680
|
+
await rpc.invoke('Window.prepareClose');
|
|
4681
|
+
} catch (error) {
|
|
4682
|
+
onError(error);
|
|
4683
|
+
} finally {
|
|
4684
|
+
try {
|
|
4685
|
+
dispose();
|
|
4686
|
+
} catch (error) {
|
|
4687
|
+
onError(error);
|
|
4688
|
+
}
|
|
4689
|
+
window.off('close', handleWindowClose);
|
|
4690
|
+
window.close();
|
|
4691
|
+
}
|
|
4692
|
+
})();
|
|
4693
|
+
};
|
|
4694
|
+
return handleWindowClose;
|
|
4695
|
+
};
|
|
4696
|
+
|
|
4663
4697
|
const accessControlAllowOrigin = 'access-control-allow-origin';
|
|
4664
4698
|
const getCorsResponseHeaders = (responseHeaders = {}) => {
|
|
4665
4699
|
const hasAccessControlAllowOrigin = Object.keys(responseHeaders).some(key => key.toLowerCase() === accessControlAllowOrigin);
|
|
@@ -4831,20 +4865,20 @@ const createElectronSession = () => {
|
|
|
4831
4865
|
return session;
|
|
4832
4866
|
};
|
|
4833
4867
|
|
|
4834
|
-
const state$
|
|
4868
|
+
const state$1 = {
|
|
4835
4869
|
session: undefined
|
|
4836
4870
|
};
|
|
4837
4871
|
const has = () => {
|
|
4838
|
-
return Boolean(state$
|
|
4872
|
+
return Boolean(state$1.session);
|
|
4839
4873
|
};
|
|
4840
4874
|
const get$2 = () => {
|
|
4841
|
-
if (!state$
|
|
4875
|
+
if (!state$1.session) {
|
|
4842
4876
|
throw new Error('session is not defined');
|
|
4843
4877
|
}
|
|
4844
|
-
return state$
|
|
4878
|
+
return state$1.session;
|
|
4845
4879
|
};
|
|
4846
4880
|
const set$1 = value => {
|
|
4847
|
-
state$
|
|
4881
|
+
state$1.session = value;
|
|
4848
4882
|
};
|
|
4849
4883
|
|
|
4850
4884
|
const create$2 = rpc => {
|
|
@@ -4902,12 +4936,8 @@ class WindowLoadError extends VError {
|
|
|
4902
4936
|
}
|
|
4903
4937
|
}
|
|
4904
4938
|
|
|
4905
|
-
const
|
|
4906
|
-
|
|
4907
|
-
};
|
|
4908
|
-
const getOrCreateLogger = () => {
|
|
4909
|
-
state$1.console ||= createFileLogger('log-window.txt');
|
|
4910
|
-
return state$1.console;
|
|
4939
|
+
const getLogFileName = (windowId, now = Date.now()) => {
|
|
4940
|
+
return `${windowId}/${now}.txt`;
|
|
4911
4941
|
};
|
|
4912
4942
|
const formatMessage = ({
|
|
4913
4943
|
level,
|
|
@@ -4924,10 +4954,13 @@ const formatMessage = ({
|
|
|
4924
4954
|
timestamp: new Date().toISOString()
|
|
4925
4955
|
});
|
|
4926
4956
|
};
|
|
4927
|
-
const addListener = (webContents, logger =
|
|
4957
|
+
const addListener = (windowId, webContents, logger = createFileLogger(getLogFileName(windowId))) => {
|
|
4928
4958
|
webContents.on('console-message', event => {
|
|
4929
4959
|
logger.log(formatMessage(event));
|
|
4930
4960
|
});
|
|
4961
|
+
webContents.on('destroyed', () => {
|
|
4962
|
+
logger.dispose?.();
|
|
4963
|
+
});
|
|
4931
4964
|
};
|
|
4932
4965
|
|
|
4933
4966
|
// TODO impossible to test these methods
|
|
@@ -4973,7 +5006,7 @@ const createAppWindow = async (windowOptions, parsedArgs, workingDirectory, titl
|
|
|
4973
5006
|
}
|
|
4974
5007
|
});
|
|
4975
5008
|
mark(DidCreateCodeWindow);
|
|
4976
|
-
addListener(window.webContents);
|
|
5009
|
+
addListener(window.id, window.webContents);
|
|
4977
5010
|
addDevDiagnostics(window);
|
|
4978
5011
|
const handleReadyToShow = () => {
|
|
4979
5012
|
// due to electron bug, zoom level needs to be set here,
|
|
@@ -4996,14 +5029,7 @@ const createAppWindow = async (windowOptions, parsedArgs, workingDirectory, titl
|
|
|
4996
5029
|
webContents: window.webContents
|
|
4997
5030
|
});
|
|
4998
5031
|
const disposeFullScreenListener = listen$1(window, rpc);
|
|
4999
|
-
const handleWindowClose = (
|
|
5000
|
-
try {
|
|
5001
|
-
disposeFullScreenListener();
|
|
5002
|
-
window.off('close', handleWindowClose);
|
|
5003
|
-
} catch (error) {
|
|
5004
|
-
handleError(new VError(error, `Failed to run window close listener`));
|
|
5005
|
-
}
|
|
5006
|
-
};
|
|
5032
|
+
const handleWindowClose = createWindowCloseHandler(window, rpc, error => handleError(new VError(error, `Failed to prepare window close`)), disposeFullScreenListener);
|
|
5007
5033
|
window.on('close', handleWindowClose);
|
|
5008
5034
|
await loadUrl(window, url);
|
|
5009
5035
|
};
|