HELP Problem communicating main -> renderer
Closed this issue · 1 comments
Hello,
I'm new in the world of Java Script.
I use Electron-vue and I have some problems with this module.
I am able to send message from renderer to main and get a beautiful unicorn.
But when I have to do the reverse, I'm stuck.
I tried to put the main part in my main.js.
Then,
const win = electron.BrowserWindow.getFocusedWindow();
returns 'undefined'.
I also tried to put it in main/index.js at the end of my file (it's the file that create the window of the app).
And then it returns 'null'.
I have really no idea to make all things in order... Can someone help me please?
(if you understood nothing to what is the files I am talking about, here is my project: https://github.com/Irraky/test_mDNS)
Finally succeed!!!
Got help from someone and end with that:
main/index.js
const ipc = require('electron-better-ipc')
setInterval(() => {
(async () => {
const emoji = await ipc.callRenderer(mainWindow, 'get-emoji', 'unicorn')
console.log('Received from renderer', emoji)
})()
}, 2000)
Main.vue
<script>
const ipc = require('electron-better-ipc')
function getEmoji (emoji) {
if (emoji === 'unicorn') {
return '🦄'
}
return emoji
}
export default {
name: 'jsonformat',
created () {
ipc.answerMain('get-emoji', async emojiName => {
const emoji = await getEmoji(emojiName)
return emoji
})
}
}
</script>
That works as expected :3