Check Flipper version when handling deeplinks
Summary: Check if Flipper is up to date before handling deeplink. Reviewed By: nikoant Differential Revision: D29846236 fbshipit-source-id: 011d05958346c3d18c76cf0ae63c3cb087f5933c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b757bff9f6
commit
4b892e7373
@@ -49,32 +49,7 @@ export default function UpdateIndicator() {
|
||||
placement: 'bottomLeft',
|
||||
key: 'flipperupdatecheck',
|
||||
message: 'Update available',
|
||||
description: (
|
||||
<>
|
||||
Flipper version {versionCheckResult.version} is now available.
|
||||
{fbConfig.isFBBuild ? (
|
||||
fbConfig.getReleaseChannel() === ReleaseChannel.INSIDERS ? (
|
||||
<> Restart Flipper to update to the latest version.</>
|
||||
) : (
|
||||
<>
|
||||
{' '}
|
||||
Run <code>arc pull</code> (optionally with{' '}
|
||||
<code>--latest</code>) in <code>~/fbsource</code> and
|
||||
restart Flipper to update to the latest version.
|
||||
</>
|
||||
)
|
||||
) : (
|
||||
<>
|
||||
{' '}
|
||||
Click to{' '}
|
||||
<Typography.Link href={versionCheckResult.url}>
|
||||
download
|
||||
</Typography.Link>
|
||||
.
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
),
|
||||
description: getUpdateAvailableMessage(versionCheckResult),
|
||||
duration: null, // no auto close
|
||||
});
|
||||
break;
|
||||
@@ -127,3 +102,35 @@ export default function UpdateIndicator() {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getUpdateAvailableMessage(versionCheckResult: {
|
||||
url: string;
|
||||
version: string;
|
||||
}): React.ReactNode {
|
||||
return (
|
||||
<>
|
||||
Flipper version {versionCheckResult.version} is now available.
|
||||
{fbConfig.isFBBuild ? (
|
||||
fbConfig.getReleaseChannel() === ReleaseChannel.INSIDERS ? (
|
||||
<> Restart Flipper to update to the latest version.</>
|
||||
) : (
|
||||
<>
|
||||
{' '}
|
||||
Run <code>arc pull</code> (optionally with <code>--latest</code>) in{' '}
|
||||
<code>~/fbsource</code> and restart Flipper to update to the latest
|
||||
version.
|
||||
</>
|
||||
)
|
||||
) : (
|
||||
<>
|
||||
{' '}
|
||||
Click to{' '}
|
||||
<Typography.Link href={versionCheckResult.url}>
|
||||
download
|
||||
</Typography.Link>
|
||||
.
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,10 @@ test('Triggering a deeplink will work', async () => {
|
||||
jest.runAllTimers();
|
||||
expect(linksSeen).toEqual(['universe']);
|
||||
expect(renderer.baseElement).toMatchInlineSnapshot(`
|
||||
<body>
|
||||
<body
|
||||
class=""
|
||||
style=""
|
||||
>
|
||||
<div>
|
||||
<div
|
||||
class="css-1x2cmzz-SandySplitContainer e1hsqii10"
|
||||
|
||||
@@ -7,14 +7,17 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import {Dialog, getFlipperLib} from 'flipper-plugin';
|
||||
import {getUser} from '../fb-stubs/user';
|
||||
import {Store} from '../reducers/index';
|
||||
// import {checkForUpdate} from '../fb-stubs/checkForUpdate';
|
||||
// import {getAppVersion} from '../utils/info';
|
||||
import {checkForUpdate} from '../fb-stubs/checkForUpdate';
|
||||
import {getAppVersion} from '../utils/info';
|
||||
import {ACTIVE_SHEET_SIGN_IN, setActiveSheet} from '../reducers/application';
|
||||
import {UserNotSignedInError} from '../utils/errors';
|
||||
import {selectPlugin} from '../reducers/connections';
|
||||
import {getUpdateAvailableMessage} from '../chrome/UpdateIndicator';
|
||||
import {Typography} from 'antd';
|
||||
|
||||
type OpenPluginParams = {
|
||||
pluginId: string;
|
||||
@@ -42,11 +45,12 @@ export function parseOpenPluginParams(query: string): OpenPluginParams {
|
||||
|
||||
export async function handleOpenPluginDeeplink(store: Store, query: string) {
|
||||
const params = parseOpenPluginParams(query);
|
||||
const title = `Starting plugin ${params.pluginId}…`;
|
||||
|
||||
if (!(await verifyLighthouseAndUserLoggedIn(store, params))) {
|
||||
if (!(await verifyLighthouseAndUserLoggedIn(store, title))) {
|
||||
return;
|
||||
}
|
||||
// await verifyFlipperIsUpToDate();
|
||||
await verifyFlipperIsUpToDate(title);
|
||||
// await verifyPluginInstalled();
|
||||
// await verifyDevices();
|
||||
// await verifyClient();
|
||||
@@ -57,14 +61,12 @@ export async function handleOpenPluginDeeplink(store: Store, query: string) {
|
||||
// check if user is connected to VPN and logged in. Returns true if OK, or false if aborted
|
||||
async function verifyLighthouseAndUserLoggedIn(
|
||||
store: Store,
|
||||
params: OpenPluginParams,
|
||||
title: string,
|
||||
): Promise<boolean> {
|
||||
if (!getFlipperLib().isFB || process.env.NODE_ENV === 'test') {
|
||||
return true; // ok, continue
|
||||
}
|
||||
|
||||
const title = `Starting plugin ${params.pluginId}…`;
|
||||
|
||||
// repeat until connection succeeded
|
||||
while (true) {
|
||||
const spinnerDialog = Dialog.loading({
|
||||
@@ -136,6 +138,41 @@ async function waitForLogin(store: Store) {
|
||||
});
|
||||
}
|
||||
|
||||
async function verifyFlipperIsUpToDate(title: string) {
|
||||
const currentVersion = getAppVersion();
|
||||
const handle = Dialog.loading({
|
||||
title,
|
||||
message: 'Checking if Flipper is up-to-date',
|
||||
});
|
||||
try {
|
||||
const result = await checkForUpdate(currentVersion);
|
||||
handle.close();
|
||||
switch (result.kind) {
|
||||
case 'error':
|
||||
// if we can't tell if we're up to date, we don't want to halt the process on that.
|
||||
console.warn('Failed to verify Flipper version', result);
|
||||
return;
|
||||
case 'up-to-date':
|
||||
return;
|
||||
case 'update-available':
|
||||
await Dialog.confirm({
|
||||
title,
|
||||
message: (
|
||||
<Typography.Text>
|
||||
{getUpdateAvailableMessage(result)}
|
||||
</Typography.Text>
|
||||
),
|
||||
okText: 'Skip',
|
||||
});
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
// if we can't tell if we're up to date, we don't want to halt the process on that.
|
||||
console.warn('Failed to verify Flipper version', e);
|
||||
handle.close();
|
||||
}
|
||||
}
|
||||
|
||||
function openPlugin(store: Store, params: OpenPluginParams) {
|
||||
store.dispatch(
|
||||
selectPlugin({
|
||||
|
||||
@@ -79,7 +79,7 @@ export const Dialog = {
|
||||
message,
|
||||
...rest
|
||||
}: {
|
||||
message: string | React.ReactElement;
|
||||
message: React.ReactNode;
|
||||
} & BaseDialogOptions): DialogResult<true> {
|
||||
return Dialog.show<true>({
|
||||
...rest,
|
||||
@@ -94,7 +94,7 @@ export const Dialog = {
|
||||
onConfirm,
|
||||
...rest
|
||||
}: BaseDialogOptions & {
|
||||
message: string | React.ReactElement;
|
||||
message: React.ReactNode;
|
||||
defaultValue?: string;
|
||||
onConfirm?: (value: string) => Promise<string>;
|
||||
}): DialogResult<string> {
|
||||
@@ -123,7 +123,7 @@ export const Dialog = {
|
||||
width,
|
||||
}: {
|
||||
title?: string;
|
||||
message: string | React.ReactElement;
|
||||
message: React.ReactNode;
|
||||
width?: number;
|
||||
}) {
|
||||
let cancel: () => void;
|
||||
|
||||
Reference in New Issue
Block a user