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 #155 from nashaofu/dev
Browse files Browse the repository at this point in the history
release 2.0.10
  • Loading branch information
nashaofu authored Dec 9, 2018
2 parents c56ae6a + df70585 commit 40e89e5
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 31 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
钉钉桌面版,基于electron和钉钉网页版开发,支持Windows、Linux和macOS

## 安装步骤
> 直接从[GitHub relase](https://github.com/nashaofu/dingtalk/releases/latest)页面下载最新版安装包即可
> 直接从[GitHub releases](https://github.com/nashaofu/dingtalk/releases/latest)页面下载最新版安装包即可
## 国内仓库与版本安装包
* 国内git地址:[https://gitee.com/nashaofu/dingtalk](https://gitee.com/nashaofu/dingtalk)
Expand Down Expand Up @@ -79,5 +79,5 @@ npm run pack
加密信息暂不支持,详情请看[企业信息加密相关](https://github.com/nashaofu/dingtalk/issues/2),也欢迎各位朋友能够去研究一下,帮助实现这个功能

## 打赏
如果你觉的作者德辛苦付出有帮助到你,你可以给作者买杯咖啡!🤣
如果你觉得作者的辛苦付出有帮助到你,你可以给作者买杯咖啡!🤣
![打赏](./screenshot/reward.png)
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dingtalk",
"version": "2.0.9",
"version": "2.0.10",
"description": "钉钉桌面版,基于electron和钉钉网页版开发,支持Windows、Linux和macOS",
"author": "nashaofu <[email protected]>",
"main": "dist/main.js",
Expand Down Expand Up @@ -28,10 +28,10 @@
"dependencies": {
"axios": "^0.18.0",
"electron-store": "^2.0.0",
"electron-updater": "^4.0.4",
"lodash": "^4.17.10",
"normalize.css": "^8.0.0",
"shortcut-capture": "^1.0.1"
"electron-updater": "^3.2.3",
"lodash": "^4.17.11",
"normalize.css": "^8.0.1",
"shortcut-capture": "^1.0.3"
},
"devDependencies": {
"autoprefixer": "^7.2.6",
Expand All @@ -43,10 +43,10 @@
"babel-preset-stage-2": "^6.24.1",
"chalk": "^2.3.0",
"css-loader": "^0.28.9",
"electron": "^3.0.9",
"electron-builder": "^20.36.2",
"electron": "^2.0.14",
"electron-builder": "<=20.34.0",
"electron-debug": "^2.0.0",
"electron-dev-webpack-plugin": "0.0.10",
"electron-dev-webpack-plugin": "0.0.11",
"electron-devtools-installer": "^2.2.4",
"eslint": "^4.17.0",
"eslint-config-standard": "^10.2.1",
Expand Down
72 changes: 54 additions & 18 deletions src/main/dingtalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import shortcut from './shortcut'
import ShortcutCapture from 'shortcut-capture'

export default class DingTalk {
// app对象是否ready
_ready = null
// 托盘图标
$tray = null
// 主窗口
Expand All @@ -38,18 +40,18 @@ export default class DingTalk {
}

constructor () {
// 同时只能运行一个人实例
if (!app.requestSingleInstanceLock()) return app.quit()
this.init().then(() => {
// 移除窗口菜单
Menu.setApplicationMenu(null)
this.initMainWin()
this.initTray()
this.initShortcutCapture()
this.initNotify()
this.autoUpdate()
this.bindShortcut()
})
if (!this.requestSingleInstanceLock()) {
this.init().then(() => {
// 移除窗口菜单
Menu.setApplicationMenu(null)
this.initMainWin()
this.initTray()
this.initShortcutCapture()
this.initNotify()
this.autoUpdate()
this.bindShortcut()
})
}
}

/**
Expand All @@ -59,9 +61,20 @@ export default class DingTalk {
async init () {
online(this)()
this.setting = await initSetting(this)()
// 第二次打开应用,显示主窗口
app.on('second-instance', (event, commandLine, workingDirectory) => this.showMainWin())
return app.whenReady()
return this.whenReady()
}

/**
* 使应用程序成为单个实例应用程序
* 而不是允许应用程序的多个实例运行
* 这将确保只有一个应用程序的实例正在运行
* 其余的实例全部会被终止并退出
*/
requestSingleInstanceLock () {
// 同时只能运行一个人实例
const isSecond = app.makeSingleInstance(() => this.showMainWin())
if (isSecond) app.quit()
return isSecond
}

/**
Expand Down Expand Up @@ -110,13 +123,36 @@ export default class DingTalk {
return writeSetting(this)()
}

/**
* app是否ready
* @return {Promise} setting
*/
whenReady () {
if (this._ready) return this._ready
this._ready = new Promise((resolve, reject) => {
if (app.isReady()) return resolve()
app.once('ready', () => resolve())
// 所有窗口关闭之后退出应用
app.once('window-all-closed', () => {
if (process.platform !== 'darwin') {
if (this.$tray && !this.$tray.isDestroyed()) {
this.$tray.destroy()
this.$tray = null
}
app.quit()
}
})
})
return this._ready
}

/**
* 退出应用
*/
quit () {
BrowserWindow.getAllWindows().forEach(item => {
if (!item.isDestroyed()) item.destroy()
})
this.$shortcutCapture.destroy()
const windows = BrowserWindow.getAllWindows()
windows.forEach(item => !item.isDestroyed() && item.destroy())
if (process.platform !== 'darwin') {
if (this.$tray && !this.$tray.isDestroyed()) {
this.$tray.destroy()
Expand Down
4 changes: 1 addition & 3 deletions src/main/index.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ app.on('ready', () => {
installExtension.default(installExtension.VUEJS_DEVTOOLS).catch(err => {
console.log('Unable to install `vue-devtools`: \n', err)
})
app.whenReady().then(() => {
debug({ showDevTools: 'undocked' })
})
debug({ showDevTools: 'undocked' })
})

0 comments on commit 40e89e5

Please sign in to comment.