Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add show-me for utilityProcess #1651

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const SHOW_ME_TEMPLATES: Templates = {
SystemPreferences: 'systemPreferences',
TouchBar: 'TouchBar',
Tray: 'Tray',
utilityProcess: 'utilityProcess',
WebContents: 'WebContents',
WebFrame: 'WebFrame',
},
Expand Down
5 changes: 5 additions & 0 deletions static/show-me/utilityprocess/child.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process.parentPort.on('message', (e) => {
if (e.data === 'Hello from parent!') {
process.parentPort.postMessage('Hello from child!')
}
})
26 changes: 26 additions & 0 deletions static/show-me/utilityprocess/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// The "utilityProcess" module allows creating a child process with
// Node.js and Message ports enabled.It provides the equivalent of[`child_process.fork`][] API from Node.js
// but instead uses[Services API][] from Chromium to launch the child process.
//
// For more info, see:
// https://electronjs.org/docs/api/utility-process

const { app, utilityProcess } = require('electron/main')
const path = require('node:path')

app.whenReady().then(() => {
const child = utilityProcess.fork(path.join(__dirname, 'child.js'))

child.on('spawn', () => {
console.log(`Child process spawned with PID: ${child.pid}`)
child.postMessage('Hello from parent!')
})

child.on('message', (message) => {
console.log(`Received message from child: ${message}`)
})

child.on('exit', (code) => {
console.log(`Child exited with code: ${code}`)
})
})