From 61258d4b6473addd3757f360c15b1b2a67f61761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=BCchele?= Date: Fri, 24 Aug 2018 03:44:29 -0700 Subject: [PATCH] log correct version Summary: Instead of reading version number for logging from `package.json` it is now fetched via electron. We usually don't update our version number in package.json and therefore all logs showed the same version number. the version number from `app.getVersion()` is set during the build process and reflects the actual version number that is used. Removes unused `` component. Reviewed By: jknoxville Differential Revision: D9495745 fbshipit-source-id: 6999ea23a1e4f90d6591b3695e01a803a5f3ff85 --- src/chrome/Version.js | 92 ------------------------------------------- 1 file changed, 92 deletions(-) delete mode 100644 src/chrome/Version.js diff --git a/src/chrome/Version.js b/src/chrome/Version.js deleted file mode 100644 index f85a62cb8..000000000 --- a/src/chrome/Version.js +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Copyright 2018-present Facebook. - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * @format - */ - -import {Component, FlexRow, colors, LoadingIndicator, styled} from 'sonar'; -import {version} from '../../package.json'; -import {remote} from 'electron'; -import * as path from 'path'; -import {userInfo} from 'os'; -import * as fs from 'fs'; - -const VERSION_URL = - 'https://interngraph.intern.facebook.com/sonar/version?app=543626909362475&token=AeNRaexWgPooanyxG0'; - -type VersionState = { - status: 'unknown' | 'outdated' | 'latest' | 'updated' | 'errored', -}; - -export default class Version extends Component<{}, VersionState> { - state = { - status: 'unknown', - }; - - static Container = styled(FlexRow)({ - alignItems: 'center', - marginRight: 7, - marginLeft: 7, - marginTop: -1, - color: colors.light50, - }); - - static UpdatedContainer = styled(FlexRow)({ - backgroundColor: colors.blackAlpha10, - borderRadius: '999em', - padding: '2px 6px', - marginLeft: 7, - color: colors.light80, - '&:hover': { - backgroundColor: colors.blackAlpha15, - }, - }); - - componentDidMount() { - this.watchUpdates(); - - this.checkVersion().catch(() => { - this.setState({status: 'errored'}); - }); - } - - async watchUpdates() { - fs.watch(path.join(userInfo().homedir, '.sonar-desktop'), () => - this.setState({status: 'updated'}), - ); - } - - async checkVersion() { - const req = await fetch(VERSION_URL); - const json = await req.json(); - this.setState({status: json.version === version ? 'latest' : 'outdated'}); - } - - onClick = () => { - // mark the app to relaunch once killed - remote.app.relaunch(); - // close the current window - remote.getCurrentWindow().destroy(); - }; - - render() { - const {status} = this.state; - return ( - - {version} - {status === 'outdated' && [ - - - , - 'Updating...', - ]} - {status === 'updated' && ( - - Restart Sonar - - )} - - ); - } -}