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
reduce delay in capturing intent and loading app
ammarahm-ed436bafa7b818
diff --git a/apps/mobile/App.js b/apps/mobile/App.jsindex 113ae436f..e0a0a61ec 100644--- a/apps/mobile/App.js+++ b/apps/mobile/App.js@@ -13,6 +13,7 @@ import * as RNIap from 'react-native-iap';import {enabled} from 'react-native-privacy-snapshot';import {SafeAreaProvider} from 'react-native-safe-area-context';import SplashScreen from 'react-native-splash-screen';+import {RootView} from './initializer.root';import {useTracked} from './src/provider';import {Actions} from './src/provider/Actions';import Backup from './src/services/Backup';@@ -43,16 +44,14 @@ import {eOpenPendingDialog,eOpenProgressDialog,eOpenSideMenu,- eStartSyncer,refreshNotesPage,} from './src/utils/Events';import {MMKV} from './src/utils/mmkv';import {tabBarRef} from './src/utils/Refs';import {sleep} from './src/utils/TimeUtils';-import {getNote} from './src/views/Editor/Functions';+import {getIntent, getNote, setIntent} from './src/views/Editor/Functions';const {ReceiveSharingIntent} = NativeModules;-let AppRootView = require('./initializer.root').RootView;let Sentry = null;let appIsInitialized = false;let intentOnAppLoadProcessed = false;@@ -106,6 +105,8 @@ const onAppStateChanged = async (state) => {function loadIntent(event) {if (event) {+ setIntent();+ console.log(event, getIntent());eSendEvent(eOnLoadNote, event);tabBarRef.current?.goToPage(1);Navigation.closeDrawer();@@ -131,9 +132,7 @@ const onNetworkStateChanged = (netInfo) => {};const App = () => {- const [, dispatch] = useTracked(),- [init, setInit] = useState(true),- [intent, setIntent] = useState(false);+ const [, dispatch] = useTracked();let subsriptionSuccessListerner;let subsriptionErrorListener;@@ -157,7 +156,6 @@ const App = () => {EV.unsubscribe('user:loggedOut', onLogout);EV.unsubscribe('db:sync', partialSync);EV.unsubscribe('user:checkStatus', PremiumService.onUserStatusCheck);- eUnSubscribeEvent(eStartSyncer, startSyncer);eUnSubscribeEvent(eDispatchAction, (type) => {dispatch(type);});@@ -272,8 +270,8 @@ const App = () => {};const loadMainApp = () => {+ dispatch({type: Actions.INTENT_MODE, state: false});dispatch({type: Actions.ALL});- AppRootView = require('./initializer.root').RootView;setCurrentUser().then(console.log).catch(console.log);Backup.checkAndRun().then((r) => r);sleep(500).then(() => (appIsInitialized = true));@@ -314,17 +312,20 @@ const App = () => {let isIntent = false;IntentService.getIntent().then(() => {- AppRootView = require('./initializer.intent').IntentView;- setInit(false);- intentOnAppLoadProcessed = true;- dispatch({type: Actions.ALL});- setIntent(true);- isIntent = true;- ReceiveSharingIntent.clearFileNames();+ IntentService.check((event) => {+ SplashScreen.hide();+ loadIntent(event);+ intentOnAppLoadProcessed = true;+ dispatch({type: Actions.ALL});+ isIntent = true;+ dispatch({type: Actions.INTENT_MODE, state: true});+ ReceiveSharingIntent.clearFileNames();+ });}).catch((e) => console.log).finally(() => {if (!isIntent) {+ dispatch({type: Actions.INTENT_MODE, state: false});ReceiveSharingIntent.clearFileNames();intentOnAppLoadProcessed = true;loadMainApp();@@ -372,8 +373,7 @@ const App = () => {return (<SafeAreaProvider>- {intent ? <AppRootView /> : null}- {init && !intent ? <AppRootView /> : null}+ <RootView /></SafeAreaProvider>);};diff --git a/apps/mobile/initializer.intent.js b/apps/mobile/initializer.intent.jsdeleted file mode 100644index 9de44a320..000000000--- a/apps/mobile/initializer.intent.js+++ /dev/null@@ -1,25 +0,0 @@-import React from 'react';-import {DialogManager} from './src/components/DialogManager';-import {DummyText} from './src/components/DummyText';-import {Toast} from './src/components/Toast';-import {useTracked} from './src/provider';-import {EditorWrapper} from './src/views/Editor/EditorWrapper';--export const IntentView = () => {- const [state] = useTracked();- const {colors} = state;-- return (- <>- <EditorWrapper- dimensions={{- width: '100%',- height: '100%',- }}- />- <Toast />- <DummyText />- <DialogManager colors={colors} />- </>- );-};diff --git a/apps/mobile/initializer.root.js b/apps/mobile/initializer.root.jsindex d91733ed3..5ea5b918c 100644--- a/apps/mobile/initializer.root.js+++ b/apps/mobile/initializer.root.js@@ -55,11 +55,20 @@ const onChangeTab = async (obj) => {export const RootView = () => {const [state] = useTracked();- const {colors} = state;+ const {colors, intentMode} = state;return (<>- <NavigationStack component={AppStack} />+ {intentMode ? (+ <EditorWrapper+ dimensions={{+ width: '100%',+ height: '100%',+ }}+ />+ ) : (+ <NavigationStack component={AppStack} />+ )}<Toast /><ContextMenu /><DummyText />diff --git a/apps/mobile/src/provider/Actions.js b/apps/mobile/src/provider/Actions.jsindex 0ea5e5ca9..c835271be 100644--- a/apps/mobile/src/provider/Actions.js+++ b/apps/mobile/src/provider/Actions.js@@ -32,5 +32,6 @@ export const Actions = {FULLSCREEN:"fullscreen",DEVICE_MODE:"deviceMode",MENU_PINS:"menuPins",- LAST_SYNC:"lastSynced"+ LAST_SYNC:"lastSynced",+ INTENT_MODE: "intentMode"};diff --git a/apps/mobile/src/provider/DefaultState.js b/apps/mobile/src/provider/DefaultState.jsindex 7367078c4..b2c677a9c 100644--- a/apps/mobile/src/provider/DefaultState.js+++ b/apps/mobile/src/provider/DefaultState.js@@ -82,5 +82,6 @@ export const defaultState = {},keyword: [],menuPins:[],- lastSynced:"Never"+ lastSynced:"Never",+ intentMode:true};diff --git a/apps/mobile/src/provider/Reducer.js b/apps/mobile/src/provider/Reducer.jsindex 8ab9b8f02..d85655806 100644--- a/apps/mobile/src/provider/Reducer.js+++ b/apps/mobile/src/provider/Reducer.js@@ -266,6 +266,13 @@ export const reducer = (state, action) => {menuPins: action.lastSync,};}+ case Actions.INTENT_MODE: {++ return {+ ...state,+ intentMode: action.state,+ };+ }default:throw new Error('unknown action type');}diff --git a/apps/mobile/src/views/Editor/EditorHeader.js b/apps/mobile/src/views/Editor/EditorHeader.jsindex d9f709fb7..959516072 100644--- a/apps/mobile/src/views/Editor/EditorHeader.js+++ b/apps/mobile/src/views/Editor/EditorHeader.js@@ -121,7 +121,7 @@ const EditorHeader = () => {};const _onBackPress = async () => {- if (getIntent() && sideMenuRef.current === null) {+ if (sideMenuRef.current === null) {if (tapCount > 0) {tapCount = 0;setIntent(false);diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.jsindex a43c0b520..9adebc3bf 100644--- a/apps/mobile/src/views/Editor/Functions.js+++ b/apps/mobile/src/views/Editor/Functions.js@@ -155,13 +155,12 @@ function clearNote() {let currentEditingTimer = null;-export async function loadNote(item) {+export const loadNote = async (item) => {editing.currentlyEditing = true;post('blur');-if (item && item.type === 'new') {- intent = false;+ if (intent) return;await clearEditor();clearNote();noteEdited = false;@@ -177,11 +176,11 @@ export async function loadNote(item) {await clearEditor();clearNote();id = null;- intent = true;content = {data: item.data,type: 'delta',};+ intent = true;if (webviewInit) {await loadNoteInEditor();}@@ -193,9 +192,8 @@ export async function loadNote(item) {await loadNoteInEditor();}updateEvent({type: Actions.CURRENT_EDITING_NOTE, id: item.id});-}-}+};export function setIntentNote(item) {id = null;@@ -277,7 +275,7 @@ export async function clearEditor() {});saveCounter = 0;clearNote();- intent = false;+ //intent = false;}function checkIfContentIsSavable() {@@ -382,7 +380,7 @@ export async function saveNote(canPost = true) {}saveCounter++;} else {- await db.vault.save({+ let note = await db.vault.save({title,content: {type: content.type,@@ -424,7 +422,7 @@ async function loadEditorState() {}}} else {- IntentService.check((event) => {+ /* IntentService.check((event) => {if (event) {intent = true;eSendEvent(eOnLoadNote, event);@@ -433,7 +431,7 @@ async function loadEditorState() {} else {eSendEvent('nointent');}- });+ }); */}}@@ -443,18 +441,17 @@ const loadNoteInEditor = async () => {if (!webviewInit) return;saveCounter = 0;if (intent) {- await sleep(1500);post('delta', content.data);- intent = true;+ intent = false;await saveNote();} else if (note?.id) {post('title', title);intent = false;setColors();post('delta', content.data);- await sleep(100);+ await sleep(10);post('dateEdited', timeConverter(note.dateEdited));}- await sleep(50);+ await sleep(10);post('clearHistory');};