feat: add preference on android to not confirm when exiting (#1870)
This commit is contained in:
@@ -567,7 +567,12 @@ export class MobileDevice implements MobileDeviceInterface {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
confirmAndExit() {
|
exitApp(shouldConfirm?: boolean) {
|
||||||
|
if (!shouldConfirm) {
|
||||||
|
SNReactNative.exitApp()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
Alert.alert(
|
Alert.alert(
|
||||||
'Close app',
|
'Close app',
|
||||||
'Do you want to close the app?',
|
'Do you want to close the app?',
|
||||||
|
|||||||
@@ -16,5 +16,5 @@ export interface MobileDeviceInterface extends DeviceInterface {
|
|||||||
shareBase64AsFile(base64: string, filename: string): Promise<void>
|
shareBase64AsFile(base64: string, filename: string): Promise<void>
|
||||||
downloadBase64AsFile(base64: string, filename: string, saveInTempLocation?: boolean): Promise<string | undefined>
|
downloadBase64AsFile(base64: string, filename: string, saveInTempLocation?: boolean): Promise<string | undefined>
|
||||||
previewFile(base64: string, filename: string): Promise<boolean>
|
previewFile(base64: string, filename: string): Promise<boolean>
|
||||||
confirmAndExit(): void
|
exitApp(confirm?: boolean): void
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
ComponentMutator,
|
ComponentMutator,
|
||||||
SNComponent,
|
SNComponent,
|
||||||
NewNoteTitleFormat,
|
NewNoteTitleFormat,
|
||||||
|
Platform,
|
||||||
} from '@standardnotes/snjs'
|
} from '@standardnotes/snjs'
|
||||||
import { Subtitle, Text, Title } from '@/Components/Preferences/PreferencesComponents/Content'
|
import { Subtitle, Text, Title } from '@/Components/Preferences/PreferencesComponents/Content'
|
||||||
import { WebApplication } from '@/Application/Application'
|
import { WebApplication } from '@/Application/Application'
|
||||||
@@ -52,7 +53,13 @@ const getDefaultEditor = (application: WebApplication) => {
|
|||||||
return application.componentManager.componentsForArea(ComponentArea.Editor).filter((e) => e.isDefaultEditor())[0]
|
return application.componentManager.componentsForArea(ComponentArea.Editor).filter((e) => e.isDefaultEditor())[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const AndroidConfirmBeforeExitKey = 'ConfirmBeforeExit'
|
||||||
|
|
||||||
const Defaults: FunctionComponent<Props> = ({ application }) => {
|
const Defaults: FunctionComponent<Props> = ({ application }) => {
|
||||||
|
const [androidConfirmBeforeExit, setAndroidConfirmBeforeExit] = useState(
|
||||||
|
() => (application.getValue(AndroidConfirmBeforeExitKey) as boolean) ?? true,
|
||||||
|
)
|
||||||
|
|
||||||
const [editorItems, setEditorItems] = useState<DropdownItem[]>([])
|
const [editorItems, setEditorItems] = useState<DropdownItem[]>([])
|
||||||
const [defaultEditorValue, setDefaultEditorValue] = useState(
|
const [defaultEditorValue, setDefaultEditorValue] = useState(
|
||||||
() => getDefaultEditor(application)?.package_info?.identifier || 'plain-editor',
|
() => getDefaultEditor(application)?.package_info?.identifier || 'plain-editor',
|
||||||
@@ -143,10 +150,26 @@ const Defaults: FunctionComponent<Props> = ({ application }) => {
|
|||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const toggleAndroidConfirmBeforeExit = () => {
|
||||||
|
const newValue = !androidConfirmBeforeExit
|
||||||
|
setAndroidConfirmBeforeExit(newValue)
|
||||||
|
application.setValue(AndroidConfirmBeforeExitKey, newValue)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PreferencesGroup>
|
<PreferencesGroup>
|
||||||
<PreferencesSegment>
|
<PreferencesSegment>
|
||||||
<Title>Defaults</Title>
|
<Title>Defaults</Title>
|
||||||
|
{application.platform === Platform.Android && (
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<Subtitle>Always ask before closing app</Subtitle>
|
||||||
|
<Text>Whether a confirmation dialog should be shown before closing the app.</Text>
|
||||||
|
</div>
|
||||||
|
<Switch onChange={toggleAndroidConfirmBeforeExit} checked={androidConfirmBeforeExit} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<HorizontalSeparator classes="my-4" />
|
||||||
<div>
|
<div>
|
||||||
<Subtitle>Default Note Type</Subtitle>
|
<Subtitle>Default Note Type</Subtitle>
|
||||||
<Text>New notes will be created using this type</Text>
|
<Text>New notes will be created using this type</Text>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { WebApplication } from '@/Application/Application'
|
import { WebApplication } from '@/Application/Application'
|
||||||
|
import { AndroidConfirmBeforeExitKey } from '@/Components/Preferences/Panes/General/Defaults'
|
||||||
import { observer } from 'mobx-react-lite'
|
import { observer } from 'mobx-react-lite'
|
||||||
import { createContext, memo, ReactNode, useCallback, useContext, useEffect } from 'react'
|
import { createContext, memo, ReactNode, useCallback, useContext, useEffect } from 'react'
|
||||||
|
|
||||||
@@ -34,7 +35,10 @@ const AndroidBackHandlerProvider = ({ application, children }: ProviderProps) =>
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const removeListener = addAndroidBackHandler(() => {
|
const removeListener = addAndroidBackHandler(() => {
|
||||||
application.mobileDevice().confirmAndExit()
|
const shouldConfirm = (application.getValue(AndroidConfirmBeforeExitKey) as boolean) ?? true
|
||||||
|
|
||||||
|
application.mobileDevice().exitApp(shouldConfirm)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user