Skip to content

Commit

Permalink
fix: 🐛 Search for shortcut key conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed May 26, 2024
1 parent 7116af2 commit c70e6ca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
19 changes: 9 additions & 10 deletions electron/events/shortcuts/index.js
Original file line number Diff line number Diff line change
@@ -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')
// })
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 9 additions & 7 deletions src/components/AppSearch/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,33 @@
</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 })
}
function closeSearchModal() {
window.findInPageModal.close()
}
const { ctrl_f } = useMagicKeys()
whenever(ctrl_f, () => {
openSearchModal()
})
</script>

<style lang="postcss"></style>

0 comments on commit c70e6ca

Please sign in to comment.