From 84c05d441daf1bc7de396b6b0dc2bbdfaaf9123c Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Tue, 19 Jan 2021 07:07:33 -0800 Subject: [PATCH] Turn update message into notification Summary: Based on discussion in D25805957 (https://github.com/facebook/flipper/commit/ffeb47ed7537d2d9d77bc8f9e664f7d5cb1c8f4a), instead of showing a warning icon in the siderail, Flipper now shows a notification if there is a version / launcher issue or an update available Reviewed By: nikoant Differential Revision: D25924534 fbshipit-source-id: 625e46e41d9aa58f49e8bb77e5c513de0ddfbd6a --- desktop/app/src/chrome/UpdateIndicator.tsx | 181 ++++++++++----------- 1 file changed, 85 insertions(+), 96 deletions(-) diff --git a/desktop/app/src/chrome/UpdateIndicator.tsx b/desktop/app/src/chrome/UpdateIndicator.tsx index eba31fe53..cc49cf16d 100644 --- a/desktop/app/src/chrome/UpdateIndicator.tsx +++ b/desktop/app/src/chrome/UpdateIndicator.tsx @@ -7,123 +7,112 @@ * @format */ -import {LauncherMsg} from '../reducers/application'; -import {FlexRow, Glyph, styled} from '../ui'; -import {Tooltip} from 'antd'; +import {notification, Typography} from 'antd'; import isProduction from '../utils/isProduction'; import { checkForUpdate, VersionCheckResult, } from '../utils/publicVersionChecker'; import {reportPlatformFailures} from '../utils/metrics'; -import React from 'react'; -import {shell} from 'electron'; +import React, {useEffect, useState} from 'react'; import config from '../utils/processConfig'; import fbConfig from '../fb-stubs/config'; import {useStore} from '../utils/useStore'; import {remote} from 'electron'; -import {theme} from 'flipper-plugin'; + const version = remote.app.getVersion(); -const Container = styled(FlexRow)({ - alignItems: 'center', -}); +export default function UpdateIndicator() { + const [versionCheckResult, setVersionCheckResult] = useState< + VersionCheckResult + >({kind: 'up-to-date'}); + const launcherMsg = useStore((state) => state.application.launcherMsg); -type Props = { - launcherMsg: LauncherMsg; - version: string; -}; - -type State = { - versionCheckResult: VersionCheckResult; -}; - -function getSeverityColor(severity: 'warning' | 'error'): string { - switch (severity) { - case 'warning': - return theme.warningColor; - case 'error': - return theme.errorColor; - } -} - -class UpdateIndicatorImpl extends React.PureComponent { - state = { - versionCheckResult: {kind: 'up-to-date'} as VersionCheckResult, - }; - - renderMessage(): React.ReactNode { - if (this.props.launcherMsg.message.length == 0) { - return null; + // Effect to show notification if details change + useEffect(() => { + switch (versionCheckResult.kind) { + case 'up-to-date': + break; + case 'update-available': + console.log( + `Flipper update available: ${versionCheckResult.version} at ${versionCheckResult.url}`, + ); + notification.info({ + placement: 'bottomLeft', + key: 'flipperupdatecheck', + message: 'Update available', + description: ( + <> + Flipper version {versionCheckResult.version} is now available. + {fbConfig.isFBBuild ? ( + <> + {' '} + Pull ~/fbsource and/or restart Flipper to update + to the latest version. + + ) : ( + <> + {' '} + Click to{' '} + + download + + . + + )} + + ), + duration: null, // no auto close + }); + break; + case 'error': + console.warn( + `Failed to check for Flipper update: ${versionCheckResult.msg}`, + ); + break; } + }, [versionCheckResult]); - return ( - - - - - - ); - } - - renderUpdateIndicator(): React.ReactNode { - const result = this.state.versionCheckResult; - if (result.kind !== 'update-available') { - return null; - } - - const container = ( - - shell.openExternal(result.url)} - role="button" - tabIndex={0}> - - - - ); - return ( - - ); - } - - componentDidMount() { - if (isProduction() && (config().launcherEnabled || !fbConfig.isFBBuild)) { + // trigger the update check, unless there is a launcher message already + useEffect(() => { + if (launcherMsg && launcherMsg.message) { + if (launcherMsg.severity === 'error') { + notification.error({ + placement: 'bottomLeft', + key: 'launchermsg', + message: 'Launch problem', + description: launcherMsg.message, + duration: null, + }); + } else { + notification.warning({ + placement: 'bottomLeft', + key: 'launchermsg', + message: 'Flipper version warning', + description: launcherMsg.message, + duration: null, + }); + } + } else if ( + isProduction() && + (config().launcherEnabled || !fbConfig.isFBBuild) + ) { reportPlatformFailures( - checkForUpdate(this.props.version).then((res) => { + checkForUpdate(version).then((res) => { if (res.kind === 'error') { - console.warn('Version check failure: ', res.msg); - throw new Error(res.msg); + console.warn('Version check failure: ', res); + setVersionCheckResult({ + kind: 'error', + msg: res.msg, + }); + } else { + setVersionCheckResult(res); } - - this.setState({versionCheckResult: res}); }), 'publicVersionCheck', ); } - } + }, [launcherMsg]); - render(): React.ReactNode { - return ( - <> - {this.renderMessage()} - {this.renderUpdateIndicator()} - - ); - } -} - -export default function UpdateIndicator() { - const launcherMsg = useStore((state) => state.application.launcherMsg); - return ; + return null; }