mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 03:10:08 +08:00
feat(SelectionAssistant): predefined apps filter list (#6662)
* feat: predefined app blacklist * fix * fix * fix * fix: improve filter list processing in SelectionFilterListModal
This commit is contained in:
parent
5b1a57f27f
commit
3e97f7b237
37
src/main/configs/SelectionConfig.ts
Normal file
37
src/main/configs/SelectionConfig.ts
Normal file
@ -0,0 +1,37 @@
|
||||
interface IBlacklist {
|
||||
WINDOWS: string[]
|
||||
MAC?: string[]
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* 注意:请不要修改此配置,除非你非常清楚其含义、影响和行为的目的
|
||||
* Note: Do not modify this configuration unless you fully understand its meaning, implications, and intended behavior.
|
||||
* -----------------------------------------------------------------------
|
||||
* 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.
|
||||
*
|
||||
* Specification: must be all lowercase, need to accurately find the actual running program name
|
||||
*************************************************************************/
|
||||
export const SELECTION_PREDEFINED_BLACKLIST: IBlacklist = {
|
||||
WINDOWS: [
|
||||
// Screenshot
|
||||
'snipaste.exe',
|
||||
'pixpin.exe',
|
||||
'sharex.exe',
|
||||
// Image Editor
|
||||
'photoshop.exe',
|
||||
'illustrator.exe',
|
||||
// Video Editor
|
||||
'adobe premiere pro.exe',
|
||||
'afterfx.exe',
|
||||
// Audio Editor
|
||||
'adobe audition.exe',
|
||||
// 3D Editor
|
||||
'blender.exe',
|
||||
'3dsmax.exe',
|
||||
'maya.exe',
|
||||
// CAD
|
||||
'acad.exe',
|
||||
'sldworks.exe'
|
||||
]
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
import { SELECTION_PREDEFINED_BLACKLIST } from '@main/configs/SelectionConfig'
|
||||
import { isDev, isWin } from '@main/constant'
|
||||
import { IpcChannel } from '@shared/IpcChannel'
|
||||
import { BrowserWindow, ipcMain, screen } from 'electron'
|
||||
@ -196,7 +197,27 @@ export class SelectionService {
|
||||
whitelist: 1,
|
||||
blacklist: 2
|
||||
}
|
||||
if (!this.selectionHook.setGlobalFilterMode(modeMap[mode], list)) {
|
||||
|
||||
let combinedList: string[] = []
|
||||
let combinedMode = mode
|
||||
|
||||
switch (mode) {
|
||||
case 'blacklist':
|
||||
//combine the predefined blacklist with the user-defined blacklist
|
||||
combinedList = [...new Set([...list, ...SELECTION_PREDEFINED_BLACKLIST.WINDOWS])]
|
||||
break
|
||||
case 'whitelist':
|
||||
combinedList = [...list]
|
||||
break
|
||||
case 'default':
|
||||
default:
|
||||
//use the predefined blacklist as the default filter list
|
||||
combinedList = [...SELECTION_PREDEFINED_BLACKLIST.WINDOWS]
|
||||
combinedMode = 'blacklist'
|
||||
break
|
||||
}
|
||||
|
||||
if (!this.selectionHook.setGlobalFilterMode(modeMap[combinedMode], combinedList)) {
|
||||
this.logError(new Error('Failed to set selection-hook global filter mode'))
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,13 +25,13 @@ const SelectionFilterListModal: FC<SelectionFilterListModalProps> = ({ open, onC
|
||||
const handleSave = async () => {
|
||||
try {
|
||||
const values = await form.validateFields()
|
||||
const newList = values.filterList
|
||||
const newList = (values.filterList as string)
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.split('\n')
|
||||
.map((line: string) => line.trim())
|
||||
.map((line: string) => line.trim().slice(0, 32))
|
||||
.filter((line: string) => line.length > 0)
|
||||
onSave(newList)
|
||||
onSave([...new Set(newList)])
|
||||
onClose()
|
||||
} catch (error) {
|
||||
// validation failed
|
||||
@ -57,7 +57,7 @@ const SelectionFilterListModal: FC<SelectionFilterListModalProps> = ({ open, onC
|
||||
<UserTip>{t('selection.settings.filter_modal.user_tips')}</UserTip>
|
||||
<Form form={form} layout="vertical" initialValues={{ filterList: '' }}>
|
||||
<Form.Item name="filterList" noStyle>
|
||||
<StyledTextArea autoSize={{ minRows: 6, maxRows: 16 }} autoFocus />
|
||||
<StyledTextArea autoSize={{ minRows: 6, maxRows: 16 }} spellCheck={false} autoFocus />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user