mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-03 02:59:07 +08:00
fix: unexpected quitting full screen mode (#9200)
* fix(Inputbar): 修正拼写错误,将expend改为expand
* fix: 修复Escape键事件冒泡问题并改进全屏处理
修复多个组件中Escape键事件未阻止冒泡的问题
添加全屏控制IPC通道
将全屏退出逻辑移至渲染进程处理
移除主进程中冗余的全屏退出处理代码
* fix(SelectModelPopup): 修复键盘事件处理并移除无效的useEffect
将键盘事件监听从window移动到Modal容器,避免事件冒泡问题
移除无效的useEffect并更新键盘事件类型定义
* fix(QuickPanel): 拦截window上的keydown事件
* fix(QuickPanel): 修复事件监听器移除时未使用相同参数的问题
* fix(TopView): 修复左侧导航栏布局崩坏问题
* fix: 修正变量名拼写错误,将expended改为expanded
* Revert "fix(SelectModelPopup): 修复键盘事件处理并移除无效的useEffect"
This reverts commit 4211780b95.
This commit is contained in:
parent
80dfcf05a7
commit
a21fc91915
@ -35,6 +35,7 @@ export enum IpcChannel {
|
||||
App_InstallBunBinary = 'app:install-bun-binary',
|
||||
App_LogToMain = 'app:log-to-main',
|
||||
App_SaveData = 'app:save-data',
|
||||
App_SetFullScreen = 'app:set-full-screen',
|
||||
|
||||
App_MacIsProcessTrusted = 'app:mac-is-process-trusted',
|
||||
App_MacRequestProcessTrust = 'app:mac-request-process-trust',
|
||||
|
||||
@ -191,6 +191,10 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
|
||||
})
|
||||
}
|
||||
|
||||
ipcMain.handle(IpcChannel.App_SetFullScreen, (_, value: boolean): void => {
|
||||
mainWindow.setFullScreen(value)
|
||||
})
|
||||
|
||||
ipcMain.handle(IpcChannel.Config_Set, (_, key: string, value: any, isNotify: boolean = false) => {
|
||||
configManager.set(key, value, isNotify)
|
||||
})
|
||||
|
||||
@ -223,26 +223,26 @@ export class WindowService {
|
||||
})
|
||||
|
||||
// 添加Escape键退出全屏的支持
|
||||
mainWindow.webContents.on('before-input-event', (event, input) => {
|
||||
// 当按下Escape键且窗口处于全屏状态时退出全屏
|
||||
if (input.key === 'Escape' && !input.alt && !input.control && !input.meta && !input.shift) {
|
||||
if (mainWindow.isFullScreen()) {
|
||||
// 获取 shortcuts 配置
|
||||
const shortcuts = configManager.getShortcuts()
|
||||
const exitFullscreenShortcut = shortcuts.find((s) => s.key === 'exit_fullscreen')
|
||||
if (exitFullscreenShortcut == undefined) {
|
||||
mainWindow.setFullScreen(false)
|
||||
return
|
||||
}
|
||||
if (exitFullscreenShortcut?.enabled) {
|
||||
event.preventDefault()
|
||||
mainWindow.setFullScreen(false)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
})
|
||||
// mainWindow.webContents.on('before-input-event', (event, input) => {
|
||||
// // 当按下Escape键且窗口处于全屏状态时退出全屏
|
||||
// if (input.key === 'Escape' && !input.alt && !input.control && !input.meta && !input.shift) {
|
||||
// if (mainWindow.isFullScreen()) {
|
||||
// // 获取 shortcuts 配置
|
||||
// const shortcuts = configManager.getShortcuts()
|
||||
// const exitFullscreenShortcut = shortcuts.find((s) => s.key === 'exit_fullscreen')
|
||||
// if (exitFullscreenShortcut == undefined) {
|
||||
// mainWindow.setFullScreen(false)
|
||||
// return
|
||||
// }
|
||||
// if (exitFullscreenShortcut?.enabled) {
|
||||
// event.preventDefault()
|
||||
// mainWindow.setFullScreen(false)
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return
|
||||
// })
|
||||
}
|
||||
|
||||
private setupWebContentsHandlers(mainWindow: BrowserWindow) {
|
||||
|
||||
@ -76,6 +76,7 @@ const api = {
|
||||
clearCache: () => ipcRenderer.invoke(IpcChannel.App_ClearCache),
|
||||
logToMain: (source: LogSourceWithContext, level: LogLevel, message: string, data: any[]) =>
|
||||
ipcRenderer.invoke(IpcChannel.App_LogToMain, source, level, message, data),
|
||||
setFullScreen: (value: boolean): Promise<void> => ipcRenderer.invoke(IpcChannel.App_SetFullScreen, value),
|
||||
mac: {
|
||||
isProcessTrusted: (): Promise<boolean> => ipcRenderer.invoke(IpcChannel.App_MacIsProcessTrusted),
|
||||
requestProcessTrust: (): Promise<boolean> => ipcRenderer.invoke(IpcChannel.App_MacRequestProcessTrust)
|
||||
|
||||
@ -62,6 +62,7 @@ const CollapsibleSearchBar: React.FC<CollapsibleSearchBarProps> = ({ onSearch, i
|
||||
onChange={(e) => handleTextChange(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Escape') {
|
||||
e.stopPropagation()
|
||||
handleTextChange('')
|
||||
if (!searchText) setSearchVisible(false)
|
||||
}
|
||||
|
||||
@ -282,6 +282,7 @@ export const ContentSearch = React.forwardRef<ContentSearchRef, Props>(
|
||||
implementation.searchNext()
|
||||
}
|
||||
} else if (event.key === 'Escape') {
|
||||
event.stopPropagation()
|
||||
implementation.disable()
|
||||
}
|
||||
},
|
||||
|
||||
@ -63,6 +63,7 @@ const EditableNumber: FC<EditableNumberProps> = ({
|
||||
if (e.key === 'Enter') {
|
||||
handleBlur()
|
||||
} else if (e.key === 'Escape') {
|
||||
e.stopPropagation()
|
||||
setInputValue(value)
|
||||
setIsEditing(false)
|
||||
}
|
||||
|
||||
@ -256,6 +256,7 @@ const PopupContainer: React.FC<Props> = ({ model, resolve, modelFilter }) => {
|
||||
break
|
||||
case 'Escape':
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
setOpen(false)
|
||||
resolve(undefined)
|
||||
break
|
||||
|
||||
@ -458,6 +458,7 @@ export const QuickPanelView: React.FC<Props> = ({ setInputText }) => {
|
||||
}
|
||||
break
|
||||
case 'Escape':
|
||||
e.stopPropagation()
|
||||
handleClose('esc')
|
||||
break
|
||||
}
|
||||
@ -477,14 +478,14 @@ export const QuickPanelView: React.FC<Props> = ({ setInputText }) => {
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('keydown', handleKeyDown)
|
||||
window.addEventListener('keyup', handleKeyUp)
|
||||
window.addEventListener('click', handleClickOutside)
|
||||
window.addEventListener('keydown', handleKeyDown, true)
|
||||
window.addEventListener('keyup', handleKeyUp, true)
|
||||
window.addEventListener('click', handleClickOutside, true)
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('keydown', handleKeyDown)
|
||||
window.removeEventListener('keyup', handleKeyUp)
|
||||
window.removeEventListener('click', handleClickOutside)
|
||||
window.removeEventListener('keydown', handleKeyDown, true)
|
||||
window.removeEventListener('keyup', handleKeyUp, true)
|
||||
window.removeEventListener('click', handleClickOutside, true)
|
||||
}
|
||||
}, [index, isAssistiveKeyPressed, historyPanel, ctx, list, handleItemAction, handleClose, clearSearchText])
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
import { loggerService } from '@logger'
|
||||
import TopViewMinappContainer from '@renderer/components/MinApp/TopViewMinappContainer'
|
||||
import { useAppInit } from '@renderer/hooks/useAppInit'
|
||||
import { useShortcuts } from '@renderer/hooks/useShortcuts'
|
||||
import { message, Modal } from 'antd'
|
||||
import React, { PropsWithChildren, useCallback, useEffect, useRef, useState } from 'react'
|
||||
|
||||
@ -24,6 +26,8 @@ type ElementItem = {
|
||||
element: React.FC | React.ReactNode
|
||||
}
|
||||
|
||||
const logger = loggerService.withContext('TopView')
|
||||
|
||||
const TopViewContainer: React.FC<Props> = ({ children }) => {
|
||||
const [elements, setElements] = useState<ElementItem[]>([])
|
||||
const elementsRef = useRef<ElementItem[]>([])
|
||||
@ -31,6 +35,8 @@ const TopViewContainer: React.FC<Props> = ({ children }) => {
|
||||
|
||||
const [messageApi, messageContextHolder] = message.useMessage()
|
||||
const [modal, modalContextHolder] = Modal.useModal()
|
||||
const { shortcuts } = useShortcuts()
|
||||
const enableQuitFullScreen = shortcuts.find((item) => item.key === 'exit_fullscreen')?.enabled
|
||||
|
||||
useAppInit()
|
||||
|
||||
@ -72,6 +78,21 @@ const TopViewContainer: React.FC<Props> = ({ children }) => {
|
||||
)
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
logger.debug('keydown', e)
|
||||
if (!enableQuitFullScreen) return
|
||||
|
||||
if (e.key === 'Escape' && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey) {
|
||||
window.api.setFullScreen(false)
|
||||
}
|
||||
}
|
||||
window.addEventListener('keydown', handleKeyDown)
|
||||
return () => {
|
||||
window.removeEventListener('keydown', handleKeyDown)
|
||||
}
|
||||
})
|
||||
|
||||
return (
|
||||
<>
|
||||
{children}
|
||||
|
||||
@ -66,6 +66,7 @@ export function useInPlaceEdit(options: UseInPlaceEditOptions): UseInPlaceEditRe
|
||||
saveEdit()
|
||||
} else if (e.key === 'Escape') {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
cancelEdit()
|
||||
}
|
||||
},
|
||||
|
||||
@ -87,7 +87,7 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
|
||||
enableQuickPanelTriggers,
|
||||
enableSpellCheck
|
||||
} = useSettings()
|
||||
const [expended, setExpend] = useState(false)
|
||||
const [expanded, setExpand] = useState(false)
|
||||
const [estimateTokenCount, setEstimateTokenCount] = useState(0)
|
||||
const [contextCount, setContextCount] = useState({ current: 0, max: 0 })
|
||||
const textareaRef = useRef<TextAreaRef>(null)
|
||||
@ -256,7 +256,7 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
|
||||
setFiles([])
|
||||
setTimeout(() => setText(''), 500)
|
||||
setTimeout(() => resizeTextArea(true), 0)
|
||||
setExpend(false)
|
||||
setExpand(false)
|
||||
} catch (error) {
|
||||
logger.warn('Failed to send message:', error as Error)
|
||||
parent?.recordException(error as Error)
|
||||
@ -396,9 +396,10 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
|
||||
}
|
||||
}
|
||||
|
||||
if (expended) {
|
||||
if (expanded) {
|
||||
if (event.key === 'Escape') {
|
||||
return onToggleExpended()
|
||||
event.stopPropagation()
|
||||
return onToggleExpanded()
|
||||
}
|
||||
}
|
||||
|
||||
@ -493,7 +494,7 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
|
||||
EventEmitter.emit(EVENT_NAMES.NEW_CONTEXT)
|
||||
}
|
||||
|
||||
const onInput = () => !expended && resizeTextArea()
|
||||
const onInput = () => !expanded && resizeTextArea()
|
||||
|
||||
const onChange = useCallback(
|
||||
(e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||
@ -633,7 +634,7 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
|
||||
|
||||
if (textArea) {
|
||||
textArea.style.height = `${newHeight}px`
|
||||
setExpend(newHeight == maxHeightInPixels)
|
||||
setExpand(newHeight == maxHeightInPixels)
|
||||
setTextareaHeight(newHeight)
|
||||
}
|
||||
},
|
||||
@ -795,10 +796,10 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
|
||||
|
||||
const onClearMentionModels = useCallback(() => setMentionedModels([]), [setMentionedModels])
|
||||
|
||||
const onToggleExpended = () => {
|
||||
const currentlyExpanded = expended || !!textareaHeight
|
||||
const onToggleExpanded = () => {
|
||||
const currentlyExpanded = expanded || !!textareaHeight
|
||||
const shouldExpand = !currentlyExpanded
|
||||
setExpend(shouldExpand)
|
||||
setExpand(shouldExpand)
|
||||
const textArea = textareaRef.current?.resizableTextArea?.textArea
|
||||
if (!textArea) return
|
||||
if (shouldExpand) {
|
||||
@ -818,7 +819,7 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
|
||||
focusTextarea()
|
||||
}
|
||||
|
||||
const isExpended = expended || !!textareaHeight
|
||||
const isExpanded = expanded || !!textareaHeight
|
||||
const showThinkingButton = isSupportedThinkingTokenModel(model) || isSupportedReasoningEffortModel(model)
|
||||
|
||||
if (isMultiSelectMode) {
|
||||
@ -899,8 +900,8 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
|
||||
couldMentionNotVisionModel={couldMentionNotVisionModel}
|
||||
couldAddImageFile={couldAddImageFile}
|
||||
onEnableGenerateImage={onEnableGenerateImage}
|
||||
isExpended={isExpended}
|
||||
onToggleExpended={onToggleExpended}
|
||||
isExpanded={isExpanded}
|
||||
onToggleExpanded={onToggleExpanded}
|
||||
addNewTopic={addNewTopic}
|
||||
clearTopic={clearTopic}
|
||||
onNewContext={onNewContext}
|
||||
|
||||
@ -71,8 +71,8 @@ export interface InputbarToolsProps {
|
||||
couldMentionNotVisionModel: boolean
|
||||
couldAddImageFile: boolean
|
||||
onEnableGenerateImage: () => void
|
||||
isExpended: boolean
|
||||
onToggleExpended: () => void
|
||||
isExpanded: boolean
|
||||
onToggleExpanded: () => void
|
||||
|
||||
addNewTopic: () => void
|
||||
clearTopic: () => void
|
||||
@ -113,8 +113,8 @@ const InputbarTools = ({
|
||||
couldMentionNotVisionModel,
|
||||
couldAddImageFile,
|
||||
onEnableGenerateImage,
|
||||
isExpended,
|
||||
onToggleExpended,
|
||||
isExpanded: isExpended,
|
||||
onToggleExpanded: onToggleExpended,
|
||||
addNewTopic,
|
||||
clearTopic,
|
||||
onNewContext,
|
||||
|
||||
@ -466,6 +466,7 @@ const ProvidersList: FC = () => {
|
||||
onChange={(e) => setSearchText(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Escape') {
|
||||
e.stopPropagation()
|
||||
setSearchText('')
|
||||
}
|
||||
}}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user