From 72a92e1380414de0f28c9becb522e515897bd0a4 Mon Sep 17 00:00:00 2001 From: Andrey Goncharov Date: Thu, 23 Nov 2023 04:08:07 -0800 Subject: [PATCH] Shutdown Flipper when new version is downloaded Reviewed By: passy Differential Revision: D51527986 fbshipit-source-id: d4cf1ec82070821afff5c9cdee5a85cb1421a7ef --- .../src/chrome/UpdateIndicator.tsx | 51 ++++++++++++++----- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/desktop/flipper-ui-core/src/chrome/UpdateIndicator.tsx b/desktop/flipper-ui-core/src/chrome/UpdateIndicator.tsx index fdaaa3851..108dc4429 100644 --- a/desktop/flipper-ui-core/src/chrome/UpdateIndicator.tsx +++ b/desktop/flipper-ui-core/src/chrome/UpdateIndicator.tsx @@ -7,7 +7,7 @@ * @format */ -import {notification, Typography} from 'antd'; +import {Button, notification, Typography} from 'antd'; import isProduction from '../utils/isProduction'; import {reportPlatformFailures, ReleaseChannel} from 'flipper-common'; import React, {useEffect, useState} from 'react'; @@ -91,17 +91,29 @@ export default function UpdateIndicator() { isProduction() ) { reportPlatformFailures( - checkForUpdate(version).then((res) => { - if (res.kind === 'error') { - console.warn('Version check failure: ', res); + checkForUpdate(version) + .then((res) => { + if (res.kind === 'error') { + throw new Error(res.msg); + } + if (res.kind === 'up-to-date') { + setVersionCheckResult(res); + return; + } + + return getRenderHostInstance() + .flipperServer.exec('fetch-new-version', res.version) + .then(() => { + setVersionCheckResult(res); + }); + }) + .catch((e) => { + console.warn('Version check failure: ', e); setVersionCheckResult({ kind: 'error', - msg: res.msg, + msg: e, }); - } else { - setVersionCheckResult(res); - } - }), + }), 'publicVersionCheck', ); } @@ -114,18 +126,31 @@ export function getUpdateAvailableMessage(versionCheckResult: { url: string; version: string; }): React.ReactNode { + const {launcherSettings} = getRenderHostInstance().serverConfig; + + const shutdownFlipper = () => { + getRenderHostInstance().flipperServer.exec('shutdown'); + window.close(); + }; + return ( <> Flipper version {versionCheckResult.version} is now available. {fbConfig.isFBBuild ? ( - fbConfig.getReleaseChannel() === ReleaseChannel.INSIDERS ? ( - <> Restart Flipper to update to the latest version. + fbConfig.getReleaseChannel() === ReleaseChannel.INSIDERS || + launcherSettings.ignoreLocalPin ? ( + ) : ( <> {' '} Run arc pull (optionally with --latest) in{' '} - ~/fbsource and restart Flipper to update to the latest - version. + ~/fbsource and{' '} + + . ) ) : (