Skip to content

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

some cleanup

ammarahm-edea652d53372d
diff --git a/apps/mobile/App.js b/apps/mobile/App.js
index d173516dd..10f93fa36 100644
--- a/apps/mobile/App.js
+++ b/apps/mobile/App.js
@@ -66,11 +66,7 @@ const App = () => {
const updateTheme = async () => {
let settings;
- try {
settings = await MMKV.getStringAsync('settings');
- } catch (e) {
- console.log(e.message);
- } finally {
if (settings) {
settings = JSON.parse(settings);
if (settings.useSystemTheme) {
@@ -78,7 +74,6 @@ const App = () => {
dispatch({type: Actions.THEME, colors: newColors});
}
}
- }
};
useEffect(() => {
@@ -155,33 +150,43 @@ const App = () => {
try {
await db.init();
user = await db.user.get();
- } catch (e) {
- error = e;
- } finally {
if (user) {
dispatch({type: Actions.USER, user: user});
await startSyncer();
- } else {
+ }
+ } catch (e) {
+ error = e;
+ console.log(e)
+ }
+ if (!user || !user.id) {
setLoginMessage(dispatch);
}
dispatch({type: Actions.ALL});
setInit(true);
- sleep(1000).then(async () => {
- settings = await MMKV.getStringAsync('settings');
- settings = JSON.parse(settings);
- if (await Backup.checkBackupRequired(settings.reminder)) {
- await Backup.run();
- }
- });
+ backupData();
+
if (error) {
setTimeout(() => {
ToastEvent.show(error.message);
}, 500);
}
- }
+
});
}, []);
+ async function backupData() {
+ await sleep(1000)
+ settings = await MMKV.getStringAsync('settings');
+ settings = JSON.parse(settings);
+ if (await Backup.checkBackupRequired(settings.reminder) ) {
+ try {
+ await Backup.run();
+ } catch(e) {
+ console.log(e);
+ }
+ }
+ }
+
async function Initialize() {
let settings;
scale.fontScale = 1;
@@ -195,25 +200,21 @@ const App = () => {
}
firstLoad = false;
}
-
- try {
settings = await MMKV.getStringAsync('settings');
- settings = JSON.parse(settings);
-
- if (settings.fontScale) {
- scale.fontScale = settings.fontScale;
- }
- updateSize();
- } catch (e) {
- if (!settings || !settings.includes('fontScale')) {
+ console.log('settings',settings)
+ if (!settings) {
settings = defaultState.settings;
await MMKV.setStringAsync('settings', JSON.stringify(settings));
+ } else {
+ settings = JSON.parse(settings);
+ }
+ if (settings.fontScale) {
+ scale.fontScale = settings.fontScale;
}
- } finally {
- let newColors = await getColorScheme(settings.useSystemTheme);
dispatch({type: Actions.SETTINGS, settings: {...settings}});
- dispatch({type: Actions.THEME, colors: newColors});
- }
+ updateSize();
+ await updateTheme();
+
}
if (!init) {
diff --git a/apps/mobile/android/app/src/main/assets/listeners.js b/apps/mobile/android/app/src/main/assets/listeners.js
index 6d2969d01..1ecbd0b48 100644
--- a/apps/mobile/android/app/src/main/assets/listeners.js
+++ b/apps/mobile/android/app/src/main/assets/listeners.js
@@ -163,6 +163,7 @@ function attachEditorListeners() {
editor.on("selection-change", function(evt) {
console.log(evt);
+ if (evt.length > 0) return;
var bounds = editor.getBounds(evt.index, evt.index);
console.log(bounds)
setTimeout(() => {
diff --git a/apps/mobile/android/gradle.properties b/apps/mobile/android/gradle.properties
index af6300a0b..ebebe3d93 100644
--- a/apps/mobile/android/gradle.properties
+++ b/apps/mobile/android/gradle.properties
@@ -25,4 +25,4 @@ android.useAndroidX=true
android.enableJetifier=true
# Version of flipper SDK to use with React Native
-FLIPPER_VERSION=0.37.0
+FLIPPER_VERSION=0.54.0
diff --git a/apps/mobile/src/components/LoginDialog/index.js b/apps/mobile/src/components/LoginDialog/index.js
index 2a4815394..a420cfa94 100644
--- a/apps/mobile/src/components/LoginDialog/index.js
+++ b/apps/mobile/src/components/LoginDialog/index.js
@@ -122,7 +122,7 @@ const LoginDialog = () => {
try {
let user = await db.user.get();
if (!user) throw new Error('Username or password incorrect');
- setStatus('Syncing your notes');
+ setStatus('Syncing your notes');
dispatch({type: Actions.USER, user: user});
dispatch({type: Actions.SYNCING, syncing: true});
await db.sync();
diff --git a/apps/mobile/src/services/Backup.js b/apps/mobile/src/services/Backup.js
index 6fbdca8ca..2efd16c84 100644
--- a/apps/mobile/src/services/Backup.js
+++ b/apps/mobile/src/services/Backup.js
@@ -2,6 +2,7 @@ const {MMKV} = require('../utils/MMKV');
import RNFetchBlob from 'rn-fetch-blob';
import storage from '../utils/storage';
import {db} from '../utils/DB';
+import { ToastEvent } from './EventManager';
async function run() {
if (Platform.OS === 'android') {
@@ -27,13 +28,7 @@ async function run() {
}
async function getLastBackupDate() {
- let date;
- try {
- date = await MMKV.getItem('backupDate');
- } catch (e) {
- date = 'never';
- }
- return date;
+ return await MMKV.getItem('backupDate');
}
const MS_DAY = 86400000;
const MS_WEEK = MS_DAY * 7;
diff --git a/apps/mobile/src/utils/ColorUtils.js b/apps/mobile/src/utils/ColorUtils.js
index 0b63fe98c..69a0ceff1 100644
--- a/apps/mobile/src/utils/ColorUtils.js
+++ b/apps/mobile/src/utils/ColorUtils.js
@@ -63,19 +63,12 @@ export const RGB_Linear_Shade = (p, rgba) => {
};
export async function getColorScheme(useSystemTheme) {
- let accentColor;
- let theme;
- try {
- accentColor = await MMKV.getStringAsync('accentColor');
- } catch (e) {
- }
-
- try {
- theme = await MMKV.getStringAsync('theme');
- } catch (e) {
- }
+
+ let accentColor = await MMKV.getStringAsync('accentColor');
+ let theme= await MMKV.getStringAsync('theme');
+
- if (typeof accentColor !== 'string') {
+ if (!accentColor ) {
MMKV.setStringAsync('accentColor', '#0560FF');
setAccentColor('#0560FF');
} else {
@@ -94,7 +87,7 @@ export async function getColorScheme(useSystemTheme) {
return COLOR_SCHEME;
}
- if (typeof theme !== 'string') {
+ if (!theme) {
MMKV.setStringAsync('theme', JSON.stringify({night: false}));
setColorScheme(COLOR_SCHEME_LIGHT);
diff --git a/apps/mobile/src/utils/DB.js b/apps/mobile/src/utils/DB.js
index 6832f042d..e25f378e9 100644
--- a/apps/mobile/src/utils/DB.js
+++ b/apps/mobile/src/utils/DB.js
@@ -9,4 +9,4 @@ export const db = new Database(
Storage,
Platform.OS === 'ios' ? EventSource : AndroidEventSource,
);
-db.host("https://192.168.10.8:5000")
+db.host("https://api.notesnook.com")
diff --git a/apps/mobile/src/utils/Storage.js b/apps/mobile/src/utils/Storage.js
index 94eec816f..241d30d9e 100644
--- a/apps/mobile/src/utils/Storage.js
+++ b/apps/mobile/src/utils/Storage.js
@@ -8,17 +8,15 @@ import { Platform } from "react-native";
import { ANDROID_PATH, IOS_PATH } from ".";
async function read(key, isArray = false) {
- let data;
-
- try {
- data = await MMKV.getItem(key);
- } catch (e) {}
+ let data = await MMKV.getItem(key);
if (!data) return null;
try {
data = JSON.parse(data);
data = isArray ? [...data] : data;
- } catch (e) {}
+ } catch (e) {
+
+ }
return data;
}
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index 98c84ceaa..ab7d31efc 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -70,6 +70,7 @@ export const Home = ({navigation}) => {
}, [notes]);
const _onPressBottomButton = async () => {
+
eSendEvent(eOnLoadNote, {type: 'new'});
if (DDS.isPhone || DDS.isSmallTab) {