2024-10-03 02:10:44 +00:00
|
|
|
import { ParentPort } from '@electron/internal/utility/parent-port';
|
|
|
|
|
2024-01-04 21:20:37 +00:00
|
|
|
import { EventEmitter } from 'events';
|
2023-09-29 21:38:37 +00:00
|
|
|
import { pathToFileURL } from 'url';
|
|
|
|
|
2022-10-20 05:49:49 +00:00
|
|
|
const v8Util = process._linkedBinding('electron_common_v8_util');
|
|
|
|
|
|
|
|
const entryScript: string = v8Util.getHiddenValue(process, '_serviceStartupScript');
|
|
|
|
// We modified the original process.argv to let node.js load the init.js,
|
|
|
|
// we need to restore it here.
|
|
|
|
process.argv.splice(1, 1, entryScript);
|
|
|
|
|
|
|
|
// Import common settings.
|
|
|
|
require('@electron/internal/common/init');
|
|
|
|
|
2024-01-04 21:20:37 +00:00
|
|
|
process._linkedBinding('electron_browser_event_emitter').setEventEmitterPrototype(EventEmitter.prototype);
|
|
|
|
|
2022-10-20 05:49:49 +00:00
|
|
|
const parentPort: ParentPort = new ParentPort();
|
|
|
|
Object.defineProperty(process, 'parentPort', {
|
|
|
|
enumerable: true,
|
|
|
|
writable: false,
|
|
|
|
value: parentPort
|
|
|
|
});
|
|
|
|
|
|
|
|
// Based on third_party/electron_node/lib/internal/worker/io.js
|
|
|
|
parentPort.on('newListener', (name: string) => {
|
|
|
|
if (name === 'message' && parentPort.listenerCount('message') === 0) {
|
|
|
|
parentPort.start();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
parentPort.on('removeListener', (name: string) => {
|
|
|
|
if (name === 'message' && parentPort.listenerCount('message') === 0) {
|
|
|
|
parentPort.pause();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Finally load entry script.
|
2024-05-13 15:43:14 +00:00
|
|
|
const { runEntryPointWithESMLoader } = __non_webpack_require__('internal/modules/run_main');
|
2023-09-29 21:38:37 +00:00
|
|
|
const mainEntry = pathToFileURL(entryScript);
|
2024-05-13 15:43:14 +00:00
|
|
|
|
|
|
|
runEntryPointWithESMLoader(async (cascadedLoader: any) => {
|
2023-09-29 21:38:37 +00:00
|
|
|
try {
|
2024-05-13 15:43:14 +00:00
|
|
|
await cascadedLoader.import(mainEntry.toString(), undefined, Object.create(null));
|
2023-09-29 21:38:37 +00:00
|
|
|
} catch (err) {
|
|
|
|
// @ts-ignore internalBinding is a secret internal global that we shouldn't
|
|
|
|
// really be using, so we ignore the type error instead of declaring it in types
|
|
|
|
internalBinding('errors').triggerUncaughtException(err);
|
|
|
|
}
|
|
|
|
});
|