@@ -4,16 +4,19 @@ import { observer } from "mobx-react-lite";
44import React , { useEffect , useState } from "react" ;
55import { ipcAsyncByMainWindow , ipcReceive , ipcReceiveRemove } from "../../utils/ipc" ;
66import { useTranslation } from "react-i18next" ;
7+ import { update } from "flat-types" ;
78
89export interface AppUpgradeModalProps {
9- /** open modal when newVersion has truthy value */
10- newVersion ?: string ;
11- /** close modal */
10+ updateInfo :
11+ | ( update . UpdateCheckInfo & {
12+ hasNewVersion : true ;
13+ } )
14+ | null ;
1215 onClose : ( ) => void ;
1316}
1417
1518export const AppUpgradeModal = observer < AppUpgradeModalProps > ( function AppUpgradeModal ( {
16- newVersion ,
19+ updateInfo ,
1720 onClose,
1821} ) {
1922 const { t } = useTranslation ( ) ;
@@ -22,7 +25,7 @@ export const AppUpgradeModal = observer<AppUpgradeModalProps>(function AppUpgrad
2225 const [ upgradeFail , setUpgradeFail ] = useState ( false ) ;
2326
2427 useEffect ( ( ) => {
25- if ( showUpgradeProgress ) {
28+ if ( showUpgradeProgress && updateInfo !== null ) {
2629 ipcReceive ( "update-progress" , args => {
2730 if ( args . status ) {
2831 setUpgradePercent ( args . percent ) ;
@@ -31,12 +34,14 @@ export const AppUpgradeModal = observer<AppUpgradeModalProps>(function AppUpgrad
3134 }
3235 } ) ;
3336
34- ipcAsyncByMainWindow ( "start-update" , undefined ) ;
37+ ipcAsyncByMainWindow ( "start-update" , {
38+ prereleaseTag : updateInfo . prereleaseTag ,
39+ } ) ;
3540 }
3641 return ( ) => {
3742 ipcReceiveRemove ( "update-progress" ) ;
3843 } ;
39- } , [ showUpgradeProgress ] ) ;
44+ } , [ showUpgradeProgress , updateInfo ] ) ;
4045
4146 const renderModalTitle = ( ) : React . ReactNode => {
4247 return < div className = "app-upgrade-modal-title" > { t ( "version-updates" ) } </ div > ;
@@ -58,7 +63,7 @@ export const AppUpgradeModal = observer<AppUpgradeModalProps>(function AppUpgrad
5863 maskClosable = { false }
5964 title = { renderModalTitle ( ) }
6065 footer = { [ ] }
61- visible = { Boolean ( newVersion ) }
66+ visible = { updateInfo !== null }
6267 onCancel = { cancelUpgrade }
6368 wrapClassName = "app-upgrade-modal-container"
6469 closable = { false }
@@ -68,11 +73,11 @@ export const AppUpgradeModal = observer<AppUpgradeModalProps>(function AppUpgrad
6873 < span className = "app-upgrade-modal-font" >
6974 { t ( "downloading" ) } ({ upgradePercent . toFixed ( 2 ) } %)...
7075 </ span >
71- < div className = "app-upgrade-modal-progress" > </ div >
76+ < div className = "app-upgrade-modal-progress" / >
7277 < div
7378 className = "app-upgrade-active-progress"
7479 style = { { width : `${ upgradePercent } %` } }
75- > </ div >
80+ / >
7681 { upgradeFail && (
7782 < div >
7883 < span className = "app-upgrade-modal-font" >
@@ -89,7 +94,7 @@ export const AppUpgradeModal = observer<AppUpgradeModalProps>(function AppUpgrad
8994 ) : (
9095 < div >
9196 < span className = "app-upgrade-modal-font" >
92- { t ( "new-version-tips" , { version : newVersion || " " } ) }
97+ { t ( "new-version-tips" , { version : updateInfo ?. version || " " } ) }
9398 </ span >
9499 < div className = "app-upgrade-modal-btn" >
95100 < Button type = "primary" onClick = { upgradeStart } >
0 commit comments