optimize: 快捷键设置功能:优化退出软件时注销快捷键
parent
95ea782eb4
commit
d73d53cfc8
|
@ -257,9 +257,6 @@ async function beforeQuit () {
|
||||||
return DevSidecar.api.shutdown()
|
return DevSidecar.api.shutdown()
|
||||||
}
|
}
|
||||||
async function quit () {
|
async function quit () {
|
||||||
globalShortcut.unregisterAll()
|
|
||||||
log.info('注销所有快捷键成功')
|
|
||||||
|
|
||||||
if (tray) {
|
if (tray) {
|
||||||
tray.displayBalloon({ title: '正在关闭', content: '关闭中,请稍候。。。' })
|
tray.displayBalloon({ title: '正在关闭', content: '关闭中,请稍候。。。' })
|
||||||
}
|
}
|
||||||
|
@ -277,9 +274,7 @@ function initApp () {
|
||||||
|
|
||||||
// 全局监听快捷键,用于 显示/隐藏 窗口
|
// 全局监听快捷键,用于 显示/隐藏 窗口
|
||||||
app.whenReady().then(async () => {
|
app.whenReady().then(async () => {
|
||||||
globalShortcut.unregisterAll()
|
|
||||||
const showHideShortcut = DevSidecar.api.config.get().app.showHideShortcut
|
const showHideShortcut = DevSidecar.api.config.get().app.showHideShortcut
|
||||||
log.info('先注销所有快捷键,再根据配置设置一个全局快捷键:', showHideShortcut)
|
|
||||||
if (showHideShortcut && showHideShortcut !== '无' && showHideShortcut.length > 1) {
|
if (showHideShortcut && showHideShortcut !== '无' && showHideShortcut.length > 1) {
|
||||||
try {
|
try {
|
||||||
const registerSuccess = globalShortcut.register(DevSidecar.api.config.get().app.showHideShortcut, () => {
|
const registerSuccess = globalShortcut.register(DevSidecar.api.config.get().app.showHideShortcut, () => {
|
||||||
|
@ -342,11 +337,12 @@ if (!isFirstInstance) {
|
||||||
log.info('before-quit')
|
log.info('before-quit')
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
quit()
|
quit()
|
||||||
} else {
|
|
||||||
globalShortcut.unregisterAll()
|
|
||||||
log.info('注销所有快捷键成功')
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
app.on('will-quit', () => {
|
||||||
|
globalShortcut.unregisterAll();
|
||||||
|
log.info('应用关闭,注销所有快捷键')
|
||||||
|
});
|
||||||
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
||||||
log.info('new app started, command:', commandLine)
|
log.info('new app started, command:', commandLine)
|
||||||
if (win) {
|
if (win) {
|
||||||
|
@ -362,9 +358,6 @@ if (!isFirstInstance) {
|
||||||
// to stay active until the user quits explicitly with Cmd + Q
|
// to stay active until the user quits explicitly with Cmd + Q
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
quit()
|
quit()
|
||||||
} else {
|
|
||||||
globalShortcut.unregisterAll()
|
|
||||||
log.info('注销所有快捷键成功')
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue