Commit 3452e12 1 parent 7a37cd9 commit 3452e12 Copy full SHA for 3452e12
File tree 3 files changed +32
-0
lines changed
static/show-me/utilityprocess
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 = {
27
27
SystemPreferences : 'systemPreferences' ,
28
28
TouchBar : 'TouchBar' ,
29
29
Tray : 'Tray' ,
30
+ utilityProcess : 'utilityProcess' ,
30
31
WebContents : 'WebContents' ,
31
32
WebFrame : 'WebFrame' ,
32
33
} ,
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