Skip to content

Commit

Permalink
added version display in the settings component
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaun Cullen committed Sep 5, 2019
1 parent 3203061 commit dea3b06
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
7 changes: 4 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ function createUpdaterWindow() {
if (updaterWindow === null) {
updaterWindow = new BrowserWindow({
icon: path.join(resources, '96x96.png'),
width: 800,
height: 800,
width: 400,
height: 200,
resizable: false,
show: false,
title: 'Updater',
})

updaterWindow.toggleDevTools()
// updaterWindow.toggleDevTools()

}

// win.setMenuBarVisibility(false)
Expand Down
19 changes: 16 additions & 3 deletions src/components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { Component } from 'react'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'

import { MainSessionState, Token, SessionSettings } from '../store/session/types'
import { getCSRFToken } from '../store/session/thunks'
import { getCSRFToken, getApiVersion } from '../store/session/thunks'
import { updateMainSession } from '../store/session/actions'
import { connect } from 'react-redux'
import { AppState } from '../store/'
Expand All @@ -24,19 +24,27 @@ interface DefaultState {
jobManagerUrl: string
s2d2Url: string
s2d2Verified: boolean
tileViewerVersion: string
s2d2Version: string
jobManagerVerified: boolean
version: string
}

const defaultState = {
declare var VERSION: string


const defaultState = {
tileViewerVersion: VERSION,
}


class Settings extends Component<AppProps, AppState & DefaultState> {
constructor (props: AppProps) {
super(props)
console.log('settings constructor running')

this.state = {
...defaultState,
...this.state,
jobManagerUrl: props.settings.jobManagerUrl,
s2d2Url: props.settings.s2d2Url,
Expand Down Expand Up @@ -80,6 +88,8 @@ class Settings extends Component<AppProps, AppState & DefaultState> {
console.log('check CSRF result')
console.log(result)

const apiversion = await getApiVersion(this.state.s2d2Url)

const session = { ...this.props.session }
console.log(session)

Expand All @@ -90,7 +100,8 @@ class Settings extends Component<AppProps, AppState & DefaultState> {
this.props.updateMainSession(session)

this.setState({
s2d2Verified: true
s2d2Verified: true,
s2d2Version: JSON.parse(apiversion).version
})
} else {
session.csrfTokens.s2d2.key = ""
Expand Down Expand Up @@ -129,6 +140,7 @@ class Settings extends Component<AppProps, AppState & DefaultState> {
if (this.state.s2d2Verified) {
return (<div className='verified flexItem2'>
<FontAwesomeIcon icon={'check'} />
<span>{' API version:' + this.state.s2d2Version}</span>
</div>)
} else {
return (<div className='notVerified flexItem2'>
Expand Down Expand Up @@ -173,6 +185,7 @@ class Settings extends Component<AppProps, AppState & DefaultState> {
<div className='main'>
<div className='settings'>
<h1>Settings</h1> <br />
<h5>{this.state.tileViewerVersion}</h5>
<label htmlFor='job_url'>Job Manager API Url</label> <br />
<div className='settingsEntry'>
<input id='job_url' className='job_url' size={50} type='text' value={this.state.jobManagerUrl} onChange={this.updatejobManagerUrl} />
Expand Down
22 changes: 22 additions & 0 deletions src/store/session/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,25 @@ export async function getCSRFToken(apiRootUrl: string): Promise<string> {

return result
}

export async function getApiVersion(apiRootUrl: string): Promise<string> {
const headers = new Headers()

const result = await fetch(`${apiRootUrl}/version/`, {
method: 'GET',
mode: 'cors',
cache: 'default',
headers,
})
.then(response => response.json())
.then(response => {
console.log('Success:', JSON.stringify(response))
return JSON.stringify(response)
})
.catch(err => {
console.log('Something blew up while verifying the API')
return ''
})

return result
}
3 changes: 3 additions & 0 deletions webpack.build.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ module.exports = {
'process.env.NODE_ENV': JSON.stringify('production'),
}),
new MinifyPlugin(),
new webpack.DefinePlugin({
VERSION: JSON.stringify(require("./package.json").version)
}),
],
stats: {
colors: true,
Expand Down
3 changes: 3 additions & 0 deletions webpack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ module.exports = {
new MiniCssExtractPlugin({
filename: 'css/[name].bundle.css',
}),
new webpack.DefinePlugin({
VERSION: JSON.stringify(require("./package.json").version)
}),
],
devtool: 'inline-source-map',
devServer: {
Expand Down

0 comments on commit dea3b06

Please sign in to comment.