@@ -7,6 +7,10 @@ import {useDispatch, useSelector} from "react-redux";
77import Button from "@material-ui/core/Button" ;
88import Typography from "@material-ui/core/Typography" ;
99import BackButton from "../../components/BackButton" ;
10+ import RefreshIcon from "@material-ui/icons/Refresh" ;
11+ import { Updater } from "../../utils/Updater" ;
12+ import UpdateDialog from "../../components/UpdateDialog" ;
13+ import AlertDialog from "../../components/AlertDialog" ;
1014
1115const useStyles = makeStyles ( theme => ( {
1216 content : {
@@ -29,24 +33,50 @@ const useStyles = makeStyles(theme => ({
2933 }
3034} ) ) ;
3135
36+ const os = window . require ( 'os' ) ;
3237const ipcRenderer = window . require ( 'electron' ) . ipcRenderer ;
3338
39+ let appVersion ;
40+
41+ ipcRenderer . on ( 'get-version-reply' , ( e , version ) => {
42+ appVersion = version ;
43+ } ) ;
44+ ipcRenderer . send ( 'get-version' ) ;
45+
3446const About = ( ) => {
3547
3648 const classes = useStyles ( ) ;
3749 const language = useSelector ( state => state . MainReducer . languages [ state . MainReducer . languageIndex ] ) ;
3850 const dispatch = useDispatch ( ) ;
39- let [ appVersion , setAppVersion ] = useState ( "" ) ;
4051
41- ipcRenderer . on ( 'get-version-reply' , ( e , version ) => {
42- setAppVersion ( version ) ;
43- } ) ;
44- ipcRenderer . send ( 'get-version' ) ;
52+ const [ errorMessage , setErrorMessage ] = useState ( null ) ;
53+ const [ loading , setLoading ] = useState ( false ) ;
54+ const [ update , setUpdate ] = useState ( null ) ;
4555
4656 useEffect ( ( ) => {
4757 dispatch ( { type : 'SET_ACTIVE_LISTITEM' , index : 5 } ) ;
4858 } , [ dispatch ] ) ;
4959
60+ /**
61+ * Check for application updates
62+ * @returns {Promise<void> }
63+ */
64+ const checkForUpdates = async ( ) => {
65+ if ( loading ) return ;
66+
67+ setLoading ( true ) ;
68+ setUpdate ( null ) ;
69+ setErrorMessage ( null ) ;
70+
71+ const data = await Updater ( os ) ;
72+ if ( data && data . length > 0 ) {
73+ setErrorMessage ( data ) ;
74+ } else {
75+ setUpdate ( data ) ;
76+ }
77+ setLoading ( false ) ;
78+ } ;
79+
5080 return (
5181 < div >
5282 < div className = { classes . heroContent } >
@@ -60,41 +90,48 @@ const About = () => {
6090 </ Container >
6191 </ div >
6292 < main className = { classes . content } >
93+ { update && update . updateAvailable ? (
94+ < UpdateDialog downloadUrl = { update . updateUrl } infoUrl = { update . infoUrl }
95+ newVersion = { update . version } /> ) : null }
96+ { update && ! update . updateAvailable ? (
97+ < AlertDialog title = { language . noUpdatesTitle } content = { language . noUpdatesMessage } /> ) : null }
98+ { errorMessage && errorMessage . length > 0 ? (
99+ < AlertDialog title = { language . errorTitle } content = { errorMessage } /> ) : null }
63100 < Container maxWidth = "lg" className = { classes . container } >
64- < Grid container spacing = { 2 } >
65- < Grid item xs = { 12 } md = { 12 } lg = { 12 } >
66- < Typography component = "h2" variant = "h5" color = "primary" gutterBottom >
67- < BackButton />
68- { language . appName } - { language . about }
69- </ Typography >
70- < Paper className = { classes . paper } >
71- < div style = { { whiteSpace : 'pre-wrap' } } >
72- < p >
73- { language . aboutMessage . replace ( "{x}" , appVersion ) }
74- </ p >
75- </ div >
101+ < Typography component = "h2" variant = "h5" color = "primary" gutterBottom >
102+ < BackButton />
103+ { language . appName } - { language . about }
104+ </ Typography >
105+ < Paper className = { classes . paper } >
106+ < div style = { { whiteSpace : 'pre-wrap' } } >
107+ < p >
108+ { language . aboutMessage . replace ( "{x}" , appVersion ) }
109+ </ p >
110+ </ div >
76111
77- < Grid container spacing = { 2 } >
78- < Grid item xs = { 12 } md = { 6 } lg = { 6 } >
79- < Button target = { "_blank" }
80- style = { { width : '100%' } }
81- href = { "http://codedead.com/Software/DeadHash/gpl.pdf" }
82- color = { "primary" } variant = { "contained" } >
83- { language . license }
84- </ Button >
85- </ Grid >
86- < Grid item xs = { 12 } md = { 6 } lg = { 6 } >
87- < Button target = { "_blank" }
88- style = { { width : '100%' } }
89- href = { "http://codedead.com" }
90- color = { "primary" } variant = { "contained" } >
91- { language . codedead }
92- </ Button >
93- </ Grid >
94- </ Grid >
95- </ Paper >
112+ < Grid container spacing = { 2 } >
113+ < Grid item xs = { 12 } md = { 6 } lg = { 6 } >
114+ < Button target = { "_blank" }
115+ style = { { width : '100%' } }
116+ href = { "http://codedead.com/Software/DeadHash/gpl.pdf" }
117+ color = { "primary" } variant = { "contained" } >
118+ { language . license }
119+ </ Button >
120+ </ Grid >
121+ < Grid item xs = { 12 } md = { 6 } lg = { 6 } >
122+ < Button target = { "_blank" }
123+ style = { { width : '100%' } }
124+ href = { "http://codedead.com" }
125+ color = { "primary" } variant = { "contained" } >
126+ { language . codedead }
127+ </ Button >
128+ </ Grid >
96129 </ Grid >
97- </ Grid >
130+ </ Paper >
131+ < Button className = { classes . button } color = { "primary" } onClick = { ( ) => checkForUpdates ( ) } >
132+ < RefreshIcon />
133+ { language . checkForUpdates }
134+ </ Button >
98135 </ Container >
99136 </ main >
100137 </ div >
0 commit comments