|
@@ -1,11 +1,29 @@
|
|
|
import { Menu, Tray, app } from "electron";
|
|
|
-import { ICON, readIniFile, writeIniFile } from "./utils";
|
|
|
+import path from "node:path";
|
|
|
+import { DIST, ICON, PUBLIC, readIniFile, url, writeIniFile } from "./utils";
|
|
|
import { showMainWin, extra } from "../win/mainWin";
|
|
|
import log from "electron-log/main";
|
|
|
import { handeGet, handeSet } from "./store";
|
|
|
+import io from "socket.io-client";
|
|
|
|
|
|
export const initTray = () => {
|
|
|
- let appIcon = new Tray(ICON);
|
|
|
+ const handlePath = (icon: string) => {
|
|
|
+ return url ? path.join(PUBLIC!, icon) : path.join(DIST, icon);
|
|
|
+ };
|
|
|
+ const ICONS = {
|
|
|
+ default: ICON,
|
|
|
+ icon1: handlePath("./icon-1.png"),
|
|
|
+ icon2: handlePath("./icon-2.png"),
|
|
|
+ icon3: handlePath("./icon-3.png"),
|
|
|
+ icon4: handlePath("./icon-4.png"),
|
|
|
+ icon5: handlePath("./icon-5.png"),
|
|
|
+ icon6: handlePath("./icon-6.png"),
|
|
|
+ icon7: handlePath("./icon-7.png"),
|
|
|
+ icon8: handlePath("./icon-8.png"),
|
|
|
+ icon9: handlePath("./icon-9.png"),
|
|
|
+ icon9plus: handlePath("./icon-9plus.png"),
|
|
|
+ };
|
|
|
+ let appIcon = new Tray(ICONS.default);
|
|
|
const isFocusOpenWin: number = handeGet("isFocusOpenWin");
|
|
|
let contextMenu = Menu.buildFromTemplate([
|
|
|
{
|
|
@@ -34,6 +52,29 @@ export const initTray = () => {
|
|
|
appIcon.setToolTip("菁苗健康");
|
|
|
appIcon.setContextMenu(contextMenu);
|
|
|
|
|
|
+
|
|
|
+ const SOCKET_URL = "http://114.215.252.134:2120";
|
|
|
+ const socket = io(SOCKET_URL, {
|
|
|
+ reconnection: true,
|
|
|
+ reconnectionDelay: 1000,
|
|
|
+ timeout: 20000,
|
|
|
+ });
|
|
|
+ let msgCount = 0;
|
|
|
+
|
|
|
+ socket.on("connect", function () {
|
|
|
+ console.log("Connected via CDN ES6");
|
|
|
+ socket.emit("login", 158);
|
|
|
+ });
|
|
|
+
|
|
|
+ socket.on("new_msg", function (msg) {
|
|
|
+ msgCount++;
|
|
|
+ if (msgCount <= 9) {
|
|
|
+ appIcon.setImage(ICONS[`icon${msgCount}`]);
|
|
|
+ } else {
|
|
|
+ appIcon.setImage(ICONS[`icon9plus`]);
|
|
|
+ }
|
|
|
+ appIcon.setToolTip(`菁苗健康-未读消息数量(${msgCount})`);
|
|
|
+ });
|
|
|
appIcon.addListener("click", function () {
|
|
|
showMainWin();
|
|
|
});
|