A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
mobile: handle state when app entered background to take some action like pick a file/image etc.
ammarahm-edcef2472aae7a
diff --git a/apps/mobile/app/hooks/use-app-events.js b/apps/mobile/app/hooks/use-app-events.jsindex 23e9df912..94438d99e 100644--- a/apps/mobile/app/hooks/use-app-events.js+++ b/apps/mobile/app/hooks/use-app-events.js@@ -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;diff --git a/apps/mobile/app/screens/editor/tiptap/picker.js b/apps/mobile/app/screens/editor/tiptap/picker.jsindex 0f74301b5..ba8b987a9 100644--- a/apps/mobile/app/screens/editor/tiptap/picker.js+++ b/apps/mobile/app/screens/editor/tiptap/picker.js@@ -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,diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor.ts b/apps/mobile/app/screens/editor/tiptap/use-editor.tsindex 5cd901a54..9c1926af1 100644--- a/apps/mobile/app/screens/editor/tiptap/use-editor.ts+++ b/apps/mobile/app/screens/editor/tiptap/use-editor.ts@@ -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;diff --git a/apps/mobile/app/screens/editor/wrapper.js b/apps/mobile/app/screens/editor/wrapper.jsindex a3632084e..1bf0ea77e 100644--- a/apps/mobile/app/screens/editor/wrapper.js+++ b/apps/mobile/app/screens/editor/wrapper.js@@ -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);diff --git a/apps/mobile/app/stores/use-setting-store.ts b/apps/mobile/app/stores/use-setting-store.tsindex e165d35bc..af6398f1a 100644--- a/apps/mobile/app/stores/use-setting-store.ts+++ b/apps/mobile/app/stores/use-setting-store.ts@@ -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 }