1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import { Menu, Tray, app } from "electron";
- import { ICON, readIniFile, writeIniFile } from "./utils";
- import { showMainWin, extra } from "../win/mainWin";
- import log from "electron-log/main";
- import { handeGet, handeSet } from "./store";
- export const initTray = () => {
- let appIcon = new Tray(ICON);
- const isFocusOpenWin: number = handeGet("isFocusOpenWin");
- let contextMenu = Menu.buildFromTemplate([
- {
- id: "open-win",
- label: `${isFocusOpenWin == 1 ? "关闭" : "开启"}主动弹窗`,
- click: () => {
- updateItem();
- },
- },
- {
- label: "打开弹窗",
- click: () => {
- showMainWin();
- },
- },
- {
- label: "退出弹窗",
- click: () => {
- extra.activeClose = true;
- setTimeout(() => {
- app.quit();
- });
- },
- },
- ]);
- appIcon.setToolTip("菁苗健康");
- appIcon.setContextMenu(contextMenu);
- appIcon.addListener("click", function () {
- showMainWin();
- });
- // 更新item
- const updateItem = async () => {
- let isFocusOpenWin: number = handeGet("isFocusOpenWin");
- const openMenuItem = contextMenu.getMenuItemById("open-win");
- if (isFocusOpenWin == 1) {
- isFocusOpenWin = 2;
- openMenuItem!.label = `开启主动弹窗`;
- } else {
- isFocusOpenWin = 1;
- openMenuItem!.label = `关闭主动弹窗`;
- }
- contextMenu = Menu.buildFromTemplate(contextMenu.items);
- appIcon.setContextMenu(contextMenu);
- handeSet("isFocusOpenWin", isFocusOpenWin);
- log.info("isFocusOpenWin==>", isFocusOpenWin);
- };
- return appIcon;
- };
|