refactor: update file path handling and enhance image support logic in mini window

- Changed file path retrieval method in MessageAttachments component.
- Initialized filesPath in MiniWindowApp using Redux dispatch.
- Enhanced image support checks in HomeWindow to conditionally allow image file types based on the assistant model.
This commit is contained in:
xihajun 2025-12-10 12:42:38 +00:00
parent 047a581220
commit 6b196f0107
3 changed files with 26 additions and 3 deletions

View File

@ -36,7 +36,7 @@ const MessageAttachments: FC<Props> = ({ block }) => {
fileList={[
{
uid: block.file.id,
url: 'file://' + FileManager.getSafePath(block.file),
url: 'file://' + FileManager.getFilePath(block.file),
status: 'done' as const,
name: FileManager.formatFileName(block.file),
type: block.file.type,

View File

@ -3,7 +3,8 @@ import '@renderer/databases'
import { ErrorBoundary } from '@renderer/components/ErrorBoundary'
import { getToastUtilities } from '@renderer/components/TopView/toast'
import { useSettings } from '@renderer/hooks/useSettings'
import store, { persistor } from '@renderer/store'
import store, { persistor, useAppDispatch } from '@renderer/store'
import { setFilesPath } from '@renderer/store/runtime'
import { useEffect } from 'react'
import { Provider } from 'react-redux'
import { PersistGate } from 'redux-persist/integration/react'
@ -16,6 +17,14 @@ import HomeWindow from './home/HomeWindow'
// Inner component that uses the hook after Redux is initialized
function MiniWindowContent(): React.ReactElement {
const { customCss } = useSettings()
const dispatch = useAppDispatch()
// Initialize filesPath for mini window (same as useAppInit in main window)
useEffect(() => {
window.api.getAppInfo().then((info) => {
dispatch(setFilesPath(info.filesPath))
})
}, [dispatch])
useEffect(() => {
let customCssElement = document.getElementById('user-defined-custom-css') as HTMLStyleElement

View File

@ -1,5 +1,6 @@
import { loggerService } from '@logger'
import { isMac } from '@renderer/config/constant'
import { isGenerateImageModel, isVisionModel } from '@renderer/config/models'
import { useTheme } from '@renderer/context/ThemeProvider'
import { useAssistant } from '@renderer/hooks/useAssistant'
import { useSettings } from '@renderer/hooks/useSettings'
@ -77,7 +78,18 @@ const HomeWindow: FC<{ draggable?: boolean }> = ({ draggable = true }) => {
const inputBarRef = useRef<HTMLDivElement>(null)
const featureMenusRef = useRef<FeatureMenusRef>(null)
const supportedImageExts = useMemo(() => ['.png', '.jpg', '.jpeg', '.gif', '.bmp', '.webp'], [])
// 检查当前助手的模型是否支持图片(复用主窗口逻辑)
const isVisionSupported = useMemo(() => isVisionModel(currentAssistant.model), [currentAssistant.model])
const isGenerateImageSupported = useMemo(() => isGenerateImageModel(currentAssistant.model), [currentAssistant.model])
const canAddImageFile = useMemo(
() => isVisionSupported || isGenerateImageSupported,
[isVisionSupported, isGenerateImageSupported]
)
const supportedImageExts = useMemo(
() => (canAddImageFile ? ['.png', '.jpg', '.jpeg', '.gif', '.bmp', '.webp'] : []),
[canAddImageFile]
)
const referenceText = useMemo(() => clipboardText || userInputText, [clipboardText, userInputText])
@ -223,6 +235,8 @@ const HomeWindow: FC<{ draggable?: boolean }> = ({ draggable = true }) => {
const handlePaste = useCallback(
async (event: React.ClipboardEvent<HTMLInputElement>) => {
// 复用 PasteService根据 supportedImageExts 自动过滤不支持的文件类型
// 当模型不支持图片时supportedImageExts 为空数组PasteService 会显示提示
await PasteService.handlePaste(
event.nativeEvent,
supportedImageExts,