-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check new version on github and notify user
- Loading branch information
Showing
12 changed files
with
131 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
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,42 @@ | ||
import {SchedulerService} from "../../../../common/SchedulerService"; | ||
import {EventEmitter} from 'events'; | ||
import {default as fetch} from 'node-fetch'; | ||
|
||
export class UpdateService extends EventEmitter { | ||
public static CURRENT_VERSION_EVENT = 'CURRENT_VERSION_EVENT'; | ||
|
||
private schedulerService: SchedulerService; | ||
|
||
constructor() { | ||
super(); | ||
this.schedulerService = new SchedulerService(() => { | ||
this.retrieveVersion(); | ||
}, 60_000 * 10); | ||
} | ||
|
||
public start(): void { | ||
this.retrieveVersion(); | ||
this.schedulerService.start(); | ||
console.log("UpdateService started"); | ||
} | ||
|
||
public stop(): void { | ||
this.schedulerService.stop(); | ||
console.log("UpdateService stopped"); | ||
} | ||
|
||
|
||
private async retrieveVersion(): Promise<void> { | ||
try { | ||
const response = await fetch(`https://api.github.com/repos/ErgoWallet/ergowallet-desktop/releases/latest`); | ||
if (!response.ok) { | ||
console.error(new Error(`${response.status}: ${response.statusText}`)); | ||
} | ||
const body = await response.json(); | ||
|
||
this.emit(UpdateService.CURRENT_VERSION_EVENT, body); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
} |
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,35 @@ | ||
import {useSelector} from "react-redux"; | ||
import {RootState} from "../../store/root-reducer"; | ||
import * as React from "react"; | ||
import {Button, Snackbar} from "@material-ui/core"; | ||
import {Alert} from "@material-ui/lab"; | ||
import {shell} from 'electron'; | ||
import * as semver from 'semver'; | ||
|
||
const NewVersionNotification = () => { | ||
const app = useSelector((state: RootState) => state.app); | ||
if (!app.latestVersion) { | ||
return null; | ||
} | ||
if (semver.gte(app.version, app.latestVersion)) { | ||
return null; | ||
} | ||
|
||
const openDownloadPage = () => { | ||
shell.openExternal('https://ergowallet.io'); | ||
}; | ||
|
||
return ( | ||
<Snackbar open> | ||
<Alert | ||
action={( | ||
<Button onClick={openDownloadPage}>Download</Button> | ||
)} | ||
severity="info"> | ||
New version is available. | ||
</Alert> | ||
</Snackbar> | ||
); | ||
} | ||
|
||
export default NewVersionNotification; |
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