Skip to content
This repository has been archived by the owner on Feb 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #198 from nashaofu/dev
Browse files Browse the repository at this point in the history
修复托盘图标导致应用出不来的问题
  • Loading branch information
nashaofu authored Apr 27, 2019
2 parents 1dd61d6 + 66fee5e commit 103fb55
Show file tree
Hide file tree
Showing 4 changed files with 7,836 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

1. 在主进程(main)和preload中,为了减小单个文件的大小,并且合理管理代码,所有的功能模块都是通过**高阶函数**的方式加载进来的,使用高阶函数的目的是为了让我们在所有的模块代码中都可以访问到dingtalk对象
2. 主进程的入口文件在调试环境时使用**index.dev.js**,正式环境使用**index.js**
3. rendder部分和普通vue项目一样,具体请参考vue光放提出的编码风格指南
3. rendder部分和普通vue项目一样,具体请参考vue官方提出的编码风格指南
4. 在所有的进程中,如果需要访问图片资源或者其他资源,请通过`path.join(app.getAppPath(), './icon/32x32.png')`的方式来获取,因为打包之后相对的目录结构不能保证一致,所以请务必注意
5. 编码时请使用ES6语法,并遵守ESLint的规则,在提交pr的时候请尽量在代码中补充好注释,并去掉不必要的代码,也好减轻review的工作量

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"electron": "^2.0.18",
"electron-builder": "<=20.34.0",
"electron-debug": "^2.1.0",
"electron-dev-webpack-plugin": "^1.0.0",
"electron-dev-webpack-plugin": "^1.0.2",
"electron-devtools-installer": "^2.2.4",
"eslint": "^5.14.1",
"eslint-config-standard": "^12.0.0",
Expand Down
18 changes: 10 additions & 8 deletions src/main/dingtalkTray.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import { Tray, Menu, nativeImage } from 'electron'
import { Tray, Menu } from 'electron'
import { getMessageTrayIcon, getNoMessageTrayIcon } from './logo'

const messageTrayIcon = nativeImage.createFromPath(getMessageTrayIcon())
const noMessageTrayIcon = nativeImage.createFromPath(getNoMessageTrayIcon())

export default class DingtalkTray {
_dingtalk = null
// 图标闪烁定时
_flickerTimer = null

// 托盘对象
$tray = null
// 图标文件
messageTrayIcon = getMessageTrayIcon()
noMessageTrayIcon = getNoMessageTrayIcon()

constructor ({ dingtalk }) {
// this.messageTrayIcon = getMessageTrayIcon()
// this.noMessageTrayIcon = getNoMessageTrayIcon()
this._dingtalk = dingtalk
// 生成托盘图标及其菜单项实例
this.$tray = new Tray(noMessageTrayIcon)
this.$tray = new Tray(this.noMessageTrayIcon)
// 设置鼠标悬浮时的标题
this.$tray.setToolTip('钉钉')
this.initMenu()
Expand Down Expand Up @@ -69,15 +71,15 @@ export default class DingtalkTray {
if (is) {
// 防止连续调用多次,导致图标切换时间间隔不是1000ms
if (this._flickerTimer !== null) return
let icon = messageTrayIcon
let icon = this.messageTrayIcon
this._flickerTimer = setInterval(() => {
this.$tray.setImage(icon)
icon = icon === messageTrayIcon ? noMessageTrayIcon : messageTrayIcon
icon = icon === this.messageTrayIcon ? this.noMessageTrayIcon : this.messageTrayIcon
}, 1000)
} else {
clearInterval(this._flickerTimer)
this._flickerTimer = null
this.$tray.setImage(noMessageTrayIcon)
this.$tray.setImage(this.noMessageTrayIcon)
}
}

Expand Down
Loading

0 comments on commit 103fb55

Please sign in to comment.