mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-23 10:00:08 +08:00
refactor: Seperate MiniWindow loading from MainWindow (#5581)
This commit is contained in:
parent
49c9e14790
commit
7c0086a484
@ -489,11 +489,9 @@ export class WindowService {
|
||||
})
|
||||
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
this.miniWindow.loadURL(process.env['ELECTRON_RENDERER_URL'] + '#/mini')
|
||||
this.miniWindow.loadURL(process.env['ELECTRON_RENDERER_URL'] + '/src/windows/mini/index.html')
|
||||
} else {
|
||||
this.miniWindow.loadFile(join(__dirname, '../renderer/index.html'), {
|
||||
hash: '#/mini'
|
||||
})
|
||||
this.miniWindow.loadFile(join(__dirname, '../renderer/src/windows/mini/index.html'))
|
||||
}
|
||||
|
||||
return this.miniWindow
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="initial-scale=1, width=device-width" />
|
||||
<meta
|
||||
http-equiv="Content-Security-Policy"
|
||||
<meta http-equiv="Content-Security-Policy"
|
||||
content="default-src 'self'; connect-src blob: *; script-src 'self' 'unsafe-eval' *; worker-src 'self' blob:; style-src 'self' 'unsafe-inline' *; font-src 'self' data: *; img-src 'self' data: file: * blob:; frame-src * file:" />
|
||||
<title>Cherry Studio</title>
|
||||
|
||||
@ -29,14 +29,15 @@
|
||||
border-radius: 50px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<div id="spinner">
|
||||
<img src="/src/assets/images/logo.png" />
|
||||
</div>
|
||||
<script type="module" src="/src/init.ts"></script>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
<script type="module" src="/src/entryPoint.tsx"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
9
src/renderer/src/entryPoint.tsx
Normal file
9
src/renderer/src/entryPoint.tsx
Normal file
@ -0,0 +1,9 @@
|
||||
import './assets/styles/index.scss'
|
||||
import '@ant-design/v5-patch-for-react-19'
|
||||
|
||||
import { createRoot } from 'react-dom/client'
|
||||
|
||||
import App from './App'
|
||||
|
||||
const root = createRoot(document.getElementById('root') as HTMLElement)
|
||||
root.render(<App />)
|
||||
@ -6,7 +6,7 @@ import store from './store'
|
||||
|
||||
function initSpinner() {
|
||||
const spinner = document.getElementById('spinner')
|
||||
if (spinner && window.location.hash !== '#/mini') {
|
||||
if (spinner) {
|
||||
spinner.style.display = 'flex'
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
import './assets/styles/index.scss'
|
||||
import '@ant-design/v5-patch-for-react-19'
|
||||
|
||||
import { createRoot } from 'react-dom/client'
|
||||
|
||||
import App from './App'
|
||||
import MiniApp from './windows/mini/App'
|
||||
|
||||
if (location.hash === '#/mini') {
|
||||
document.getElementById('spinner')?.remove()
|
||||
const root = createRoot(document.getElementById('root') as HTMLElement)
|
||||
root.render(<MiniApp />)
|
||||
} else {
|
||||
const root = createRoot(document.getElementById('root') as HTMLElement)
|
||||
root.render(<App />)
|
||||
}
|
||||
@ -155,10 +155,6 @@ export const compareVersions = (v1: string, v2: string): number => {
|
||||
return 0
|
||||
}
|
||||
|
||||
export function isMiniWindow() {
|
||||
return window.location.hash === '#/mini'
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示确认模态框。
|
||||
* @param params 模态框参数
|
||||
|
||||
@ -57,6 +57,18 @@ function useMiniWindowCustomCss() {
|
||||
return isInitialized
|
||||
}
|
||||
|
||||
// Inner component that uses the hook after Redux is initialized
|
||||
function MiniWindowContent(): React.ReactElement {
|
||||
const cssInitialized = useMiniWindowCustomCss()
|
||||
|
||||
// Show empty fragment until CSS is initialized
|
||||
if (!cssInitialized) {
|
||||
return <></>
|
||||
}
|
||||
|
||||
return <HomeWindow />
|
||||
}
|
||||
|
||||
function MiniWindow(): React.ReactElement {
|
||||
//miniWindow should register its own message component
|
||||
const [messageApi, messageContextHolder] = message.useMessage()
|
||||
@ -78,16 +90,4 @@ function MiniWindow(): React.ReactElement {
|
||||
)
|
||||
}
|
||||
|
||||
// Inner component that uses the hook after Redux is initialized
|
||||
function MiniWindowContent(): React.ReactElement {
|
||||
const cssInitialized = useMiniWindowCustomCss()
|
||||
|
||||
// Show empty fragment until CSS is initialized
|
||||
if (!cssInitialized) {
|
||||
return <></>
|
||||
}
|
||||
|
||||
return <HomeWindow />
|
||||
}
|
||||
|
||||
export default MiniWindow
|
||||
@ -5,7 +5,6 @@ import MessageContent from '@renderer/pages/home/Messages/MessageContent'
|
||||
import MessageErrorBoundary from '@renderer/pages/home/Messages/MessageErrorBoundary'
|
||||
// import { LegacyMessage } from '@renderer/types'
|
||||
import type { Message } from '@renderer/types/newMessage'
|
||||
import { isMiniWindow } from '@renderer/utils'
|
||||
import { FC, memo, useMemo, useRef } from 'react'
|
||||
import styled from 'styled-components'
|
||||
|
||||
@ -35,7 +34,7 @@ const MessageItem: FC<Props> = ({ message, index, total, route }) => {
|
||||
|
||||
const messageBackground = getMessageBackground(true, isAssistantMessage)
|
||||
|
||||
const maxWidth = isMiniWindow() ? '800px' : '100%'
|
||||
const maxWidth = '800px'
|
||||
|
||||
if (['summary', 'explanation'].includes(route) && index === total - 1) {
|
||||
return null
|
||||
|
||||
22
src/renderer/src/windows/mini/entryPoint.tsx
Normal file
22
src/renderer/src/windows/mini/entryPoint.tsx
Normal file
@ -0,0 +1,22 @@
|
||||
import '@renderer/assets/styles/index.scss'
|
||||
import '@ant-design/v5-patch-for-react-19'
|
||||
|
||||
import KeyvStorage from '@kangfenmao/keyv-storage'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
|
||||
import MiniWindowApp from './MiniWindowApp'
|
||||
|
||||
/**
|
||||
* This function is required for model API
|
||||
* eg. BaseProviders.ts
|
||||
* Although the coupling is too strong, we have no choice but to load it
|
||||
* In multi-window handling, decoupling is needed
|
||||
*/
|
||||
function initKeyv() {
|
||||
window.keyv = new KeyvStorage()
|
||||
window.keyv.init()
|
||||
}
|
||||
initKeyv()
|
||||
|
||||
const root = createRoot(document.getElementById('root') as HTMLElement)
|
||||
root.render(<MiniWindowApp />)
|
||||
@ -181,7 +181,6 @@ const HomeWindow: FC = () => {
|
||||
messages: [userMessage],
|
||||
assistant: { ...assistant, model: getDefaultModel() },
|
||||
onChunkReceived: (chunk: Chunk) => {
|
||||
console.log('chunk', chunk)
|
||||
if (chunk.type === ChunkType.TEXT_DELTA) {
|
||||
blockContent += chunk.text
|
||||
if (!blockId) {
|
||||
|
||||
24
src/renderer/src/windows/mini/index.html
Normal file
24
src/renderer/src/windows/mini/index.html
Normal file
@ -0,0 +1,24 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="initial-scale=1, width=device-width" />
|
||||
<meta http-equiv="Content-Security-Policy"
|
||||
content="default-src 'self'; connect-src blob: *; script-src 'self' 'unsafe-eval' *; worker-src 'self' blob:; style-src 'self' 'unsafe-inline' *; font-src 'self' data: *; img-src 'self' data: file: * blob:; frame-src * file:" />
|
||||
<title>Cherry Studio</title>
|
||||
|
||||
<style>
|
||||
html,
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="./entryPoint.tsx"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
Reference in New Issue
Block a user