/
trayicon.ts
43 lines (37 loc) · 1.21 KB
/
trayicon.ts
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
42
43
import { Menu, Tray } from "electron";
import * as path from "path";
import { EventEmitter } from "events";
export default class TrayIcon extends EventEmitter {
private tray = createTray();
constructor() {
super();
this.tray.setContextMenu(this.createMenu(false));
this.tray.on("click", () => this.emit("click"));
}
set running(value: boolean) {
this.tray.setContextMenu(this.createMenu(value));
}
private createMenu(running: boolean) {
return Menu.buildFromTemplate([
{
label: running ? "nginx 実行中" : "nginx 停止中",
enabled: false
},
{ type: "separator" },
{
label: "設定", click: () => this.emit("config")
},
{
label: "終了", click: () => this.emit("quit")
}
]);
}
}
function createTray() {
let resourcePath = path.normalize("./lib/res");
let tray = new Tray(process.platform === "darwin"
? resourcePath + "/icon_16px@3x.png"
: resourcePath + "/icon_192px.png");
tray.setToolTip("nginx-rtmp-frontend");
return tray;
}