fix: 🐛 Search for shortcut key conflicts

This commit is contained in:
viarotel 2024-05-26 22:13:20 +08:00
parent 7116af28fd
commit c70e6ca2fc
3 changed files with 19 additions and 17 deletions

View File

@ -1,13 +1,12 @@
import { globalShortcut } from 'electron'
// import { globalShortcut } from 'electron'
export default (mainWindow) => {
mainWindow.on('focus', () => {
globalShortcut.register('CommandOrControl+F', (event) => {
mainWindow.webContents.send('focus-on-search')
})
})
mainWindow.on('blur', () => {
globalShortcut.unregister('CommandOrControl+F')
})
// mainWindow.on('focus', () => {
// globalShortcut.register('CommandOrControl+F', (event) => {
// mainWindow.webContents.send('focus-on-search')
// })
// })
// mainWindow.on('blur', () => {
// globalShortcut.unregister('CommandOrControl+F')
// })
}

View File

@ -36,6 +36,7 @@
"@unocss/transformer-directives": "^0.59.4",
"@viarotel-org/unocss-preset-shades": "^0.8.2",
"@vitejs/plugin-vue": "^5.0.4",
"@vueuse/core": "^10.9.0",
"dayjs": "^1.11.11",
"electron": "^30.0.3",
"electron-builder": "^24.13.3",

View File

@ -15,24 +15,20 @@
</template>
<script setup>
import { useMagicKeys, whenever } from '@vueuse/core'
import { useThemeStore } from '$/store/theme/index.js'
const themeStore = useThemeStore()
const activeTab = inject('activeTab')
const shortcutTip = `${
window.electron.process.platform === 'darwin' ? 'Command' : 'Ctrl'
} + F`
const shortcutTip = 'Ctrl + F'
watch([() => themeStore.value, () => activeTab.value], () => {
closeSearchModal()
})
window.electron.ipcRenderer.on('focus-on-search', (event, ret) => {
openSearchModal()
})
function openSearchModal() {
window.findInPageModal.open({ isDark: themeStore.isDark })
}
@ -40,6 +36,12 @@ function openSearchModal() {
function closeSearchModal() {
window.findInPageModal.close()
}
const { ctrl_f } = useMagicKeys()
whenever(ctrl_f, () => {
openSearchModal()
})
</script>
<style lang="postcss"></style>