mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-11 08:19:01 +08:00
feat(SelectionService): enhance trigger mode handling and update predefined blacklist
This commit is contained in:
parent
20b55693cb
commit
0cd62a07fb
@ -9,6 +9,7 @@ interface IBlacklist {
|
|||||||
* -----------------------------------------------------------------------
|
* -----------------------------------------------------------------------
|
||||||
* A predefined application filter list to include commonly used software
|
* A predefined application filter list to include commonly used software
|
||||||
* that does not require text selection but may conflict with it, and disable them in advance.
|
* that does not require text selection but may conflict with it, and disable them in advance.
|
||||||
|
* Only available in the selected mode.
|
||||||
*
|
*
|
||||||
* Specification: must be all lowercase, need to accurately find the actual running program name
|
* Specification: must be all lowercase, need to accurately find the actual running program name
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
@ -18,6 +19,9 @@ export const SELECTION_PREDEFINED_BLACKLIST: IBlacklist = {
|
|||||||
'snipaste.exe',
|
'snipaste.exe',
|
||||||
'pixpin.exe',
|
'pixpin.exe',
|
||||||
'sharex.exe',
|
'sharex.exe',
|
||||||
|
// Office
|
||||||
|
'excel.exe',
|
||||||
|
'powerpnt.exe',
|
||||||
// Image Editor
|
// Image Editor
|
||||||
'photoshop.exe',
|
'photoshop.exe',
|
||||||
'illustrator.exe',
|
'illustrator.exe',
|
||||||
|
|||||||
@ -37,6 +37,11 @@ type RelativeOrientation =
|
|||||||
| 'middleRight'
|
| 'middleRight'
|
||||||
| 'center'
|
| 'center'
|
||||||
|
|
||||||
|
enum TriggerMode {
|
||||||
|
Selected = 'selected',
|
||||||
|
Ctrlkey = 'ctrlkey'
|
||||||
|
}
|
||||||
|
|
||||||
/** SelectionService is a singleton class that manages the selection hook and the toolbar window
|
/** SelectionService is a singleton class that manages the selection hook and the toolbar window
|
||||||
*
|
*
|
||||||
* Features:
|
* Features:
|
||||||
@ -59,7 +64,7 @@ export class SelectionService {
|
|||||||
private initStatus: boolean = false
|
private initStatus: boolean = false
|
||||||
private started: boolean = false
|
private started: boolean = false
|
||||||
|
|
||||||
private triggerMode = 'selected'
|
private triggerMode = TriggerMode.Selected
|
||||||
private isFollowToolbar = true
|
private isFollowToolbar = true
|
||||||
private isRemeberWinSize = false
|
private isRemeberWinSize = false
|
||||||
private filterMode = 'default'
|
private filterMode = 'default'
|
||||||
@ -145,7 +150,7 @@ export class SelectionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private initConfig() {
|
private initConfig() {
|
||||||
this.triggerMode = configManager.getSelectionAssistantTriggerMode()
|
this.triggerMode = configManager.getSelectionAssistantTriggerMode() as TriggerMode
|
||||||
this.isFollowToolbar = configManager.getSelectionAssistantFollowToolbar()
|
this.isFollowToolbar = configManager.getSelectionAssistantFollowToolbar()
|
||||||
this.isRemeberWinSize = configManager.getSelectionAssistantRemeberWinSize()
|
this.isRemeberWinSize = configManager.getSelectionAssistantRemeberWinSize()
|
||||||
this.filterMode = configManager.getSelectionAssistantFilterMode()
|
this.filterMode = configManager.getSelectionAssistantFilterMode()
|
||||||
@ -153,9 +158,16 @@ export class SelectionService {
|
|||||||
|
|
||||||
this.setHookGlobalFilterMode(this.filterMode, this.filterList)
|
this.setHookGlobalFilterMode(this.filterMode, this.filterList)
|
||||||
|
|
||||||
configManager.subscribe(ConfigKeys.SelectionAssistantTriggerMode, (triggerMode: string) => {
|
configManager.subscribe(ConfigKeys.SelectionAssistantTriggerMode, (triggerMode: TriggerMode) => {
|
||||||
|
const oldTriggerMode = this.triggerMode
|
||||||
|
|
||||||
this.triggerMode = triggerMode
|
this.triggerMode = triggerMode
|
||||||
this.processTriggerMode()
|
this.processTriggerMode()
|
||||||
|
|
||||||
|
//trigger mode changed, need to update the filter list
|
||||||
|
if (oldTriggerMode !== triggerMode) {
|
||||||
|
this.setHookGlobalFilterMode(this.filterMode, this.filterList)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
configManager.subscribe(ConfigKeys.SelectionAssistantFollowToolbar, (isFollowToolbar: boolean) => {
|
configManager.subscribe(ConfigKeys.SelectionAssistantFollowToolbar, (isFollowToolbar: boolean) => {
|
||||||
@ -198,23 +210,26 @@ export class SelectionService {
|
|||||||
blacklist: 2
|
blacklist: 2
|
||||||
}
|
}
|
||||||
|
|
||||||
let combinedList: string[] = []
|
let combinedList: string[] = list
|
||||||
let combinedMode = mode
|
let combinedMode = mode
|
||||||
|
|
||||||
switch (mode) {
|
//only the selected mode need to combine the predefined blacklist with the user-defined blacklist
|
||||||
case 'blacklist':
|
if (this.triggerMode === TriggerMode.Selected) {
|
||||||
//combine the predefined blacklist with the user-defined blacklist
|
switch (mode) {
|
||||||
combinedList = [...new Set([...list, ...SELECTION_PREDEFINED_BLACKLIST.WINDOWS])]
|
case 'blacklist':
|
||||||
break
|
//combine the predefined blacklist with the user-defined blacklist
|
||||||
case 'whitelist':
|
combinedList = [...new Set([...list, ...SELECTION_PREDEFINED_BLACKLIST.WINDOWS])]
|
||||||
combinedList = [...list]
|
break
|
||||||
break
|
case 'whitelist':
|
||||||
case 'default':
|
combinedList = [...list]
|
||||||
default:
|
break
|
||||||
//use the predefined blacklist as the default filter list
|
case 'default':
|
||||||
combinedList = [...SELECTION_PREDEFINED_BLACKLIST.WINDOWS]
|
default:
|
||||||
combinedMode = 'blacklist'
|
//use the predefined blacklist as the default filter list
|
||||||
break
|
combinedList = [...SELECTION_PREDEFINED_BLACKLIST.WINDOWS]
|
||||||
|
combinedMode = 'blacklist'
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.selectionHook.setGlobalFilterMode(modeMap[combinedMode], combinedList)) {
|
if (!this.selectionHook.setGlobalFilterMode(modeMap[combinedMode], combinedList)) {
|
||||||
@ -774,7 +789,7 @@ export class SelectionService {
|
|||||||
*/
|
*/
|
||||||
private handleKeyDownHide = (data: KeyboardEventData) => {
|
private handleKeyDownHide = (data: KeyboardEventData) => {
|
||||||
//dont hide toolbar when ctrlkey is pressed
|
//dont hide toolbar when ctrlkey is pressed
|
||||||
if (this.triggerMode === 'ctrlkey' && this.isCtrlkey(data.vkCode)) {
|
if (this.triggerMode === TriggerMode.Ctrlkey && this.isCtrlkey(data.vkCode)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//dont hide toolbar when shiftkey is pressed, because it's used for selection
|
//dont hide toolbar when shiftkey is pressed, because it's used for selection
|
||||||
@ -1042,7 +1057,7 @@ export class SelectionService {
|
|||||||
* Manages appropriate event listeners for each mode
|
* Manages appropriate event listeners for each mode
|
||||||
*/
|
*/
|
||||||
private processTriggerMode() {
|
private processTriggerMode() {
|
||||||
if (this.triggerMode === 'selected') {
|
if (this.triggerMode === TriggerMode.Selected) {
|
||||||
if (this.isCtrlkeyListenerActive) {
|
if (this.isCtrlkeyListenerActive) {
|
||||||
this.selectionHook!.off('key-down', this.handleKeyDownCtrlkeyMode)
|
this.selectionHook!.off('key-down', this.handleKeyDownCtrlkeyMode)
|
||||||
this.selectionHook!.off('key-up', this.handleKeyUpCtrlkeyMode)
|
this.selectionHook!.off('key-up', this.handleKeyUpCtrlkeyMode)
|
||||||
@ -1051,7 +1066,7 @@ export class SelectionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.selectionHook!.setSelectionPassiveMode(false)
|
this.selectionHook!.setSelectionPassiveMode(false)
|
||||||
} else if (this.triggerMode === 'ctrlkey') {
|
} else if (this.triggerMode === TriggerMode.Ctrlkey) {
|
||||||
if (!this.isCtrlkeyListenerActive) {
|
if (!this.isCtrlkeyListenerActive) {
|
||||||
this.selectionHook!.on('key-down', this.handleKeyDownCtrlkeyMode)
|
this.selectionHook!.on('key-down', this.handleKeyDownCtrlkeyMode)
|
||||||
this.selectionHook!.on('key-up', this.handleKeyUpCtrlkeyMode)
|
this.selectionHook!.on('key-up', this.handleKeyUpCtrlkeyMode)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user