refactor: update Minapp components to use preference management

- Replaced useSettings with usePreference in PinnedMinapps and useMinappPopup components for better preference handling.
- Added external dependency for Electron in electron.vite.config.ts and set output format to CommonJS.
This commit is contained in:
fullex 2025-09-06 17:23:19 +08:00
parent c2a1178dff
commit 9a847dc5a3
3 changed files with 8 additions and 6 deletions

View File

@ -64,8 +64,10 @@ export default defineConfig({
index: resolve(__dirname, 'src/preload/index.ts'),
simplest: resolve(__dirname, 'src/preload/simplest.ts') // Minimal preload
},
external: ['electron'],
output: {
entryFileNames: '[name].js'
entryFileNames: '[name].js',
format: 'cjs'
}
}
}

View File

@ -1,9 +1,9 @@
import { usePreference } from '@data/hooks/usePreference'
import { useTheme } from '@renderer/context/ThemeProvider'
import { useMinappPopup } from '@renderer/hooks/useMinappPopup'
import { useMinapps } from '@renderer/hooks/useMinapps'
import { useNavbarPosition } from '@renderer/hooks/useNavbar'
import { useRuntime } from '@renderer/hooks/useRuntime'
import { useSettings } from '@renderer/hooks/useSettings'
import { MinAppType } from '@renderer/types'
import type { MenuProps } from 'antd'
import { Dropdown, Tooltip } from 'antd'
@ -18,7 +18,7 @@ import MinAppIcon from '../Icons/MinAppIcon'
export const TopNavbarOpenedMinappTabs: FC = () => {
const { minappShow, openedKeepAliveMinapps, currentMinappId } = useRuntime()
const { openMinappKeepAlive, hideMinappPopup, closeMinapp, closeAllMinapps } = useMinappPopup()
const { showOpenedMinappsInSidebar } = useSettings()
const [showOpenedMinappsInSidebar] = usePreference('feature.minapp.show_opened_in_sidebar')
const { theme } = useTheme()
const { t } = useTranslation()
const [keepAliveMinapps, setKeepAliveMinapps] = useState(openedKeepAliveMinapps)
@ -112,7 +112,7 @@ export const TopNavbarOpenedMinappTabs: FC = () => {
export const SidebarOpenedMinappTabs: FC = () => {
const { minappShow, openedKeepAliveMinapps, currentMinappId } = useRuntime()
const { openMinappKeepAlive, hideMinappPopup, closeMinapp, closeAllMinapps } = useMinappPopup()
const { showOpenedMinappsInSidebar } = useSettings() // 获取控制显示的设置
const [showOpenedMinappsInSidebar] = usePreference('feature.minapp.show_opened_in_sidebar')
const { theme } = useTheme()
const { t } = useTranslation()
const { isLeftNavbar } = useNavbarPosition()

View File

@ -1,6 +1,6 @@
import { usePreference } from '@data/hooks/usePreference'
import { DEFAULT_MIN_APPS } from '@renderer/config/minapps'
import { useRuntime } from '@renderer/hooks/useRuntime'
import { useSettings } from '@renderer/hooks/useSettings' // 使用设置中的值
import { useAppDispatch } from '@renderer/store'
import {
setCurrentMinappId,
@ -31,7 +31,7 @@ let minAppsCache: LRUCache<string, MinAppType>
export const useMinappPopup = () => {
const dispatch = useAppDispatch()
const { openedKeepAliveMinapps, openedOneOffMinapp, minappShow } = useRuntime()
const { maxKeepAliveMinapps } = useSettings() // 使用设置中的值
const [maxKeepAliveMinapps] = usePreference('feature.minapp.max_keep_alive')
const createLRUCache = useCallback(() => {
return new LRUCache<string, MinAppType>({