Write ipc message with class style method is possible
yarn add -D vue-ipc-decorator
I reccomend use this library with vue-property-decorator
import { ipcRenderer } from 'electron';
import Vue from 'vue';
import Component from 'vue-class-component';
@Component()
export default class GreetComponent extends Vue {
//
// some super awesome implementations...
//
// 🤔
private greet() {
ipcRenderer.on('greet-response', (ev, data) => {
console.log('got response!!', data)
})
ipcRenderer.send('greet', 'hey!');
}
}
import { ipcMain } from 'electron';
ipcMain.on('greet', (ev, data) => {
console.log('greeting from renderer', data)
ev.sender.send('greet-response','hello')
})
import { IpcRendererSend } from 'vue-ipc-decorator';
import Vue from 'vue';
import Component from 'vue-class-component';
@Component()
export default class GreetComponent extends Vue {
//
// some super awesome implementations...
//
// 😎
@IpcRendererSend()
private greetFromRenderer() {
return 'hey!';
}
private async greet() {
// decorated function will be asynchronous function
let response = await this.greetFromRenderer();
console.log('got response!!', response)
}
}
import { IpcMainReceive } from 'vue-ipc-decorator';
class Greet {
@IpcMainReceive()
private greetFromRenderer(data: any) {
console.log('greeting from renderer', data)
return 'hello'
}
}
const greeter = new Greet();