feature: 添加显示/隐藏窗口的全局快捷键,默认:`Alt+S` (#360)

pull/361/head
王良 2 months ago committed by GitHub
parent 6ed8e71b41
commit fa9899d2f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -27,6 +27,7 @@ module.exports = {
personalUrl: ''
},
startShowWindow: true, // 启动时是否打开窗口true=打开窗口, false=隐藏窗口
showHideShortcut: 'Alt+S', // 显示/隐藏窗口快捷键
windowSize: { width: 900, height: 750 }, // 启动时,窗口的尺寸
theme: 'dark', // 主题light=亮色, dark=暗色
autoChecked: true, // 是否自动检查更新

@ -1,7 +1,7 @@
'use strict'
/* global __static */
import path from 'path'
import { app, protocol, BrowserWindow, Menu, Tray, ipcMain, dialog, powerMonitor, nativeImage, nativeTheme } from 'electron'
import { app, protocol, BrowserWindow, Menu, Tray, ipcMain, dialog, powerMonitor, nativeImage, nativeTheme, globalShortcut } from 'electron'
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
import backend from './bridge/backend'
import DevSidecar from '@docmirror/dev-sidecar'
@ -15,6 +15,7 @@ const isDevelopment = process.env.NODE_ENV !== 'production'
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win
let winIsHidden = false
// eslint-disable-next-line no-unused-vars
let tray // 防止被内存清理
let forceClose = false
@ -141,6 +142,7 @@ function hideWin () {
if (isMac && hideDockWhenWinClose) {
app.dock.hide()
}
winIsHidden = true
}
}
@ -151,6 +153,15 @@ function showWin () {
if (app.dock) {
app.dock.show()
}
winIsHidden = false
}
function switchWin () {
if (winIsHidden) {
showWin()
} else {
hideWin()
}
}
function changeAppConfig (config) {
@ -179,6 +190,7 @@ function createWindow (startHideWindow) {
// eslint-disable-next-line no-undef
icon: path.join(__static, 'icon.png')
})
winIsHidden = !!startHideWindow
Menu.setApplicationMenu(null)
win.setMenu(null)
@ -261,13 +273,29 @@ async function quit () {
app.quit()
}
// eslint-disable-next-line no-unused-vars
function setDock () {
function initApp () {
if (isMac) {
app.whenReady().then(() => {
app.dock.setIcon(path.join(__dirname, '../build/mac/512x512.png'))
})
}
// 全局监听快捷键,用于 显示/隐藏 窗口
app.whenReady().then(() => {
globalShortcut.unregisterAll()
if (DevSidecar.api.config.get().app.showHideShortcut) {
globalShortcut.register(DevSidecar.api.config.get().app.showHideShortcut, () => {
if (winIsHidden) {
showWin()
} else {
// linux快捷键不关闭窗口
if (!isLinux()) {
hideWin()
}
}
})
}
})
}
// -------------执行开始---------------
app.disableHardwareAcceleration() // 禁用gpu
@ -332,7 +360,7 @@ if (!isFirstInstance) {
}
})
// setDock()
// initApp()
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
@ -369,7 +397,7 @@ if (!isFirstInstance) {
})
}
setDock()
initApp()
// Exit cleanly on request from parent process in development mode.
if (isDevelopment) {

@ -88,6 +88,13 @@
点击窗口右上角关闭按钮的效果
</div>
</a-form-item>
<hr/>
<a-form-item label="打开窗口快捷键" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-input v-model="config.app.showHideShortcut"></a-input>
<div class="form-help">
当前版本修改快捷键后需重启 ds 才会生效
</div>
</a-form-item>
<a-form-item label="启动时打开窗口" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-radio-group v-model="config.app.startShowWindow" default-value="true" button-style="solid">
<a-radio-button :value="true">

Loading…
Cancel
Save