Skip to content

Commit

Permalink
快捷搜索窗口可以esc退出
Browse files Browse the repository at this point in the history
  • Loading branch information
ftyszyx committed Oct 11, 2024
1 parent 5eb2b6f commit 98e200c
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 17 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,18 @@ google你就不能把代码分几个模块啊,真是服了。
2. 通过ctrl+1和ctrl+2来控制子窗口间切换
3. 然后可以通过键盘的上下来控制菜单 的移动

## 2024/10/11

1. 快捷搜索窗口点esc关闭
2. 因为没有mac测试环境,程序正确性无法验证,打包只打windows包

## 需要处理

1. 自己上传图片更换
2. 加密图片信息
3. 快捷搜索窗口点esc无反应

# 远期的优化

1. 增加一个常用密码列表的设置

# 问题反馈

邮箱:whyzi@qq.com
Expand Down
1 change: 1 addition & 0 deletions src/common/entitys/ipcmsg.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ export enum MainToWebMsg {
AppUpdateEvent = 'UpdateEvent',
VaultChangeNotBackup = 'VaultChangeNotBackup',
WindowsHide = 'windosHide',
WindowsShow = 'windosShow',
AppSetChange = 'AppSetChange'
}
2 changes: 2 additions & 0 deletions src/main/windows/window.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class WindowBase {
Log.info('show window', this.url)
AppModel.getInstance().setLastPoint(screen.getCursorScreenPoint())
this.win.show()
this.win.webContents.send(MainToWebMsg.WindowsShow)
}

hide() {
Expand Down Expand Up @@ -170,6 +171,7 @@ export class WindowBase {
}

CheckBlurClick(windows: BrowserWindow) {
// console.log('winblur', this.url)
if (!this.click_outsize_close || this.window.isVisible() == false) return
if (this.window != windows) return
// console.log('checkblurclick', windows, this.window == windows, this.window.isVisible())
Expand Down
23 changes: 16 additions & 7 deletions src/renderer/src/libs/tools/shortKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,27 @@ class ShortKeyHelp {
this.clean()
}

isEventValid(e: KeyboardEvent): boolean {
isEventValid(e: KeyboardEvent, down: boolean = true): boolean {
const ele = e.target as HTMLElement
const tagname = ele.tagName
// ConsoleLog.info('handleKey', e.key, tagname, ele.className)
if (this.logflag)
ConsoleLog.info(
`handleKey ${down ? 'down' : 'up'} key:${e.key} tagname:${tagname} class:${ele.className}`
)
if ((' ' + ele.className + ' ').indexOf(' mousetrap ') > -1) {
return false
}
const key = GetTrueKey(e)
if (key == KEY_MAP.esc) {
const ele = e.target as HTMLElement
ele.blur()
this.handleBlur()
if (tagname == 'BODY') {
return true
}
if (down) {
if (this.logflag) ConsoleLog.info('esc blur')
ele.blur()
this.pressedKeys.clear()
}
return false
}

Expand All @@ -109,7 +118,7 @@ class ShortKeyHelp {
}

private handleKeyDown = (e: KeyboardEvent) => {
if (!this.isEventValid(e)) return
if (!this.isEventValid(e, true)) return
const key = GetTrueKey(e)
if (this.logflag) ConsoleLog.info('handleKeyDown', key)
this.pressedKeys.add(key)
Expand All @@ -130,9 +139,9 @@ class ShortKeyHelp {
}

private handleKeyUp = (e: KeyboardEvent) => {
if (!this.isEventValid(e)) return
if (!this.isEventValid(e, false)) return
const key = GetTrueKey(e)
// ConsoleLog.info('handleKeyUp', key)
if (this.logflag) ConsoleLog.info('handleKeyUp', key)
this.pressedKeys.delete(key)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/pages/quick/QuickLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function QucickLayout(props: ChildProps): JSX.Element {
}, [appstore.cur_user])

return (
<div>
<div tabIndex={0}>
{contextHolder}
{props.children}
</div>
Expand Down
38 changes: 32 additions & 6 deletions src/renderer/src/pages/quick/QuickSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { renderViewType } from '@common/entitys/app.entity'
import { MainToWebMsg, webToManMsg } from '@common/entitys/ipcmsg.entity'
import { VaultItem } from '@common/entitys/vault_item.entity'
import { Icon_type, VaultItemType } from '@common/gloabl'
import { GetTrueKey, KEY_MAP } from '@common/keycode'
import Icon from '@renderer/components/Icon'
import {
GetPasswordInfoString,
Expand All @@ -11,6 +12,7 @@ import {
} from '@renderer/entitys/Vault_item.entity'
import { ConsoleLog } from '@renderer/libs/Console'
import { ipc_call_normal } from '@renderer/libs/tools/other'
import { shortKeys } from '@renderer/libs/tools/shortKeys'
import { AppStore, use_appstore } from '@renderer/models/app.model'
import { AppsetStore, use_appset } from '@renderer/models/appset.model'
import { Button, Input, InputRef, message } from 'antd'
Expand Down Expand Up @@ -51,9 +53,20 @@ export default function QuickSearch() {
})
}

useEffect(() => {
window.electron.ipcRenderer.on(MainToWebMsg.WindowsShow, () => {
foucsInput()
})
return () => {
window.electron.ipcRenderer.removeAllListeners(MainToWebMsg.WindowsShow)
}
}, [])

useEffect(() => {
window.electron.ipcRenderer.on(MainToWebMsg.WindowsHide, () => {
setSearch('')
setShowDetail(false)
setSelectItem(null)
})
return () => {
window.electron.ipcRenderer.removeAllListeners(MainToWebMsg.WindowsHide)
Expand Down Expand Up @@ -148,6 +161,16 @@ export default function QuickSearch() {
}, 300)
}

useEffect(() => {
shortKeys.bindShortKey(KEY_MAP.esc, () => {
HideWin()
return true
})
return () => {
shortKeys.unbindShortKey(KEY_MAP.esc)
}
}, [])

function handlerCopy(keytype: PasswordRenderDetailKey) {
ConsoleLog.info(`handlerCopy ${keytype}`)
const selectItem = selectItemRef.current
Expand Down Expand Up @@ -178,23 +201,26 @@ export default function QuickSearch() {
handlerCopy(PasswordRenderDetailKey.ctrl_shift_C)
return
}
switch (event.key) {
case 'ArrowUp':
const truekey = GetTrueKey(event)
switch (truekey) {
case KEY_MAP.up:
// 处理向上箭头键
moveSelectPos('up')
break
case 'ArrowDown':
case KEY_MAP.down:
// 处理向下箭头键
moveSelectPos('down')
break
case 'ArrowRight':
case KEY_MAP.right:
if (selectItem) setShowDetail(true)
break
case 'ArrowLeft':
case KEY_MAP.left:
setShowDetail(false)
setSelectItem(null)
break
case 'Enter':
case KEY_MAP.esc:
break
case KEY_MAP.enter:
ConsoleLog.info(`enter show_detail:${show_detail} selectItemDetail:${selectItemDetail}`)
if (show_detail) {
if (selectItemDetail == SELECT_ITEM_STR) {
Expand Down

0 comments on commit 98e200c

Please sign in to comment.