-
Notifications
You must be signed in to change notification settings - Fork 1
/
renderer.js
41 lines (31 loc) · 894 Bytes
/
renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const EventEmitter = require('events');
const { IPCChannel } = require('./global.js');
const events = require("./enums.js");
class Renderer extends EventEmitter {
constructor() {
super();
this.ipc = require('electron').ipcRenderer;
this._handleEvent = this._handleEvent.bind(this);
this.ipc.on(IPCChannel, this._handleEvent);
}
destructor() {
this.ipc.removeListener(IPCChannel, this._handleEvent);
this.ipc = null;
}
_handleEvent(event, name, ...args) {
this.emit(name, ...args);
}
send(name, ...args) {
this.ipc.send(IPCChannel, name, ...args);
}
minimize() {
return this.send(events.MINIMIZE_EVENT);
}
maximize() {
return this.send(events.MAXIMIZE_EVENT);
}
close() {
return this.send(events.CLOSE_EVENT);
}
}
module.exports = Renderer;