mobile: handle state when app entered background

to take some action like pick a file/image etc.
This commit is contained in:
ammarahm-ed
2023-09-06 20:06:46 +05:00
parent a4946f7e89
commit cef2472aae
5 changed files with 21 additions and 1 deletions

View File

@@ -534,6 +534,12 @@ export const useAppEvents = () => {
if (refValues.current?.isReconnecting || !refValues.current?.isUserReady)
return;
if (useSettingStore.getState().appDidEnterBackgroundForAction) {
useSettingStore.getState().setAppDidEnterBackgroundForAction(false);
console.log("AppDidEnterForegroundAfterAction");
return;
}
if (SettingsService.get().sessionExpired) {
refValues.current.isReconnecting = false;
return;

View File

@@ -34,6 +34,7 @@ import PremiumService from "../../../services/premium";
import { FILE_SIZE_LIMIT, IMAGE_SIZE_LIMIT } from "../../../utils/constants";
import { eCloseSheet } from "../../../utils/events";
import { editorController, editorState } from "./utils";
import { useSettingStore } from "../../../stores/use-setting-store";
const showEncryptionSheet = (file) => {
presentSheet({
@@ -62,6 +63,7 @@ const file = async (fileOptions) => {
let file;
try {
useSettingStore.getState().setAppDidEnterBackgroundForAction(true);
file = await DocumentPicker.pick(options);
} catch (e) {
return;
@@ -135,6 +137,7 @@ const file = async (fileOptions) => {
const camera = async (options) => {
try {
await db.attachments.generateKey();
useSettingStore.getState().setAppDidEnterBackgroundForAction(true);
launchCamera(
{
includeBase64: true,
@@ -156,6 +159,7 @@ const camera = async (options) => {
const gallery = async (options) => {
try {
await db.attachments.generateKey();
useSettingStore.getState().setAppDidEnterBackgroundForAction(true);
launchImageLibrary(
{
includeBase64: true,

View File

@@ -141,6 +141,7 @@ export const useEditor = (
clearTimeout(timers.current["loading-images"]);
sessionHistoryId.current = undefined;
saveCount.current = 0;
lock.current = false;
useEditorStore.getState().setReadonly(false);
resetContent && postMessage(EditorEvents.title, "");
lastContentChangeTime.current = 0;

View File

@@ -55,6 +55,7 @@ export const EditorWrapper = ({ width }) => {
prevState.current = state;
return;
}
if (useSettingStore.getState().appDidEnterBackgroundForAction) return;
if (state === "active") {
editorController.current.onReady();
editorController.current.overlay(false);

View File

@@ -103,6 +103,8 @@ export interface SettingStore extends State {
sheetKeyboardHandler: boolean;
requestBiometrics: boolean;
setRequestBiometrics: (requestBiometrics: boolean) => void;
appDidEnterBackgroundForAction: boolean;
setAppDidEnterBackgroundForAction: (value: boolean) => void;
insets: Insets;
setInsets: (insets: Insets) => void;
timeFormat: string;
@@ -155,7 +157,7 @@ export const defaultSettings: SettingStore["settings"] = {
darkTheme: ThemeDark
};
export const useSettingStore = create<SettingStore>((set) => ({
export const useSettingStore = create<SettingStore>((set, get) => ({
settings: { ...defaultSettings },
sheetKeyboardHandler: true,
fullscreen: false,
@@ -174,6 +176,12 @@ export const useSettingStore = create<SettingStore>((set) => ({
setInsets: (insets) => set({ insets }),
timeFormat: "12-hour",
dateFormat: "DD-MM-YYYY",
setAppDidEnterBackgroundForAction: (value: boolean) => {
set({
appDidEnterBackgroundForAction: value
});
},
appDidEnterBackgroundForAction: false,
insets: initialWindowMetrics?.insets
? initialWindowMetrics.insets
: { top: 0, right: 0, left: 0, bottom: 0 }