File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed
static/show-me/utilityprocess Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ export const SHOW_ME_TEMPLATES: Templates = {
2727 SystemPreferences : 'systemPreferences' ,
2828 TouchBar : 'TouchBar' ,
2929 Tray : 'Tray' ,
30+ utilityProcess : 'utilityProcess' ,
3031 WebContents : 'WebContents' ,
3132 WebFrame : 'WebFrame' ,
3233 } ,
Original file line number Diff line number Diff line change 1+ process . parentPort . on ( 'message' , ( e ) => {
2+ if ( e . data === 'Hello from parent!' ) {
3+ process . parentPort . postMessage ( 'Hello from child!' )
4+ }
5+ } )
Original file line number Diff line number Diff line change 1+ // The "utilityProcess" module allows creating a child process with
2+ // Node.js and Message ports enabled.It provides the equivalent of[`child_process.fork`][] API from Node.js
3+ // but instead uses[Services API][] from Chromium to launch the child process.
4+ //
5+ // For more info, see:
6+ // https://electronjs.org/docs/api/utility-process
7+
8+ const { app, utilityProcess } = require ( 'electron/main' )
9+ const path = require ( 'node:path' )
10+
11+ app . whenReady ( ) . then ( ( ) => {
12+ const child = utilityProcess . fork ( path . join ( __dirname , 'child.js' ) )
13+
14+ child . on ( 'spawn' , ( ) => {
15+ console . log ( `Child process spawned with PID: ${ child . pid } ` )
16+ child . postMessage ( 'Hello from parent!' )
17+ } )
18+
19+ child . on ( 'message' , ( message ) => {
20+ console . log ( `Received message from child: ${ message } ` )
21+ } )
22+
23+ child . on ( 'exit' , ( code ) => {
24+ console . log ( `Child exited with code: ${ code } ` )
25+ } )
26+ } )
You can’t perform that action at this time.
0 commit comments