diff --git a/apps/mobile/AppRootEvents.js b/apps/mobile/AppRootEvents.js index ff2ccc80e..4d153e7da 100644 --- a/apps/mobile/AppRootEvents.js +++ b/apps/mobile/AppRootEvents.js @@ -1,45 +1,45 @@ import NetInfo from '@react-native-community/netinfo'; -import { EV, EVENTS } from 'notes-core/common'; -import React, { useEffect } from 'react'; -import { Appearance, AppState, Linking, Platform } from 'react-native'; +import {EV, EVENTS} from 'notes-core/common'; +import React, {useEffect} from 'react'; +import {Appearance, AppState, Linking, Platform} from 'react-native'; import RNExitApp from 'react-native-exit-app'; import * as RNIap from 'react-native-iap'; -import { enabled } from 'react-native-privacy-snapshot'; +import {enabled} from 'react-native-privacy-snapshot'; import SplashScreen from 'react-native-splash-screen'; -import { updateEvent } from './src/components/DialogManager/recievers'; -import { useTracked } from './src/provider'; -import { Actions } from './src/provider/Actions'; +import {updateEvent} from './src/components/DialogManager/recievers'; +import {useTracked} from './src/provider'; +import {Actions} from './src/provider/Actions'; import Backup from './src/services/Backup'; import BiometricService from './src/services/BiometricService'; import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent, - ToastEvent + ToastEvent, } from './src/services/EventManager'; import { clearMessage, setEmailVerifyMessage, - setLoginMessage + setLoginMessage, } from './src/services/Message'; import Navigation from './src/services/Navigation'; import PremiumService from './src/services/PremiumService'; import SettingsService from './src/services/SettingsService'; import Sync from './src/services/Sync'; -import { APP_VERSION, doInBackground, editing } from './src/utils'; -import { updateStatusBarColor } from './src/utils/Colors'; -import { db } from './src/utils/DB'; +import {APP_VERSION, doInBackground, editing} from './src/utils'; +import {updateStatusBarColor} from './src/utils/Colors'; +import {db} from './src/utils/DB'; import { eClearEditor, eCloseProgressDialog, eOpenLoginDialog, eOpenProgressDialog, - refreshNotesPage + refreshNotesPage, } from './src/utils/Events'; -import { MMKV } from './src/utils/mmkv'; +import {MMKV} from './src/utils/mmkv'; import Storage from './src/utils/storage'; -import { sleep } from './src/utils/TimeUtils'; -import { getNote, getWebviewInit } from './src/views/Editor/Functions'; +import {sleep} from './src/utils/TimeUtils'; +import {getNote, getWebviewInit} from './src/views/Editor/Functions'; let prevTransactionId = null; let subsriptionSuccessListener; @@ -84,12 +84,13 @@ async function reconnectSSE(connection) { if (!state) { state = await NetInfo.fetch(); } - await doInBackground(async () => { - let user = await db.user.getUser(); - if (user && state.isConnected && state.isInternetReachable) { + + let user = await db.user.getUser(); + if (user && state.isConnected && state.isInternetReachable) { + await doInBackground(async () => { await db.connectSSE(); - } - }); + }); + } } catch (e) {} } @@ -248,17 +249,17 @@ export const AppRootEvents = React.memo( }; const partialSync = async () => { - await doInBackground(async () => { - try { - dispatch({type: Actions.SYNCING, syncing: true}); + try { + dispatch({type: Actions.SYNCING, syncing: true}); + await doInBackground(async () => { await db.sync(false); - dispatch({type: Actions.LAST_SYNC, lastSync: await db.lastSynced()}); - } catch (e) { - dispatch({type: Actions.SYNCING, syncing: false}); - } finally { - dispatch({type: Actions.SYNCING, syncing: false}); - } - }); + }); + dispatch({type: Actions.LAST_SYNC, lastSync: await db.lastSynced()}); + } catch (e) { + dispatch({type: Actions.SYNCING, syncing: false}); + } finally { + dispatch({type: Actions.SYNCING, syncing: false}); + } }; const onLogout = async reason => { @@ -296,8 +297,6 @@ export const AppRootEvents = React.memo( }; const setCurrentUser = async login => { - await doInBackground(async () => { - try { let user = await db.user.getUser(); if (user) { @@ -306,7 +305,9 @@ export const AppRootEvents = React.memo( await PremiumService.setPremiumStatus(); attachIAPListeners(); await Sync.run(); - user = await db.user.fetchUser(true); + await doInBackground(async () => { + user = await db.user.fetchUser(true); + }); if (!user.isEmailConfirmed) { setEmailVerifyMessage(dispatch); return; @@ -331,9 +332,6 @@ export const AppRootEvents = React.memo( eSendEvent(eCloseProgressDialog); } } - - }); - }; const onSuccessfulSubscription = async subscription => { diff --git a/apps/mobile/android/app/proguard-rules.pro b/apps/mobile/android/app/proguard-rules.pro index 279ea497f..eee789d36 100644 --- a/apps/mobile/android/app/proguard-rules.pro +++ b/apps/mobile/android/app/proguard-rules.pro @@ -37,4 +37,6 @@ -keep public enum com.bumptech.glide.load.ImageHeaderParser$** { **[] $VALUES; public *; -} \ No newline at end of file +} + +-keep class **.R$* { *; } \ No newline at end of file diff --git a/apps/mobile/android/app/src/main/assets/init.js b/apps/mobile/android/app/src/main/assets/init.js index 49c50fa84..d506c3fbe 100755 --- a/apps/mobile/android/app/src/main/assets/init.js +++ b/apps/mobile/android/app/src/main/assets/init.js @@ -6,7 +6,7 @@ function reactNativeEventHandler(type, value) { JSON.stringify({ type: type, value: value, - }) + }), ); } } @@ -91,22 +91,21 @@ function init_tiny(size) { 'Classic=courier new;' + 'Mono=monospace;', setup: function (editor) { - editor.ui.registry.addButton('deleteimage', { icon: 'remove', - tooltip: 'Remove image', + tooltip: 'Remove image', onAction: function () { tinymce.activeEditor.execCommand('Delete'); }, onclick: function () { tinymce.activeEditor.execCommand('Delete'); - }, + } }); + editor.ui.registry.addButton('imagepreview', { icon: 'fullscreen', tooltip: 'Preview image', onAction: function () { - if (tinymce.activeEditor.selection.getNode().tagName === 'IMG') { var xhr = new XMLHttpRequest(); xhr.responseType = 'blob'; @@ -124,13 +123,12 @@ function init_tiny(size) { }; xhr.open( 'GET', - tinymce.activeEditor.selection.getNode().getAttribute('src') + tinymce.activeEditor.selection.getNode().getAttribute('src'), ); xhr.send(); } - }, - onclick: function () {}, + onclick: function () {} }); }, init_instance_callback: function (edit) { @@ -146,11 +144,11 @@ function init_tiny(size) { }); }); - editor.on('focus', function() { + editor.on('focus', function () { reactNativeEventHandler('focus', 'editor'); }); - editor.on('SetContent', function(event) { + editor.on('SetContent', function (event) { if (!event.paste) { reactNativeEventHandler('noteLoaded', true); } @@ -160,24 +158,24 @@ function init_tiny(size) { } }); - editor.on('ScrollIntoView', function(e) { + editor.on('ScrollIntoView', function (e) { e.preventDefault(); e.elm.scrollIntoView({ behavior: 'smooth', - block: 'nearest', + block: 'nearest' }); }); editor.on('input', onChange); editor.on('keyup', onChange); editor.on('NodeChange', onChange); - }, + } }); } window.prevContent = ''; -const onChange = function(event) { +const onChange = function (event) { clearTimeout(changeTimer); changeTimer = null; - changeTimer = setTimeout(function() { + changeTimer = setTimeout(function () { if (event.type === 'nodechange' && !event.selectionChange) return; if (isLoading) { isLoading = false; @@ -216,9 +214,9 @@ function selectchange() { let formats = Object.keys(editor.formatter.get()); let currentFormats = {}; - editor.formatter - .matchAll(formats) - .forEach(function(format) {currentFormats[format] = true}); + editor.formatter.matchAll(formats).forEach(function (format) { + currentFormats[format] = true; + }); let node = editor.selection.getNode(); currentFormats.hilitecolor = getNodeBg(node); diff --git a/apps/mobile/android/app/src/debug/res/drawable-anydpi-v24/ic_stat_name.xml b/apps/mobile/android/app/src/main/res/drawable-anydpi-v24/ic_stat_name.xml similarity index 100% rename from apps/mobile/android/app/src/debug/res/drawable-anydpi-v24/ic_stat_name.xml rename to apps/mobile/android/app/src/main/res/drawable-anydpi-v24/ic_stat_name.xml diff --git a/apps/mobile/android/app/src/debug/res/drawable-hdpi/ic_stat_name.png b/apps/mobile/android/app/src/main/res/drawable-hdpi/ic_stat_name.png similarity index 100% rename from apps/mobile/android/app/src/debug/res/drawable-hdpi/ic_stat_name.png rename to apps/mobile/android/app/src/main/res/drawable-hdpi/ic_stat_name.png diff --git a/apps/mobile/android/app/src/debug/res/drawable-mdpi/ic_stat_name.png b/apps/mobile/android/app/src/main/res/drawable-mdpi/ic_stat_name.png similarity index 100% rename from apps/mobile/android/app/src/debug/res/drawable-mdpi/ic_stat_name.png rename to apps/mobile/android/app/src/main/res/drawable-mdpi/ic_stat_name.png diff --git a/apps/mobile/android/app/src/debug/res/drawable-xhdpi/ic_stat_name.png b/apps/mobile/android/app/src/main/res/drawable-xhdpi/ic_stat_name.png similarity index 100% rename from apps/mobile/android/app/src/debug/res/drawable-xhdpi/ic_stat_name.png rename to apps/mobile/android/app/src/main/res/drawable-xhdpi/ic_stat_name.png diff --git a/apps/mobile/android/app/src/debug/res/drawable-xxhdpi/ic_stat_name.png b/apps/mobile/android/app/src/main/res/drawable-xxhdpi/ic_stat_name.png similarity index 100% rename from apps/mobile/android/app/src/debug/res/drawable-xxhdpi/ic_stat_name.png rename to apps/mobile/android/app/src/main/res/drawable-xxhdpi/ic_stat_name.png diff --git a/apps/mobile/android/app/src/debug/res/drawable-xxxhdpi/ic_stat_name.png b/apps/mobile/android/app/src/main/res/drawable-xxxhdpi/ic_stat_name.png similarity index 100% rename from apps/mobile/android/app/src/debug/res/drawable-xxxhdpi/ic_stat_name.png rename to apps/mobile/android/app/src/main/res/drawable-xxxhdpi/ic_stat_name.png diff --git a/apps/mobile/android/app/src/main/res/values/keep.xml b/apps/mobile/android/app/src/main/res/values/keep.xml new file mode 100644 index 000000000..597d5e8e5 --- /dev/null +++ b/apps/mobile/android/app/src/main/res/values/keep.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/apps/mobile/src/components/ActionSheetComponent/index.js b/apps/mobile/src/components/ActionSheetComponent/index.js index e4d53041e..9ce3a6f9a 100644 --- a/apps/mobile/src/components/ActionSheetComponent/index.js +++ b/apps/mobile/src/components/ActionSheetComponent/index.js @@ -659,7 +659,7 @@ export const ActionSheetComponent = ({ await doInBackground(()=>Sync.run('local'))} + onPress={async () => await Sync.run()} style={{ borderColor: colors.accent, paddingHorizontal: 5, diff --git a/apps/mobile/src/components/Input/index.js b/apps/mobile/src/components/Input/index.js index d54c118a5..7aa959eff 100644 --- a/apps/mobile/src/components/Input/index.js +++ b/apps/mobile/src/components/Input/index.js @@ -41,7 +41,7 @@ const Input = ({ returnKeyType, returnKeyLabel, autoCompleteType, - onFocusInput + onFocusInput, }) => { const [state] = useTracked(); const colors = state.colors; @@ -63,7 +63,7 @@ const Input = ({ ? customColor || colors.accent : colors.nav; - const validate = (value) => { + const validate = value => { if (!validationType) return; if (!value || value?.length === 0) { setError(false); @@ -97,7 +97,7 @@ const Input = ({ if (validationType === 'password') { let hasError = false; - Object.keys(isError).forEach((e) => { + Object.keys(isError).forEach(e => { if (isError[e] === true) { hasError = true; } @@ -111,7 +111,7 @@ const Input = ({ } }; - const onChange = (value) => { + const onChange = value => { onChangeText(value); validate(value); }; @@ -126,9 +126,8 @@ const Input = ({ const onFocus = () => { setFocus(true); if (onFocusInput) { - onFocusInput() + onFocusInput(); } - }; const style = { @@ -149,7 +148,7 @@ const Input = ({ paddingVertical: 0, paddingBottom: 2.5, flexGrow: 1, - height:35, + height: 35, }; return ( @@ -283,9 +282,9 @@ const Input = ({ style={{ paddingTop: 5, }}> - {Object.keys(errorList).filter((k) => errorList[k] === true) - .length !== 0 ? ( - Object.keys(ERRORS_LIST).map((error) => ( + {Object.keys(errorList).filter(k => errorList[k] === true).length !== + 0 ? ( + Object.keys(ERRORS_LIST).map(error => ( { const [state] = useTracked(); @@ -82,7 +80,7 @@ export const UserSection = () => { {user && ( await doInBackground(async ()=>await Sync.run('local'))} + onPress={async ()=>await Sync.run('local')} style={{ flexDirection: 'row', alignItems: 'center', diff --git a/apps/mobile/src/components/Premium/PremiumComponent.js b/apps/mobile/src/components/Premium/PremiumComponent.js index 40358f082..8b008ab94 100644 --- a/apps/mobile/src/components/Premium/PremiumComponent.js +++ b/apps/mobile/src/components/Premium/PremiumComponent.js @@ -221,7 +221,7 @@ export const PremiumComponent = ({close, promo}) => { ? promo.text : user ? `Subscribe for ${product?.localizedPrice || '$4.49'} / mo` - : 'Start Your Free 14 Day Trial' + : 'Start Your 14 Day Free Trial' } type="accent" height={60} diff --git a/apps/mobile/src/components/SimpleList/index.js b/apps/mobile/src/components/SimpleList/index.js index dd148944c..dea9fc509 100644 --- a/apps/mobile/src/components/SimpleList/index.js +++ b/apps/mobile/src/components/SimpleList/index.js @@ -79,7 +79,7 @@ const SimpleList = ({ }, [listData, deviceMode, loading]); const _onRefresh = async () => { - await doInBackground(async () => await Sync.run('local')); + await Sync.run('local'); if (refreshCallback) { refreshCallback(); } diff --git a/apps/mobile/src/services/Sync.js b/apps/mobile/src/services/Sync.js index af920c33b..4a27fe7e1 100644 --- a/apps/mobile/src/services/Sync.js +++ b/apps/mobile/src/services/Sync.js @@ -1,23 +1,20 @@ import {updateEvent} from '../components/DialogManager/recievers'; import {Actions} from '../provider/Actions'; +import {doInBackground} from '../utils'; import {db} from '../utils/DB'; import {eOpenLoginDialog} from '../utils/Events'; import {eSendEvent, ToastEvent} from './EventManager'; -import { - beginBackgroundTask, - endBackgroundTask, -} from 'react-native-begin-background-task'; -import {Platform} from 'react-native'; const run = async (context = 'global') => { - updateEvent({ type: Actions.SYNCING, syncing: true, }); try { - await db.sync(); + await doInBackground(async () => { + await db.sync(); + }); ToastEvent.show({ heading: 'Sync complete', type: 'success', @@ -56,7 +53,6 @@ const run = async (context = 'global') => { type: Actions.SYNCING, syncing: false, }); - } }; diff --git a/apps/mobile/src/utils/index.js b/apps/mobile/src/utils/index.js index 0a1f8597c..e959228e4 100755 --- a/apps/mobile/src/utils/index.js +++ b/apps/mobile/src/utils/index.js @@ -195,10 +195,13 @@ export async function doInBackground(cb) { await cb(); await endBackgroundTask(bgTaskId); } else { - await BackgroundService.start(async () => { - await cb(); - await BackgroundService.stop(); - },bgTaskOptions); + return new Promise(async (res, rej) => { + await BackgroundService.start(async () => { + await cb(); + await BackgroundService.stop(); + res('done'); + }, bgTaskOptions); + }); } }