diff --git a/tauri-app/src/App.tsx b/tauri-app/src/App.tsx index 16b88b9..07f0b60 100644 --- a/tauri-app/src/App.tsx +++ b/tauri-app/src/App.tsx @@ -9,10 +9,7 @@ import Login from './pages/Login/Login'; import VideoCreation from './pages/VideoCreation'; import MyWorks from './pages/ContentManagement/MyWorks'; import VoiceMaterialLibrary from './pages/ContentManagement/VoiceMaterialLibrary'; -import AboutUs from './pages/Settings/AboutUs'; -import SystemUpdate from './pages/Settings/SystemUpdate'; - - +import Settings from './pages/Settings/Settings'; import Profile from './pages/Profile/Profile'; import UsageDetail from './pages/Profile/UsageDetail'; import ToastContainer from './components/Toast/ToastContainer'; @@ -33,8 +30,7 @@ type PageType = | 'video-creation' | 'voice-material' | 'my-works' - | 'about-us' - | 'system-update' + | 'settings' | 'profile' | 'usage-detail'; @@ -43,8 +39,7 @@ const pages: Record = { 'video-creation': VideoCreation, 'voice-material': VoiceMaterialLibrary, 'my-works': MyWorks, - 'about-us': AboutUs, - 'system-update': SystemUpdate, + settings: Settings, profile: Profile, 'usage-detail': UsageDetail, }; diff --git a/tauri-app/src/components/Layout/Sidebar.tsx b/tauri-app/src/components/Layout/Sidebar.tsx index 1802a51..a100634 100644 --- a/tauri-app/src/components/Layout/Sidebar.tsx +++ b/tauri-app/src/components/Layout/Sidebar.tsx @@ -35,6 +35,7 @@ interface SidebarProps { const userMenuItems = [ { id: 'profile', label: '我的账户' }, + { id: 'settings', label: '设置' }, ]; export default function Sidebar({ currentPath, onNavigate }: SidebarProps) { diff --git a/tauri-app/src/pages/Profile/Profile.tsx b/tauri-app/src/pages/Profile/Profile.tsx index 3b240d2..860da87 100644 --- a/tauri-app/src/pages/Profile/Profile.tsx +++ b/tauri-app/src/pages/Profile/Profile.tsx @@ -33,12 +33,6 @@ const SettingsIcon = () => ( ); -const InfoIcon = () => ( - - - -); - const ChevronRightIcon = ({ className }: { className?: string }) => ( @@ -129,8 +123,7 @@ export default function Profile() { const menuItems = [ { label: '使用明细', icon: , onClick: () => navigate('usage-detail') }, - { label: '系统设置', icon: , onClick: () => navigate('system-update') }, - { label: '关于我们', icon: , onClick: () => navigate('about-us') }, + { label: '设置', icon: , onClick: () => navigate('settings') }, ]; return ( diff --git a/tauri-app/src/pages/Settings/AboutUs.tsx b/tauri-app/src/pages/Settings/AboutUs.tsx deleted file mode 100644 index b7534f7..0000000 --- a/tauri-app/src/pages/Settings/AboutUs.tsx +++ /dev/null @@ -1,113 +0,0 @@ -import { useState, useRef, useCallback } from 'react'; -import '../ContentManagement/ContentManagement.css'; -import AppHeader from '../../components/Layout/AppHeader'; -import EnvironmentSwitchModal from '../../components/Modal/EnvironmentSwitchModal'; -import { useNavigation } from '../../contexts/NavigationContext'; -import { saveAppConfig } from '../../api/modules/config'; -import { invoke } from '@tauri-apps/api/core'; -import { toast } from '../../store/uiStore'; - -const CURRENT_VERSION = __APP_VERSION__; - -export default function AboutUs() { - const { navigate, appEnvironment } = useNavigation(); - const [showModal, setShowModal] = useState(false); - - // 版本号连击检测 - const clickCountRef = useRef(0); - const clickTimerRef = useRef | null>(null); - - const handleVersionClick = useCallback(() => { - clickCountRef.current += 1; - - if (clickCountRef.current === 5) { - setShowModal(true); - clickCountRef.current = 0; - if (clickTimerRef.current) {clearTimeout(clickTimerRef.current);} - return; - } - - if (clickTimerRef.current) {clearTimeout(clickTimerRef.current);} - clickTimerRef.current = setTimeout(() => { - clickCountRef.current = 0; - }, 2000); - }, []); - - const handleSave = async (env: string) => { - try { - await saveAppConfig(env); - - // 开发模式下 Vite dev server 重启后无法自动恢复,改用刷新页面 - if (import.meta.env.DEV) { - toast.success('配置已保存,即将刷新'); - setTimeout(() => { - window.location.reload(); - }, 500); - return; - } - - toast.success('配置已保存,应用即将重启'); - setTimeout(() => { - invoke('restart_app'); - }, 800); - } catch { - toast.error('保存配置失败'); - } - }; - - return ( -
- navigate('profile')} /> -
-
-
- 应用名称 - 美家卡 智影 -
-
- 版本号 - - v{CURRENT_VERSION} - -
-
-
- -
-

授权信息

-
-

- 本软件由美家卡团队开发维护。授权用户可在授权范围内使用本软件进行视频创作。 - 如需商业授权或有任何疑问,请联系我们的支持团队。 -

-
-
- -
-

版权声明

-
-

- Copyright 2025 美家卡 (meijiaka.cn). All rights reserved. -

-

- 本软件及其相关文档的所有权利均归美家卡所有。 - 未经授权,不得复制、修改、分发或以其他方式使用本软件。 -

-
-
- - setShowModal(false)} - /> -
- ); -} diff --git a/tauri-app/src/pages/Settings/SystemUpdate.tsx b/tauri-app/src/pages/Settings/Settings.tsx similarity index 58% rename from tauri-app/src/pages/Settings/SystemUpdate.tsx rename to tauri-app/src/pages/Settings/Settings.tsx index dd1c4d2..4a388b8 100644 --- a/tauri-app/src/pages/Settings/SystemUpdate.tsx +++ b/tauri-app/src/pages/Settings/Settings.tsx @@ -1,21 +1,20 @@ -/** - * 系统更新页面 - * ============ - * - * 支持手动检查更新、下载并安装。 - */ - -import { useState } from 'react'; +import { useState, useRef, useCallback } from 'react'; import { useNavigation } from '../../contexts/NavigationContext'; import AppHeader from '../../components/Layout/AppHeader'; +import EnvironmentSwitchModal from '../../components/Modal/EnvironmentSwitchModal'; import { check, type Update, type DownloadEvent } from '@tauri-apps/plugin-updater'; import { relaunch } from '@tauri-apps/plugin-process'; +import { saveAppConfig } from '../../api/modules/config'; +import { invoke } from '@tauri-apps/api/core'; +import { toast } from '../../store/uiStore'; import '../ContentManagement/ContentManagement.css'; const CURRENT_VERSION = __APP_VERSION__; -export default function SystemUpdate() { - const { navigate } = useNavigation(); +export default function Settings() { + const { navigate, appEnvironment } = useNavigation(); + + // ── 系统更新状态 ── const [checking, setChecking] = useState(false); const [checkResult, setCheckResult] = useState<'none' | 'latest' | 'available'>('none'); const [updateInfo, setUpdateInfo] = useState(null); @@ -24,7 +23,12 @@ export default function SystemUpdate() { const [progress, setProgress] = useState(0); const [downloadedBytes, setDownloadedBytes] = useState(0); const [totalBytes, setTotalBytes] = useState(0); - const [error, setError] = useState(null); + const [updateError, setUpdateError] = useState(null); + + // ── 环境切换 ── + const [showEnvModal, setShowEnvModal] = useState(false); + const clickCountRef = useRef(0); + const clickTimerRef = useRef | null>(null); const formatBytes = (bytes: number) => { if (bytes === 0) return '0 B'; @@ -37,7 +41,7 @@ export default function SystemUpdate() { const handleCheck = async () => { setChecking(true); setCheckResult('none'); - setError(null); + setUpdateError(null); setUpdateInfo(null); try { @@ -49,8 +53,8 @@ export default function SystemUpdate() { setCheckResult('latest'); } } catch (err) { - console.error('[SystemUpdate] 检查更新失败:', err); - setError(err instanceof Error ? err.message : '检查更新失败'); + console.error('[Settings] 检查更新失败:', err); + setUpdateError(err instanceof Error ? err.message : '检查更新失败'); setCheckResult('none'); } finally { setChecking(false); @@ -64,9 +68,8 @@ export default function SystemUpdate() { setProgress(0); setDownloadedBytes(0); setTotalBytes(0); - setError(null); + setUpdateError(null); - // 用局部变量保存总大小,避免 Progress 回调里的闭包问题 let totalSize = 0; try { @@ -94,8 +97,8 @@ export default function SystemUpdate() { setDownloading(false); setInstalling(true); } catch (err) { - console.error('[SystemUpdate] 下载安装失败:', err); - setError(err instanceof Error ? err.message : '下载安装失败'); + console.error('[Settings] 下载安装失败:', err); + setUpdateError(err instanceof Error ? err.message : '下载安装失败'); setDownloading(false); } }; @@ -104,22 +107,57 @@ export default function SystemUpdate() { try { await relaunch(); } catch (err) { - setError(err instanceof Error ? err.message : '重启失败'); + setUpdateError(err instanceof Error ? err.message : '重启失败'); + } + }; + + // ── 版本号连击 ── + const handleVersionClick = useCallback(() => { + clickCountRef.current += 1; + + if (clickCountRef.current === 5) { + setShowEnvModal(true); + clickCountRef.current = 0; + if (clickTimerRef.current) { clearTimeout(clickTimerRef.current); } + return; + } + + if (clickTimerRef.current) { clearTimeout(clickTimerRef.current); } + clickTimerRef.current = setTimeout(() => { + clickCountRef.current = 0; + }, 2000); + }, []); + + const handleSaveEnv = async (env: string) => { + try { + await saveAppConfig(env); + + if (import.meta.env.DEV) { + toast.success('配置已保存,即将刷新'); + setTimeout(() => { window.location.reload(); }, 500); + return; + } + + toast.success('配置已保存,应用即将重启'); + setTimeout(() => { invoke('restart_app'); }, 800); + } catch { + toast.error('保存配置失败'); } }; return (
- navigate('profile')} /> + navigate('profile')} /> + + {/* 系统更新 */}
+

系统更新

- {/* 当前版本 */}
当前版本 v{CURRENT_VERSION}
- {/* 检查更新 */}
版本更新
@@ -141,7 +179,6 @@ export default function SystemUpdate() {
- {/* 更新详情 & 操作 */} {checkResult === 'available' && updateInfo && (
{updateInfo.body && ( @@ -151,7 +188,6 @@ export default function SystemUpdate() {
)} - {/* 下载进度 */} {downloading && (
@@ -164,12 +200,9 @@ export default function SystemUpdate() {
)} - {/* 按钮 */}
{installing ? ( - + ) : (
)} - {/* 错误 */} - {error && ( + {updateError && (
- {error} + {updateError}
)}
+ + {/* 关于我们 */} +
+

关于我们

+
+
+ 应用名称 + 美家卡 智影 +
+
+ 版本号 + + v{CURRENT_VERSION} + +
+
+
+ + {/* 授权信息 */} +
+

授权信息

+
+

+ 本软件由美家卡团队开发维护。授权用户可在授权范围内使用本软件进行视频创作。 + 如需商业授权或有任何疑问,请联系我们的支持团队。 +

+
+
+ + {/* 版权声明 */} +
+

版权声明

+
+

+ Copyright 2025 美家卡 (meijiaka.cn). All rights reserved. +

+

+ 本软件及其相关文档的所有权利均归美家卡所有。 + 未经授权,不得复制、修改、分发或以其他方式使用本软件。 +

+
+
+ + setShowEnvModal(false)} + />
); }