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
improve sync error handling
ammarahm-edaab2c4c19cee
diff --git a/apps/mobile/src/services/sync.js b/apps/mobile/src/services/sync.jsindex 57238813b..1c1e7924f 100644--- a/apps/mobile/src/services/sync.js+++ b/apps/mobile/src/services/sync.js@@ -1,4 +1,3 @@-import Clipboard from '@react-native-clipboard/clipboard';import NetInfo from '@react-native-community/netinfo';import { getNote, updateNoteInEditor } from '../screens/editor/Functions';import { initialize, useUserStore } from '../stores/stores';@@ -6,7 +5,7 @@ import { doInBackground } from '../utils';import { db } from '../utils/database';import { ToastEvent } from './event-manager';-const ignoredMessages = ['Sync already running', 'Not allowed to start service intent'];+export const ignoredMessages = ['Sync already running', 'Not allowed to start service intent'];const run = async (context = 'global', forced = false, full = true) => {let result = false;@@ -16,47 +15,32 @@ const run = async (context = 'global', forced = false, full = true) => {return true;}userstore.setSyncing(true);- let errorStack = null;+ let error = null;+ console.log('Sync.run started');try {let res = await doInBackground(async () => {try {return await db.sync(full, forced);} catch (e) {- errorStack = e.stack;+ error = e;return e.message;}});-if (!res) {initialize();return false;}- if (typeof res === 'string') throw new Error(res);+ if (typeof res === 'string') throw error;+ userstore.setSyncing(false);result = true;} catch (e) {result = false;- console.log(e.stack);if (!ignoredMessages.find(im => e.message?.includes(im)) && userstore.user) {userstore.setSyncing(false);let status = await NetInfo.fetch();if (status.isConnected && status.isInternetReachable) {- ToastEvent.show({- heading: 'Sync failed',- message: e.message,- context: context,- actionText: 'Copy logs',- func: () => {- if (errorStack) {- Clipboard.setString(errorStack);- ToastEvent.show({- heading: 'Logs copied!',- type: 'success',- context: 'global'- });- }- }- });+ ToastEvent.error(e, 'Sync failed', context);}}} finally {@@ -65,6 +49,8 @@ const run = async (context = 'global', forced = false, full = true) => {if (getNote()?.id) {await updateNoteInEditor();}++ console.log('sync done');userstore.setSyncing(false);}return result;diff --git a/apps/mobile/src/utils/hooks/useAppEvents.js b/apps/mobile/src/utils/hooks/useAppEvents.jsindex b9fea8de0..148c24fb6 100644--- a/apps/mobile/src/utils/hooks/useAppEvents.js+++ b/apps/mobile/src/utils/hooks/useAppEvents.js@@ -37,7 +37,7 @@ import {} from '../../services/message';import PremiumService from '../../services/premium';import SettingsService from '../../services/settings';-import Sync from '../../services/sync';+import Sync, { ignoredMessages } from '../../services/sync';import {clearAllStores,initialize,@@ -244,30 +244,11 @@ export const useAppEvents = () => {const onRequestPartialSync = async (full, force) => {console.log('auto sync request', full, force);- try {- if (full || force) {- Sync.run('global', force, full);- return;- }- setSyncing(true);- let res = await doInBackground(async () => {- try {- await db.sync(false);- return true;- } catch (e) {- return e.message;- }- });- if (res !== true) throw new Error(res);- setLastSynced(await db.lastSynced());- } catch (e) {+ if (full || force) {+ await Sync.run('global', force, full);setSyncing(false);- let status = await NetInfo.fetch();- if (status.isConnected && status.isInternetReachable) {- console.log(e.message, AppState.currentState);- ToastEvent.error(e, 'Sync failed', 'global');- }- } finally {+ } else {+ await Sync.run('global', false, false);setSyncing(false);}};