Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

handle background task errors in try/catch

ammarahm-edaa9b37c4ff5c
diff --git a/apps/mobile/src/utils/index.js b/apps/mobile/src/utils/index.js
index 66ee21a6d..a3dadb2b5 100755
--- a/apps/mobile/src/utils/index.js
+++ b/apps/mobile/src/utils/index.js
@@ -3,7 +3,7 @@ import {Dimensions, NativeModules, Platform} from 'react-native';
import BackgroundService from 'react-native-background-actions';
import {
beginBackgroundTask,
- endBackgroundTask,
+ endBackgroundTask
} from 'react-native-begin-background-task';
import FastImage from 'react-native-fast-image';
import RNTooltips from 'react-native-tooltips';
@@ -11,16 +11,16 @@ import {dummyRef} from '../components/DummyText';
import {useSettingStore} from '../provider/stores';
import {eSendEvent} from '../services/EventManager';
import Navigation from '../services/Navigation';
-import { refreshNotesPage } from './Events';
+import {refreshNotesPage} from './Events';
import {MMKV} from './mmkv';
import {tabBarRef} from './Refs';
import {SIZE} from './SizeUtils';
-import * as ackeeTracker from "./ackee"
+import * as ackeeTracker from './ackee';
export const APP_VERSION = 1510;
-export const Tracker = ackeeTracker.create('https://sa.streetwriters.co',{
- ignoreLocalhost:true
+export const Tracker = ackeeTracker.create('https://sa.streetwriters.co', {
+ ignoreLocalhost: true
});
const imgNames = [
@@ -40,12 +40,12 @@ const imgNames = [
'organize',
'privacy',
'sync',
- 'richtext',
+ 'richtext'
];
const BaseURI = (img, color) =>
`https://github.com/ammarahm-ed/notesnook/raw/main/assets/${img}-${color.replace(
'#',
- '%23',
+ '%23'
)}.png`;
const allColors = [
@@ -63,7 +63,7 @@ const allColors = [
'#9381ff',
'#FF1744',
'#B71C1C',
- '#ffadad',
+ '#ffadad'
];
const noteColors = [
@@ -73,7 +73,7 @@ const noteColors = [
'#4CAF50',
'#2196F3',
'#673AB7',
- '#9E9E9E',
+ '#9E9E9E'
];
export const updateList = items => {
@@ -83,25 +83,23 @@ export const updateList = items => {
export function preloadImages(color) {
let uri = imgNames.map(name => {
return {
- uri: BaseURI(name, color),
+ uri: BaseURI(name, color)
};
});
uri.concat(
noteColors.map(color => {
return {
- uri: BaseURI('notes', color),
+ uri: BaseURI('notes', color)
};
- }),
+ })
);
FastImage.preload(uri);
}
export const InteractionManager = {
- runAfterInteractions: (func, time = 300) => setTimeout(func, time),
+ runAfterInteractions: (func, time = 300) => setTimeout(func, time)
};
-
-
export async function setSetting(settings, name, value) {
let s = {...settings};
s[name] = value;
@@ -118,7 +116,7 @@ export const getElevation = elevation => {
shadowColor: 'black',
shadowOffset: {width: 0.3 * elevation, height: 0.5 * elevation},
shadowOpacity: 0.2,
- shadowRadius: 0.7 * elevation,
+ shadowRadius: 0.7 * elevation
};
};
@@ -127,52 +125,52 @@ export const sortSettings = {
/**
* @type {"desc" | "asc"}
*/
- sortOrder: 'desc',
+ sortOrder: 'desc'
};
export const GROUP = {
- default: "default",
+ default: 'default',
alphabetical: 'abc',
year: 'year',
week: 'week',
- month: 'month',
+ month: 'month'
};
export const SORT = {
- dateEdited:"Date edited",
- dateCreated:"Date created",
+ dateEdited: 'Date edited',
+ dateCreated: 'Date created'
//title:"Title",
-}
+};
export const editing = {
currentlyEditing: false,
isFullscreen: false,
actionAfterFirstSave: {
- type: null,
+ type: null
},
isFocused: false,
focusType: null,
movedAway: true,
tooltip: false,
- isRestoringState: false,
+ isRestoringState: false
};
export const selection = {
data: [],
type: null,
- selectedItems: [],
+ selectedItems: []
};
export const history = {
selectedItemsList: [],
- selectionMode: false,
+ selectionMode: false
};
export async function showContext(event, title) {
event._targetInst.ref.current?.measureInWindow((x, y, w, h) => {
dummyRef.current.setNativeProps({
style: {
- fontSize: SIZE.sm,
- },
+ fontSize: SIZE.sm
+ }
});
dummyRef.current?.measure((xt, yt, wt, ht) => {
let xVal;
@@ -189,9 +187,9 @@ export async function showContext(event, title) {
eSendEvent('showContextMenu', {
location: {
x: xVal,
- y: yVal,
+ y: yVal
},
- title: title,
+ title: title
});
});
});
@@ -203,25 +201,33 @@ export const bgTaskOptions = {
taskDesc: 'Syncing your notes.',
taskIcon: {
name: 'ic_stat_name',
- type: 'drawable',
+ type: 'drawable'
},
- color: '#ffffff',
+ color: '#ffffff'
};
export async function doInBackground(cb) {
if (Platform.OS === 'ios') {
let bgTaskId;
- bgTaskId = await beginBackgroundTask();
- let res = await cb();
- await endBackgroundTask(bgTaskId);
- return res;
+ try {
+ bgTaskId = await beginBackgroundTask();
+ let res = await cb();
+ await endBackgroundTask(bgTaskId);
+ return res;
+ } catch (e) {
+ return e.message;
+ }
} else {
return new Promise(async (res, rej) => {
- await BackgroundService.start(async () => {
- let result = await cb();
- await BackgroundService.stop();
- res(result);
- }, bgTaskOptions);
+ try {
+ await BackgroundService.start(async () => {
+ let result = await cb();
+ await BackgroundService.stop();
+ res(result);
+ }, bgTaskOptions);
+ } catch (e) {
+ res(e.message);
+ }
});
}
}
@@ -250,29 +256,29 @@ export const itemSkus = [
'com.streetwriters.notesnook.sub.yr.15',
'com.streetwriters.notesnook.sub.mo.15',
'com.streetwriters.notesnook.sub.mo.ofr',
- 'com.streetwriters.notesnook.sub.yr.ofr',
+ 'com.streetwriters.notesnook.sub.yr.ofr'
];
export const MenuItemsList = [
{
name: 'Notes',
icon: 'home-variant-outline',
- close: true,
+ close: true
},
{
name: 'Notebooks',
icon: 'book-outline',
- close: true,
+ close: true
},
{
name: 'Favorites',
icon: 'star-outline',
- close: true,
+ close: true
},
{
name: 'Tags',
icon: 'pound',
- close: true,
+ close: true
},
{
name: 'Monographs',
@@ -283,22 +289,22 @@ export const MenuItemsList = [
type: 'notes',
menu: true,
get: 'monographs',
- title:"Monographs",
- id:"monographs_navigation"
+ title: 'Monographs',
+ id: 'monographs_navigation'
});
Navigation.navigate('NotesPage', params, {
heading: 'Monographs',
id: 'monographs_navigation',
- type: 'notes',
+ type: 'notes'
});
eSendEvent(refreshNotesPage, params);
- },
+ }
},
{
name: 'Trash',
icon: 'delete-outline',
- close: true,
- },
+ close: true
+ }
];
export const SUBSCRIPTION_STATUS = {
@@ -307,7 +313,7 @@ export const SUBSCRIPTION_STATUS = {
BETA: 2,
PREMIUM: 5,
PREMIUM_EXPIRED: 6,
- PREMIUM_CANCELLED: 7,
+ PREMIUM_CANCELLED: 7
};
export const SUBSCRIPTION_STATUS_STRINGS = {
@@ -316,7 +322,7 @@ export const SUBSCRIPTION_STATUS_STRINGS = {
2: Platform.OS === 'ios' ? 'Pro' : 'Beta',
5: 'Pro',
6: 'Expired',
- 7: 'Pro',
+ 7: 'Pro'
};
export const SUBSCRIPTION_PROVIDER = {
@@ -324,74 +330,72 @@ export const SUBSCRIPTION_PROVIDER = {
1: {
type: 'iOS',
title: 'Subscribed on iOS',
- desc:
- 'You subscribed to Notesnook Pro on iOS using Apple In App Purchase. You can cancel anytime with your iTunes Account settings.',
- icon: 'ios',
+ desc: 'You subscribed to Notesnook Pro on iOS using Apple In App Purchase. You can cancel anytime with your iTunes Account settings.',
+ icon: 'ios'
},
2: {
type: 'Android',
title: 'Subscribed on Android',
- desc:
- 'You subscribed to Notesnook Pro on Android Phone/Tablet using Google In App Purchase.',
- icon: 'android',
+ desc: 'You subscribed to Notesnook Pro on Android Phone/Tablet using Google In App Purchase.',
+ icon: 'android'
},
3: {
type: 'Web',
title: 'Subscribed on Web',
desc: 'You subscribed to Notesnook Pro on the Web/Desktop App.',
- icon: 'web',
- },
+ icon: 'web'
+ }
};
export const BUTTON_TYPES = {
transparent: {
primary: 'transparent',
text: 'accent',
- selected: 'shade',
+ selected: 'shade'
},
gray: {
primary: 'transparent',
text: 'icon',
- selected: 'transGray',
+ selected: 'transGray'
},
grayBg: {
primary: 'nav',
text: 'icon',
- selected: 'nav',
+ selected: 'nav'
},
accent: (themeColor, text) => ({
primary: themeColor,
text: text,
- selected: themeColor,
+ selected: themeColor
}),
inverted: {
primary: 'bg',
text: 'accent',
- selected: 'bg',
+ selected: 'bg'
},
white: {
primary: 'transparent',
text: 'light',
- selected: 'transGray',
+ selected: 'transGray'
},
shade: {
primary: 'shade',
text: 'accent',
selected: 'accent',
- opacity: 0.12,
+ opacity: 0.12
},
error: {
primary: 'red',
text: 'red',
selected: 'red',
- opacity: 0.12,
+ opacity: 0.12
},
errorShade: {
primary: 'transparent',
text: 'red',
selected: 'red',
- opacity: 0.12,
- },
+ opacity: 0.12
+ }
};
let he;
@@ -407,7 +411,7 @@ export const TOOLTIP_POSITIONS = {
LEFT: 1,
RIGHT: 2,
TOP: 3,
- BOTTOM: 4,
+ BOTTOM: 4
};
export function showTooltip(event, text, position) {
@@ -417,7 +421,7 @@ export function showTooltip(event, text, position) {
tintColor: 'black',
corner: 40,
textSize: 14,
- position: position,
+ position: position
});
}