Check connection & user login when entering deeplink [1/n]
Summary: First steps in smoother deeplink flow, where connection and login status is being checked before trying to handle the deeplink. Reviewed By: lblasa Differential Revision: D29790461 fbshipit-source-id: e1e42ceb5db59c695077f316e836f1f216c7204a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
47faeade61
commit
38473121ba
@@ -7,8 +7,14 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {selectPlugin} from '../reducers/connections';
|
import {Dialog, getFlipperLib} from 'flipper-plugin';
|
||||||
|
import {getUser} from '../fb-stubs/user';
|
||||||
import {Store} from '../reducers/index';
|
import {Store} from '../reducers/index';
|
||||||
|
// 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';
|
||||||
|
|
||||||
type OpenPluginParams = {
|
type OpenPluginParams = {
|
||||||
pluginId: string;
|
pluginId: string;
|
||||||
@@ -36,32 +42,98 @@ export function parseOpenPluginParams(query: string): OpenPluginParams {
|
|||||||
|
|
||||||
export async function handleOpenPluginDeeplink(store: Store, query: string) {
|
export async function handleOpenPluginDeeplink(store: Store, query: string) {
|
||||||
const params = parseOpenPluginParams(query);
|
const params = parseOpenPluginParams(query);
|
||||||
await verifyLighthouse();
|
|
||||||
await verifyUserIsLoggedIn();
|
if (!(await verifyLighthouseAndUserLoggedIn(store, params))) {
|
||||||
await verifyFlipperIsUpToDate();
|
return;
|
||||||
await verifyPluginInstalled();
|
}
|
||||||
await verifyClient();
|
// await verifyFlipperIsUpToDate();
|
||||||
await verifyPluginInstalled();
|
// await verifyPluginInstalled();
|
||||||
|
// await verifyDevices();
|
||||||
|
// await verifyClient();
|
||||||
|
// await verifyPluginEnabled();
|
||||||
await openPlugin(store, params);
|
await openPlugin(store, params);
|
||||||
}
|
}
|
||||||
function verifyLighthouse() {
|
|
||||||
// TODO:
|
// 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,
|
||||||
|
): 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({
|
||||||
|
title,
|
||||||
|
message: 'Checking connection to Facebook Intern',
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const user = await getUser();
|
||||||
|
spinnerDialog.close();
|
||||||
|
// User is logged in
|
||||||
|
if (user) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
// Connected, but not logged in or no valid profile object returned
|
||||||
|
return await showPleaseLoginDialog(store, title);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
spinnerDialog.close();
|
||||||
|
if (e instanceof UserNotSignedInError) {
|
||||||
|
// connection, but user is not logged in
|
||||||
|
return await showPleaseLoginDialog(store, title);
|
||||||
|
}
|
||||||
|
// General connection error.
|
||||||
|
// Not connected (to presumably) intern at all
|
||||||
|
if (
|
||||||
|
!(await Dialog.confirm({
|
||||||
|
title,
|
||||||
|
message:
|
||||||
|
'It looks you are currently not connected to Lighthouse / VPN. Please connect and retry.',
|
||||||
|
okText: 'Retry',
|
||||||
|
}))
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyUserIsLoggedIn() {
|
async function showPleaseLoginDialog(
|
||||||
// TODO:
|
store: Store,
|
||||||
|
title: string,
|
||||||
|
): Promise<boolean> {
|
||||||
|
if (
|
||||||
|
!(await Dialog.confirm({
|
||||||
|
title,
|
||||||
|
message: 'You are currently not logged in, please login.',
|
||||||
|
okText: 'Login',
|
||||||
|
}))
|
||||||
|
) {
|
||||||
|
// cancelled login
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
store.dispatch(setActiveSheet(ACTIVE_SHEET_SIGN_IN));
|
||||||
|
// wait until login succeeded
|
||||||
|
await waitForLogin(store);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyFlipperIsUpToDate() {
|
async function waitForLogin(store: Store) {
|
||||||
// TODO:
|
return new Promise<void>((resolve) => {
|
||||||
}
|
const unsub = store.subscribe(() => {
|
||||||
|
if (store.getState().user?.id) {
|
||||||
function verifyPluginInstalled() {
|
unsub();
|
||||||
// TODO:
|
resolve();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
function verifyClient() {
|
});
|
||||||
// TODO:
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function openPlugin(store: Store, params: OpenPluginParams) {
|
function openPlugin(store: Store, params: OpenPluginParams) {
|
||||||
|
|||||||
Reference in New Issue
Block a user