From e3be17c7f8345c1eed5b2cc6f98b38e24647b212 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Tue, 20 Sep 2022 01:48:40 +0530 Subject: [PATCH] fix: show warning on mobile webview before app quits (#1598) --- .../WorkspaceSwitcherMenu.tsx | 54 ++++++++++++++++--- .../ConfirmSignoutModal.tsx | 10 +++- 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/packages/web/src/javascripts/Components/AccountMenu/WorkspaceSwitcher/WorkspaceSwitcherMenu.tsx b/packages/web/src/javascripts/Components/AccountMenu/WorkspaceSwitcher/WorkspaceSwitcherMenu.tsx index 574604dd5..fc5fb8c7f 100644 --- a/packages/web/src/javascripts/Components/AccountMenu/WorkspaceSwitcher/WorkspaceSwitcherMenu.tsx +++ b/packages/web/src/javascripts/Components/AccountMenu/WorkspaceSwitcher/WorkspaceSwitcherMenu.tsx @@ -45,7 +45,9 @@ const WorkspaceSwitcherMenu: FunctionComponent = ({ const signoutAll = useCallback(async () => { const confirmed = await viewControllerManager.application.alertService.confirm( - 'Are you sure you want to sign out of all workspaces on this device?', + `Are you sure you want to sign out of all workspaces on this device?${ + viewControllerManager.application.isNativeMobileWeb() && ' Your app will quit after sign out completes.' + }`, undefined, 'Sign out all', ButtonType.Danger, @@ -60,6 +62,47 @@ const WorkspaceSwitcherMenu: FunctionComponent = ({ viewControllerManager.accountMenuController.setSigningOut(true) }, [viewControllerManager]) + const activateWorkspace = useCallback( + async (descriptor: ApplicationDescriptor) => { + if (viewControllerManager.application.isNativeMobileWeb()) { + const confirmed = await viewControllerManager.application.alertService.confirm( + 'The app needs to be restarted to activate the workspace', + undefined, + 'Quit app and activate workspace', + ButtonType.Danger, + ) + + if (confirmed) { + void mainApplicationGroup.unloadCurrentAndActivateDescriptor(descriptor) + } + + return + } + + void mainApplicationGroup.unloadCurrentAndActivateDescriptor(descriptor) + }, + [mainApplicationGroup, viewControllerManager.application], + ) + + const addAnotherWorkspace = useCallback(async () => { + if (viewControllerManager.application.isNativeMobileWeb()) { + const confirmed = await viewControllerManager.application.alertService.confirm( + 'The app needs to be restarted to add another workspace', + undefined, + 'Quit app and add new workspace', + ButtonType.Danger, + ) + + if (confirmed) { + void mainApplicationGroup.unloadCurrentAndCreateNewDescriptor() + } + + return + } + + void mainApplicationGroup.unloadCurrentAndCreateNewDescriptor() + }, [mainApplicationGroup, viewControllerManager.application]) + return ( {applicationDescriptors.map((descriptor) => ( @@ -68,18 +111,13 @@ const WorkspaceSwitcherMenu: FunctionComponent = ({ descriptor={descriptor} hideOptions={hideWorkspaceOptions} onDelete={destroyWorkspace} - onClick={() => void mainApplicationGroup.unloadCurrentAndActivateDescriptor(descriptor)} + onClick={() => activateWorkspace(descriptor)} renameDescriptor={(label: string) => mainApplicationGroup.renameDescriptor(descriptor, label)} /> ))} - { - void mainApplicationGroup.unloadCurrentAndCreateNewDescriptor() - }} - > + Add another workspace diff --git a/packages/web/src/javascripts/Components/ConfirmSignoutModal/ConfirmSignoutModal.tsx b/packages/web/src/javascripts/Components/ConfirmSignoutModal/ConfirmSignoutModal.tsx index 9ba529753..22eb0ff69 100644 --- a/packages/web/src/javascripts/Components/ConfirmSignoutModal/ConfirmSignoutModal.tsx +++ b/packages/web/src/javascripts/Components/ConfirmSignoutModal/ConfirmSignoutModal.tsx @@ -41,7 +41,15 @@ const ConfirmSignoutModal: FunctionComponent = ({ application, viewContro Sign out workspace?
-

{STRING_SIGN_OUT_CONFIRMATION}

+

+ {STRING_SIGN_OUT_CONFIRMATION} + {application.isNativeMobileWeb() && ( +

+
+ Your app will quit after sign out completes. +
+ )} +

{showWorkspaceWarning && ( <>