This repository has been archived by the owner on Jan 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Display update dialog in React, store update infos in Redux
- Loading branch information
1 parent
15811a7
commit 4e6fc19
Showing
7 changed files
with
122 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
owner: UnstoppableSwap | ||
repo: unstoppableswap-gui | ||
provider: github | ||
releaseType: prerelease | ||
updaterCacheDirName: unstoppableswap-gui-updater |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import SystemUpdateIcon from '@material-ui/icons/SystemUpdate'; | ||
import { | ||
Dialog, | ||
DialogTitle, | ||
DialogContent, | ||
DialogContentText, | ||
DialogActions, | ||
Button, | ||
} from '@material-ui/core'; | ||
import { UpdateInfo } from 'electron-updater'; | ||
import { useAppDispatch, useAppSelector } from 'store/hooks'; | ||
import { updateShownToUser } from 'store/features/updateSlice'; | ||
|
||
export default function UpdaterDialog() { | ||
const dispatch = useAppDispatch(); | ||
const updateNotification: UpdateInfo | null = useAppSelector( | ||
(state) => state.update.updateNotification | ||
); | ||
|
||
if (updateNotification == null) return null; | ||
|
||
function hideNotification() { | ||
dispatch(updateShownToUser()); | ||
} | ||
|
||
function openDownloadUrl() { | ||
const downloadUrl = `https://github.com/UnstoppableSwap/unstoppableswap-gui/releases/tag/v${updateNotification!.version}`; | ||
window.open(downloadUrl, '_blank'); | ||
hideNotification(); | ||
} | ||
|
||
return ( | ||
<Dialog | ||
fullWidth | ||
maxWidth="xs" | ||
open={Boolean(updateNotification)} | ||
onClose={() => hideNotification()} | ||
> | ||
<DialogTitle>Update Available</DialogTitle> | ||
<DialogContent> | ||
<DialogContentText> | ||
A new version (v{updateNotification.version}) of the software was | ||
released on{' '} | ||
{new Date(updateNotification.releaseDate).toLocaleDateString()}. | ||
Please download and install the update manually to benefit from new | ||
features and enhancements. Staying updated ensures you have the latest | ||
improvements and security fixes. | ||
</DialogContentText> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button | ||
variant="text" | ||
color="default" | ||
onClick={() => hideNotification()} | ||
> | ||
Remind me later | ||
</Button> | ||
<Button | ||
endIcon={<SystemUpdateIcon />} | ||
variant="contained" | ||
onClick={openDownloadUrl} | ||
color="primary" | ||
> | ||
Download | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; | ||
import { UpdateInfo } from 'electron-updater'; | ||
|
||
export interface UpdateState { | ||
updateNotification: UpdateInfo | null; | ||
} | ||
|
||
const initialState: UpdateState = { | ||
updateNotification: null, | ||
}; | ||
|
||
const updateSlice = createSlice({ | ||
name: 'update', | ||
initialState, | ||
reducers: { | ||
updateReceived: (state, action: PayloadAction<UpdateInfo>) => { | ||
state.updateNotification = action.payload; | ||
}, | ||
updateShownToUser: (state) => { | ||
state.updateNotification = null; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { updateReceived, updateShownToUser } = updateSlice.actions; | ||
|
||
export default updateSlice.reducer; |