luke 6 gadi atpakaļ
vecāks
revīzija
e80f847f4e

BIN
service_exe/build/icons/empty.png


+ 34 - 2
service_exe/src/main/index.js

@@ -1,11 +1,19 @@
-import {app, BrowserWindow} from 'electron'
-
+import { app, BrowserWindow, ipcMain, Menu, Tray, nativeImage } from 'electron'
+let tray = null;
+let path = require("path")
+let icon
+let iconS
 /**
  * Set `__static` path to static files in production
  * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
  */
 if (process.env.NODE_ENV !== 'development') {
+	icon = nativeImage.createFromPath(path.join(__dirname, '../../../icon.png'))
+	iconS = nativeImage.createFromPath(path.join(__dirname, '../../../empty.png'))
 	global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
+} else {
+	icon = nativeImage.createFromPath('build/icons/icon.png')
+	iconS = nativeImage.createFromPath('build/icons/empty.png')
 }
 
 let mainWindow
@@ -14,6 +22,30 @@ const winURL = process.env.NODE_ENV === 'development'
 	: `file://${__dirname}/index.html`
 
 function createWindow() {
+	let timer = null
+	let count = 0;
+	tray = new Tray(icon)
+	ipcMain.on('haveMessage', (event,arg) => {
+		timer = setInterval(() => {
+			count += 1
+			if (count % 2 === 0) {
+				tray.setImage(icon)
+			} else {
+				tray.setImage(iconS) // 创建一个空的nativeImage实例
+			}
+		}, 500)
+	})
+	tray.on('click', () => {
+		if (mainWindow.isVisible()) {
+			mainWindow.hide()
+		} else {
+			mainWindow.show()
+			tray.setImage(icon)
+			clearInterval(timer)
+			timer = null
+			count = 0
+		}
+	})
 	/**
 	 * Initial window options
 	 */

+ 5 - 1
service_exe/src/renderer/App.vue

@@ -8,7 +8,8 @@
 
 <script>
   import Vue from 'vue';
-  import receiveAPP from '../../static/audio/receive.wav'
+  import receiveAPP from '../../static/audio/receive.wav';
+  import electron from 'electron'
   export default {
     name: 'App',
     data(){
@@ -200,6 +201,9 @@
 
         //接收用户消息数据
         if(redata.message_type == "chatMessage"){
+          const ipc = require('electron').ipcRenderer;
+          ipc.send('haveMessage');
+          console.log(ipc,'123')
           this.Messagenum = this.$store.getters.get_megnum;
           this.Messagenum = ++this.Messagenum;
           this.$store.dispatch("SET_MEGNNUM", this.Messagenum);