|
|
@@ -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
|
|
|
*/
|