Shutdown Flipper when new version is downloaded

Reviewed By: passy

Differential Revision: D51527986

fbshipit-source-id: d4cf1ec82070821afff5c9cdee5a85cb1421a7ef
This commit is contained in:
Andrey Goncharov
2023-11-23 04:08:07 -08:00
committed by Facebook GitHub Bot
parent 685a0e53d7
commit 72a92e1380

View File

@@ -7,7 +7,7 @@
* @format * @format
*/ */
import {notification, Typography} from 'antd'; import {Button, notification, Typography} from 'antd';
import isProduction from '../utils/isProduction'; import isProduction from '../utils/isProduction';
import {reportPlatformFailures, ReleaseChannel} from 'flipper-common'; import {reportPlatformFailures, ReleaseChannel} from 'flipper-common';
import React, {useEffect, useState} from 'react'; import React, {useEffect, useState} from 'react';
@@ -91,16 +91,28 @@ export default function UpdateIndicator() {
isProduction() isProduction()
) { ) {
reportPlatformFailures( reportPlatformFailures(
checkForUpdate(version).then((res) => { checkForUpdate(version)
.then((res) => {
if (res.kind === 'error') { if (res.kind === 'error') {
console.warn('Version check failure: ', res); 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({ setVersionCheckResult({
kind: 'error', kind: 'error',
msg: res.msg, msg: e,
}); });
} else {
setVersionCheckResult(res);
}
}), }),
'publicVersionCheck', 'publicVersionCheck',
); );
@@ -114,18 +126,31 @@ export function getUpdateAvailableMessage(versionCheckResult: {
url: string; url: string;
version: string; version: string;
}): React.ReactNode { }): React.ReactNode {
const {launcherSettings} = getRenderHostInstance().serverConfig;
const shutdownFlipper = () => {
getRenderHostInstance().flipperServer.exec('shutdown');
window.close();
};
return ( return (
<> <>
Flipper version {versionCheckResult.version} is now available. Flipper version {versionCheckResult.version} is now available.
{fbConfig.isFBBuild ? ( {fbConfig.isFBBuild ? (
fbConfig.getReleaseChannel() === ReleaseChannel.INSIDERS ? ( fbConfig.getReleaseChannel() === ReleaseChannel.INSIDERS ||
<> Restart Flipper to update to the latest version.</> launcherSettings.ignoreLocalPin ? (
<Button block type="primary" onClick={shutdownFlipper}>
Quit Flipper to upgrade
</Button>
) : ( ) : (
<> <>
{' '} {' '}
Run <code>arc pull</code> (optionally with <code>--latest</code>) in{' '} Run <code>arc pull</code> (optionally with <code>--latest</code>) in{' '}
<code>~/fbsource</code> and restart Flipper to update to the latest <code>~/fbsource</code> and{' '}
version. <Button block type="primary" onClick={shutdownFlipper}>
Quit Flipper to upgrade
</Button>
.
</> </>
) )
) : ( ) : (