Skip to content

Call ipc main handler from shortcuts? #23

@deadcoder0904

Description

@deadcoder0904

Describe the bug

So I have a use-case where I have to call the same function in both shortcut & main ipc handler.

Is it possible to just call the ipc in main from shortcut?

I've made a simple example but my actual example is a bit complex which essentially does the same thing with a few goodies (few lines of code) added.

Full proj -> https://github.com/deadcoder0904/electron-typed-ipc-poc

Relevant files:

src/main/shortcuts.ts

globalShortcut.register('CommandOrControl+G', () => {
	console.log('Command/Ctrl + G pressed.')
	console.log('##### Hello from IPC #####') // invoke ipc function `helloFromIPC()` from here
})

src/main/ipc.ts

ipcMainHandler.handle('helloFromIPC', () => {
	console.log('##### Hello from IPC #####')
})

src/main/index.ts

app.whenReady().then(() => {
	initIpc()
	shortcutsHelper.registerGlobalShortcuts()
})

Now what I want to do is do the comment I mentioned in shortcuts.ts where the common function is the console.log. I'm assuming this isn't possible as IPC literally stands for inter-process communication (main to renderer or renderer to main) so I prolly need to make a common function or something?

Is that essentially correct? Note this example is trivial but my main one is a bit complicated.

PS: Love this library although understanding the same naming was hard but meru's implementation came to rescue.

Electron-Toolkit Version

^1.0.2

Electron Version

^36.2.0

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions