Skip to content
This repository has been archived by the owner on May 5, 2020. It is now read-only.

Commit

Permalink
finished "update app" message feature
Browse files Browse the repository at this point in the history
  • Loading branch information
JoJordens committed Jan 23, 2017
1 parent f606a61 commit 3155dad
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
10 changes: 8 additions & 2 deletions src/app/css/components/_updateMessage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
justify-content: center;
align-items: center;
top: 0;
span {
> span {
border-radius: 5px;
padding: 10px;
background-origin: #e6e6e6;
background-color: #e6e6e6;
display: flex;
align-items: center;
flex-flow: column;
a {
color: blue;
}
}
}
1 change: 1 addition & 0 deletions src/app/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<div id="app"></div>
<script type="text/javascript">
window.ipcRenderer = require('electron').ipcRenderer
window.shell = require('electron').shell
</script>
<script type="text/javascript" src="js/app.js"></script>
</body>
Expand Down
24 changes: 18 additions & 6 deletions src/app/js/components/UpdateMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,40 @@ class UpdateMessage extends Component {

this.state = {
visible: false,
error: false
error: false,
latest: ''
}
}

componentDidMount() {
ipcRenderer.on('showUpdateNotification', (event, url) => {
this.setState({visible: true, error: false})
componentDidMount () {
ipcRenderer.on('showUpdateNotification', (event, latest) => {
this.setState({visible: true, error: false, latest})
})

ipcRenderer.on('showUpdateErrorNotification', (event, error) => {
this.setState({visible: true, error})
})
}

openUrl () {
shell.openExternal("https://github.com/AppSaloon/socket.io-tester/releases")
}

render () {
const state = this.state
const error = state.error
const errorMessage = Object.prototype.toString.apply(error).slice(8, -1) === 'Object' ? `${error.message} - ${error.documentation_url}` || `Error: ${JSON.stringify(error)}` : `Error: ${JSON.stringify(error)}`
return (
<div className={`update-message ${state.visible ? '' : 'hidden'}`}>
<div className={`update-message ${state.visible ? '' : 'hidden'}`} onClick={ () => this.setState({visible: false}) }>
{ !state.error ?
<span>update please</span>
<span onClick={ e => e.stopPropagation() }>
<span>{`This version of the app is outdated, the latest version is ${state.latest}.`}</span>
<span>
<span>Get it </span>
<a onClick={this.openUrl}>here</a>
<span>.</span>
</span>
</span>
:
<span>{state.error.message || ''}</span>
}
Expand Down
15 changes: 5 additions & 10 deletions src/electron/checkVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ function getRelease () {

res.on("end", function () {
const body = Buffer.concat(chunks)
if ( res.statusCode !== 200 ) return reject(body.toString())
return resolve(body.toString())
if ( res.statusCode !== 200 ) return reject(JSON.parse(body.toString()))
return resolve(JSON.parse(body.toString()))
})
})

Expand All @@ -37,16 +37,11 @@ async function checkVersion (appWindow) {
win = appWindow
try {
const release = await getRelease()
if ( Object.prototype.toString.apply(release).slice(8, -1) === 'Object' && release.name === version )
sendMessageToWindow({channel: 'showUpdateNotification'})
if ( Object.prototype.toString.apply(release).slice(8, -1) === 'Object' && release.name !== `v${version}` )
sendMessageToWindow({channel: 'showUpdateNotification', message: release.name})
}
catch (error) {
let parsedError = error
try {
parsedError = JSON.parse(error)
}
catch (error) {}
sendMessageToWindow({channel: 'showUpdateErrorNotification', message: parsedError})
sendMessageToWindow({channel: 'showUpdateErrorNotification', message: error})
}
}

Expand Down

0 comments on commit 3155dad

Please sign in to comment.