1、两个状态控制开始录制、结束录制
2、退出应用
3、当录制状态时,切换另一个状态【结束录制】,反之显示【开始录制】
electron录制-系统托盘-演示
function createTray(init = 0) {
if (tray) {
console.log("Tray already created!");
return
}
tray = new Tray(path.join(process.env.VITE_PUBLIC, init === 0 ? 'tray-icon-start.png' : 'tray-icon-stop.png'));
const startItem = {
label: 'Start Record',
click: function () {
console.log("Start Record");
tray?.destroy()
tray = null
createTray(1)
}
}
const stopItem = {
label: 'Stop Record',
click: function () {
console.log("Start Record");
tray?.destroy()
tray = null
createTray(0)
}
}
const contextMenu = Menu.buildFromTemplate([
init === 0 ? startItem : stopItem,
{
label: 'Quit',
role: 'quit'
}
]);
tray.setToolTip('AV CRAFT');
tray.setContextMenu(contextMenu);
}