1+ import { invoke } from "@tauri-apps/api/core" ;
12import { check , Update } from "@tauri-apps/plugin-updater" ;
23import { BookOpen , Download , MessageCircleCode } from "lucide-react" ;
34import React from "react" ;
@@ -8,14 +9,19 @@ import icon from "../../assets/icon.png";
89import QQ from "../../assets/qq.svg?react" ;
910import versions from "../../assets/versions.json" ;
1011import Button from "../../components/Button" ;
12+ import { Settings } from "../../core/service/Settings" ;
1113import { getAppVersion } from "../../utils/otherApi" ;
14+ import { SettingField } from "./_field" ;
1215
1316export default function About ( ) {
1417 const [ version , setVersion ] = React . useState ( "" ) ;
1518 const [ versionName , setVersionName ] = React . useState ( "" ) ;
1619 const [ versionNameEn , setVersionNameEn ] = React . useState ( "" ) ;
1720 const [ update , setUpdate ] = React . useState < Update | null > ( null ) ;
1821 const [ updating , setUpdating ] = React . useState ( false ) ;
22+ const [ newVersionFileSize , setNewVersionFileSize ] = React . useState ( 0 ) ;
23+ const [ newVersionDownloadedSize , setNewVersionDownloadedSize ] = React . useState ( 0 ) ;
24+ const [ updateChannel ] = Settings . use ( "updateChannel" ) ;
1925 const { t, i18n } = useTranslation ( "about" ) ;
2026
2127 React . useEffect ( ( ) => {
@@ -34,9 +40,14 @@ export default function About() {
3440 setVersionNameEn ( "Unknown Version" ) ;
3541 }
3642 } ) ;
37- check ( ) . then ( setUpdate ) ;
3843 } , [ ] ) ;
3944
45+ React . useEffect ( ( ) => {
46+ invoke ( "set_update_channel" , { channel : updateChannel } )
47+ . then ( ( ) => check ( ) )
48+ . then ( setUpdate ) ;
49+ } , [ updateChannel ] ) ;
50+
4051 return (
4152 < div className = "flex h-full" >
4253 < div className = "flex w-64 flex-col items-center justify-center gap-4" >
@@ -52,13 +63,25 @@ export default function About() {
5263 < Button
5364 onClick = { ( ) => {
5465 setUpdating ( true ) ;
55- update ?. downloadAndInstall ( ) . then ( ( ) => {
56- setUpdating ( false ) ;
66+ update ?. downloadAndInstall ( ( event ) => {
67+ switch ( event . event ) {
68+ case "Started" :
69+ setNewVersionFileSize ( event . data . contentLength ?? 0 ) ;
70+ break ;
71+ case "Progress" :
72+ setNewVersionDownloadedSize ( ( prev ) => prev + ( event . data . chunkLength ?? 0 ) ) ;
73+ break ;
74+ case "Finished" :
75+ setUpdating ( false ) ;
76+ break ;
77+ }
5778 } ) ;
5879 } }
5980 >
6081 < Download />
61- { updating ? t ( "updater.downloading" ) : `${ t ( "updater.available" ) } : ${ update . version } ` }
82+ { updating
83+ ? `${ t ( "updater.downloading" ) } : ${ ( ( newVersionDownloadedSize / newVersionFileSize ) * 100 ) . toFixed ( ) } %`
84+ : `${ t ( "updater.available" ) } : ${ update . version } ` }
6285 </ Button >
6386 ) }
6487 < div className = "flex flex-wrap justify-center gap-2" >
@@ -91,6 +114,7 @@ export default function About() {
91114 </ div >
92115 </ div >
93116 < div className = "text-panel-text flex flex-1 flex-col gap-4 overflow-auto" >
117+ < SettingField icon = { < Download /> } settingKey = "updateChannel" type = "select" />
94118 < Paragraph i18nKey = "intro" />
95119 < Paragraph i18nKey = "ideaSources" />
96120 < Paragraph i18nKey = "team" />
0 commit comments