Skip to content

Commit 0e2a5de

Browse files
committed
* Simplified DOM of some pages
* Added ability to check for updates on about page * Fixed event leak
1 parent 51276e0 commit 0e2a5de

File tree

7 files changed

+189
-158
lines changed

7 files changed

+189
-158
lines changed

src/components/App/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import Topbar from "../Topbar";
99
import About from "../../routes/About";
1010
import File from "../../routes/File";
1111
import Text from "../../routes/Text";
12-
import Drawerbar from "../Drawerbar";
1312
import {CssBaseline} from "@material-ui/core";
1413
import DropZone from "../DropZone";
1514

src/components/Topbar/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useState} from "react";
1+
import React, {useState, useEffect} from "react";
22
import {makeStyles} from '@material-ui/core/styles';
33
import AppBar from '@material-ui/core/AppBar';
44
import Toolbar from '@material-ui/core/Toolbar';
@@ -59,13 +59,18 @@ const Topbar = () => {
5959
const [drawerOpen, setDrawerOpen] = useState(false);
6060
const languageOpen = Boolean(anchorEl);
6161

62-
ipcRenderer.on("window-maximized", () => {
62+
const fullScreenEvent = () => {
6363
setFullScreen(true);
64-
})
64+
}
6565

66-
ipcRenderer.on("window-unmaximized", () => {
66+
const exitFullScreenEvent = () => {
6767
setFullScreen(false);
68-
});
68+
}
69+
70+
useEffect(() => {
71+
ipcRenderer.on("window-maximized", fullScreenEvent);
72+
ipcRenderer.on("window-unmaximized", exitFullScreenEvent);
73+
}, []);
6974

7075
/**
7176
* Open the drawer

src/routes/About/index.js

Lines changed: 74 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import {useDispatch, useSelector} from "react-redux";
77
import Button from "@material-ui/core/Button";
88
import Typography from "@material-ui/core/Typography";
99
import 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

1115
const useStyles = makeStyles(theme => ({
1216
content: {
@@ -29,24 +33,50 @@ const useStyles = makeStyles(theme => ({
2933
}
3034
}));
3135

36+
const os = window.require('os');
3237
const 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+
3446
const 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>

src/routes/File/index.js

Lines changed: 51 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {useDispatch, useSelector} from "react-redux";
33
import {Checkbox, FormControlLabel, makeStyles, Paper} from "@material-ui/core";
44
import Container from "@material-ui/core/Container";
55
import Typography from "@material-ui/core/Typography";
6-
import Grid from "@material-ui/core/Grid";
76
import Button from "@material-ui/core/Button";
87
import GridList from "../../components/GridList";
98
import Hash from "../../components/Hash";
@@ -156,64 +155,60 @@ const File = () => {
156155
</div>
157156
<main className={classes.content}>
158157
<Container className={classes.container}>
159-
<Grid container spacing={2}>
160-
<Grid item xs={12} md={12} lg={12}>
161-
<Typography component="h2" variant="h5" color="primary" gutterBottom>
162-
<BackButton/>
163-
{language.input}
164-
</Typography>
165-
<Paper className={classes.paper}>
166-
<TextField
167-
margin="normal"
168-
onClick={() => fileRef.current.click()}
169-
disabled
170-
id="filled-disabled"
171-
value={file && file.path ? file.path : ""}
172-
variant="outlined"
173-
/>
174-
175-
<input ref={fileRef} type="file" onChange={onFileChange}
176-
style={{display: 'none'}}/>
177-
178-
<Button color={"primary"} variant={"contained"}
179-
onClick={() => fileRef.current.click()}>{language.select}</Button>
180-
181-
<FormControlLabel
182-
control={
183-
<Checkbox
184-
checked={compare}
185-
onChange={(e) => setCompare(e.target.checked)}
186-
value="compare"
187-
color="primary"
188-
/>
189-
}
190-
label={language.compare}
158+
<Typography component="h2" variant="h5" color="primary" gutterBottom>
159+
<BackButton/>
160+
{language.input}
161+
</Typography>
162+
<Paper className={classes.paper}>
163+
<TextField
164+
margin="normal"
165+
onClick={() => fileRef.current.click()}
166+
disabled
167+
id="filled-disabled"
168+
value={file && file.path ? file.path : ""}
169+
variant="outlined"
170+
/>
171+
172+
<input ref={fileRef} type="file" onChange={onFileChange}
173+
style={{display: 'none'}}/>
174+
175+
<Button color={"primary"} variant={"contained"}
176+
onClick={() => fileRef.current.click()}>{language.select}</Button>
177+
178+
<FormControlLabel
179+
control={
180+
<Checkbox
181+
checked={compare}
182+
onChange={(e) => setCompare(e.target.checked)}
183+
value="compare"
184+
color="primary"
191185
/>
192-
{compareField}
193-
</Paper>
194-
{hashes && hashes.length > 0 ? (
195-
<>
196-
<Button className={classes.button} color={"primary"} variant={"contained"}
197-
onClick={() => clearData()}>
198-
{language.clear}
199-
</Button>
200-
201-
<CsvExport fileName={"DeadHash Export " + new Date() + ".csv"} data={hashes}>
202-
<Button className={classes.button} color={"primary"} variant={"contained"}
203-
style={{marginLeft: 5}}>
204-
{language.export}
205-
</Button>
206-
</CsvExport>
207-
</>
208-
209-
) : null}
186+
}
187+
label={language.compare}
188+
/>
189+
{compareField}
190+
</Paper>
191+
{hashes && hashes.length > 0 ? (
192+
<>
210193
<Button className={classes.button} color={"primary"} variant={"contained"}
211-
disabled={!file || file.length === 0}
212-
style={{float: 'right'}} onClick={async () => calculateHashes()}>
213-
{language.calculate}
194+
onClick={() => clearData()}>
195+
{language.clear}
214196
</Button>
215-
</Grid>
216-
</Grid>
197+
198+
<CsvExport fileName={"DeadHash Export " + new Date() + ".csv"} data={hashes}>
199+
<Button className={classes.button} color={"primary"} variant={"contained"}
200+
style={{marginLeft: 5}}>
201+
{language.export}
202+
</Button>
203+
</CsvExport>
204+
</>
205+
206+
) : null}
207+
<Button className={classes.button} color={"primary"} variant={"contained"}
208+
disabled={!file || file.length === 0}
209+
style={{float: 'right'}} onClick={async () => calculateHashes()}>
210+
{language.calculate}
211+
</Button>
217212
{output}
218213
</Container>
219214
</main>

src/routes/Settings/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const Settings = () => {
145145
<main className={classes.content}>
146146
{update && update.updateAvailable ? (
147147
<UpdateDialog downloadUrl={update.updateUrl} infoUrl={update.infoUrl}
148-
newVersion={update.version} />) : null}
148+
newVersion={update.version}/>) : null}
149149
{update && !update.updateAvailable ? (
150150
<AlertDialog title={language.noUpdatesTitle} content={language.noUpdatesMessage}/>) : null}
151151
{errorMessage && errorMessage.length > 0 ? (

0 commit comments

Comments
 (0)