diff --git a/packages/mobile/src/Lib/Interface.ts b/packages/mobile/src/Lib/Interface.ts index 7911983bc..4cd694039 100644 --- a/packages/mobile/src/Lib/Interface.ts +++ b/packages/mobile/src/Lib/Interface.ts @@ -567,7 +567,12 @@ export class MobileDevice implements MobileDeviceInterface { return true } - confirmAndExit() { + exitApp(shouldConfirm?: boolean) { + if (!shouldConfirm) { + SNReactNative.exitApp() + return + } + Alert.alert( 'Close app', 'Do you want to close the app?', diff --git a/packages/services/src/Domain/Device/MobileDeviceInterface.ts b/packages/services/src/Domain/Device/MobileDeviceInterface.ts index 0a26c8278..9063b04af 100644 --- a/packages/services/src/Domain/Device/MobileDeviceInterface.ts +++ b/packages/services/src/Domain/Device/MobileDeviceInterface.ts @@ -16,5 +16,5 @@ export interface MobileDeviceInterface extends DeviceInterface { shareBase64AsFile(base64: string, filename: string): Promise downloadBase64AsFile(base64: string, filename: string, saveInTempLocation?: boolean): Promise previewFile(base64: string, filename: string): Promise - confirmAndExit(): void + exitApp(confirm?: boolean): void } diff --git a/packages/web/src/javascripts/Components/Preferences/Panes/General/Defaults.tsx b/packages/web/src/javascripts/Components/Preferences/Panes/General/Defaults.tsx index 8862e81b4..b58bbc2d5 100644 --- a/packages/web/src/javascripts/Components/Preferences/Panes/General/Defaults.tsx +++ b/packages/web/src/javascripts/Components/Preferences/Panes/General/Defaults.tsx @@ -7,6 +7,7 @@ import { ComponentMutator, SNComponent, NewNoteTitleFormat, + Platform, } from '@standardnotes/snjs' import { Subtitle, Text, Title } from '@/Components/Preferences/PreferencesComponents/Content' import { WebApplication } from '@/Application/Application' @@ -52,7 +53,13 @@ const getDefaultEditor = (application: WebApplication) => { return application.componentManager.componentsForArea(ComponentArea.Editor).filter((e) => e.isDefaultEditor())[0] } +export const AndroidConfirmBeforeExitKey = 'ConfirmBeforeExit' + const Defaults: FunctionComponent = ({ application }) => { + const [androidConfirmBeforeExit, setAndroidConfirmBeforeExit] = useState( + () => (application.getValue(AndroidConfirmBeforeExitKey) as boolean) ?? true, + ) + const [editorItems, setEditorItems] = useState([]) const [defaultEditorValue, setDefaultEditorValue] = useState( () => getDefaultEditor(application)?.package_info?.identifier || 'plain-editor', @@ -143,10 +150,26 @@ const Defaults: FunctionComponent = ({ application }) => { [], ) + const toggleAndroidConfirmBeforeExit = () => { + const newValue = !androidConfirmBeforeExit + setAndroidConfirmBeforeExit(newValue) + application.setValue(AndroidConfirmBeforeExitKey, newValue) + } + return ( Defaults + {application.platform === Platform.Android && ( +
+
+ Always ask before closing app + Whether a confirmation dialog should be shown before closing the app. +
+ +
+ )} +
Default Note Type New notes will be created using this type diff --git a/packages/web/src/javascripts/NativeMobileWeb/useAndroidBackHandler.tsx b/packages/web/src/javascripts/NativeMobileWeb/useAndroidBackHandler.tsx index 4f0313042..e1521d5cd 100644 --- a/packages/web/src/javascripts/NativeMobileWeb/useAndroidBackHandler.tsx +++ b/packages/web/src/javascripts/NativeMobileWeb/useAndroidBackHandler.tsx @@ -1,4 +1,5 @@ import { WebApplication } from '@/Application/Application' +import { AndroidConfirmBeforeExitKey } from '@/Components/Preferences/Panes/General/Defaults' import { observer } from 'mobx-react-lite' import { createContext, memo, ReactNode, useCallback, useContext, useEffect } from 'react' @@ -34,7 +35,10 @@ const AndroidBackHandlerProvider = ({ application, children }: ProviderProps) => useEffect(() => { const removeListener = addAndroidBackHandler(() => { - application.mobileDevice().confirmAndExit() + const shouldConfirm = (application.getValue(AndroidConfirmBeforeExitKey) as boolean) ?? true + + application.mobileDevice().exitApp(shouldConfirm) + return true }) return () => {