fix sync not working in release mode

This commit is contained in:
ammarahm-ed
2021-05-25 10:36:49 +05:00
parent 087e42f267
commit 23b57df47c
17 changed files with 88 additions and 92 deletions

View File

@@ -15,12 +15,12 @@ import {
eSendEvent, eSendEvent,
eSubscribeEvent, eSubscribeEvent,
eUnSubscribeEvent, eUnSubscribeEvent,
ToastEvent ToastEvent,
} from './src/services/EventManager'; } from './src/services/EventManager';
import { import {
clearMessage, clearMessage,
setEmailVerifyMessage, setEmailVerifyMessage,
setLoginMessage setLoginMessage,
} from './src/services/Message'; } from './src/services/Message';
import Navigation from './src/services/Navigation'; import Navigation from './src/services/Navigation';
import PremiumService from './src/services/PremiumService'; import PremiumService from './src/services/PremiumService';
@@ -34,7 +34,7 @@ import {
eCloseProgressDialog, eCloseProgressDialog,
eOpenLoginDialog, eOpenLoginDialog,
eOpenProgressDialog, eOpenProgressDialog,
refreshNotesPage refreshNotesPage,
} from './src/utils/Events'; } from './src/utils/Events';
import {MMKV} from './src/utils/mmkv'; import {MMKV} from './src/utils/mmkv';
import Storage from './src/utils/storage'; import Storage from './src/utils/storage';
@@ -84,12 +84,13 @@ async function reconnectSSE(connection) {
if (!state) { if (!state) {
state = await NetInfo.fetch(); state = await NetInfo.fetch();
} }
await doInBackground(async () => {
let user = await db.user.getUser(); let user = await db.user.getUser();
if (user && state.isConnected && state.isInternetReachable) { if (user && state.isConnected && state.isInternetReachable) {
await doInBackground(async () => {
await db.connectSSE(); await db.connectSSE();
}
}); });
}
} catch (e) {} } catch (e) {}
} }
@@ -248,17 +249,17 @@ export const AppRootEvents = React.memo(
}; };
const partialSync = async () => { const partialSync = async () => {
await doInBackground(async () => {
try { try {
dispatch({type: Actions.SYNCING, syncing: true}); dispatch({type: Actions.SYNCING, syncing: true});
await doInBackground(async () => {
await db.sync(false); await db.sync(false);
});
dispatch({type: Actions.LAST_SYNC, lastSync: await db.lastSynced()}); dispatch({type: Actions.LAST_SYNC, lastSync: await db.lastSynced()});
} catch (e) { } catch (e) {
dispatch({type: Actions.SYNCING, syncing: false}); dispatch({type: Actions.SYNCING, syncing: false});
} finally { } finally {
dispatch({type: Actions.SYNCING, syncing: false}); dispatch({type: Actions.SYNCING, syncing: false});
} }
});
}; };
const onLogout = async reason => { const onLogout = async reason => {
@@ -296,8 +297,6 @@ export const AppRootEvents = React.memo(
}; };
const setCurrentUser = async login => { const setCurrentUser = async login => {
await doInBackground(async () => {
try { try {
let user = await db.user.getUser(); let user = await db.user.getUser();
if (user) { if (user) {
@@ -306,7 +305,9 @@ export const AppRootEvents = React.memo(
await PremiumService.setPremiumStatus(); await PremiumService.setPremiumStatus();
attachIAPListeners(); attachIAPListeners();
await Sync.run(); await Sync.run();
await doInBackground(async () => {
user = await db.user.fetchUser(true); user = await db.user.fetchUser(true);
});
if (!user.isEmailConfirmed) { if (!user.isEmailConfirmed) {
setEmailVerifyMessage(dispatch); setEmailVerifyMessage(dispatch);
return; return;
@@ -331,9 +332,6 @@ export const AppRootEvents = React.memo(
eSendEvent(eCloseProgressDialog); eSendEvent(eCloseProgressDialog);
} }
} }
});
}; };
const onSuccessfulSubscription = async subscription => { const onSuccessfulSubscription = async subscription => {

View File

@@ -38,3 +38,5 @@
**[] $VALUES; **[] $VALUES;
public *; public *;
} }
-keep class **.R$* { *; }

View File

@@ -6,7 +6,7 @@ function reactNativeEventHandler(type, value) {
JSON.stringify({ JSON.stringify({
type: type, type: type,
value: value, value: value,
}) }),
); );
} }
} }
@@ -91,7 +91,6 @@ function init_tiny(size) {
'Classic=courier new;' + 'Classic=courier new;' +
'Mono=monospace;', 'Mono=monospace;',
setup: function (editor) { setup: function (editor) {
editor.ui.registry.addButton('deleteimage', { editor.ui.registry.addButton('deleteimage', {
icon: 'remove', icon: 'remove',
tooltip: 'Remove image', tooltip: 'Remove image',
@@ -100,13 +99,13 @@ function init_tiny(size) {
}, },
onclick: function () { onclick: function () {
tinymce.activeEditor.execCommand('Delete'); tinymce.activeEditor.execCommand('Delete');
}, }
}); });
editor.ui.registry.addButton('imagepreview', { editor.ui.registry.addButton('imagepreview', {
icon: 'fullscreen', icon: 'fullscreen',
tooltip: 'Preview image', tooltip: 'Preview image',
onAction: function () { onAction: function () {
if (tinymce.activeEditor.selection.getNode().tagName === 'IMG') { if (tinymce.activeEditor.selection.getNode().tagName === 'IMG') {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.responseType = 'blob'; xhr.responseType = 'blob';
@@ -124,13 +123,12 @@ function init_tiny(size) {
}; };
xhr.open( xhr.open(
'GET', 'GET',
tinymce.activeEditor.selection.getNode().getAttribute('src') tinymce.activeEditor.selection.getNode().getAttribute('src'),
); );
xhr.send(); xhr.send();
} }
}, },
onclick: function () {}, onclick: function () {}
}); });
}, },
init_instance_callback: function (edit) { init_instance_callback: function (edit) {
@@ -164,13 +162,13 @@ function init_tiny(size) {
e.preventDefault(); e.preventDefault();
e.elm.scrollIntoView({ e.elm.scrollIntoView({
behavior: 'smooth', behavior: 'smooth',
block: 'nearest', block: 'nearest'
}); });
}); });
editor.on('input', onChange); editor.on('input', onChange);
editor.on('keyup', onChange); editor.on('keyup', onChange);
editor.on('NodeChange', onChange); editor.on('NodeChange', onChange);
}, }
}); });
} }
window.prevContent = ''; window.prevContent = '';
@@ -216,9 +214,9 @@ function selectchange() {
let formats = Object.keys(editor.formatter.get()); let formats = Object.keys(editor.formatter.get());
let currentFormats = {}; let currentFormats = {};
editor.formatter editor.formatter.matchAll(formats).forEach(function (format) {
.matchAll(formats) currentFormats[format] = true;
.forEach(function(format) {currentFormats[format] = true}); });
let node = editor.selection.getNode(); let node = editor.selection.getNode();
currentFormats.hilitecolor = getNodeBg(node); currentFormats.hilitecolor = getNodeBg(node);

View File

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:keep="@drawable/ic_stat_name"/>

View File

@@ -659,7 +659,7 @@ export const ActionSheetComponent = ({
<TouchableOpacity <TouchableOpacity
activeOpacity={0.9} activeOpacity={0.9}
testID={notesnook.ids.dialogs.actionsheet.sync} testID={notesnook.ids.dialogs.actionsheet.sync}
onPress={async () => await doInBackground(()=>Sync.run('local'))} onPress={async () => await Sync.run()}
style={{ style={{
borderColor: colors.accent, borderColor: colors.accent,
paddingHorizontal: 5, paddingHorizontal: 5,

View File

@@ -41,7 +41,7 @@ const Input = ({
returnKeyType, returnKeyType,
returnKeyLabel, returnKeyLabel,
autoCompleteType, autoCompleteType,
onFocusInput onFocusInput,
}) => { }) => {
const [state] = useTracked(); const [state] = useTracked();
const colors = state.colors; const colors = state.colors;
@@ -63,7 +63,7 @@ const Input = ({
? customColor || colors.accent ? customColor || colors.accent
: colors.nav; : colors.nav;
const validate = (value) => { const validate = value => {
if (!validationType) return; if (!validationType) return;
if (!value || value?.length === 0) { if (!value || value?.length === 0) {
setError(false); setError(false);
@@ -97,7 +97,7 @@ const Input = ({
if (validationType === 'password') { if (validationType === 'password') {
let hasError = false; let hasError = false;
Object.keys(isError).forEach((e) => { Object.keys(isError).forEach(e => {
if (isError[e] === true) { if (isError[e] === true) {
hasError = true; hasError = true;
} }
@@ -111,7 +111,7 @@ const Input = ({
} }
}; };
const onChange = (value) => { const onChange = value => {
onChangeText(value); onChangeText(value);
validate(value); validate(value);
}; };
@@ -126,9 +126,8 @@ const Input = ({
const onFocus = () => { const onFocus = () => {
setFocus(true); setFocus(true);
if (onFocusInput) { if (onFocusInput) {
onFocusInput() onFocusInput();
} }
}; };
const style = { const style = {
@@ -283,9 +282,9 @@ const Input = ({
style={{ style={{
paddingTop: 5, paddingTop: 5,
}}> }}>
{Object.keys(errorList).filter((k) => errorList[k] === true) {Object.keys(errorList).filter(k => errorList[k] === true).length !==
.length !== 0 ? ( 0 ? (
Object.keys(ERRORS_LIST).map((error) => ( Object.keys(ERRORS_LIST).map(error => (
<View <View
style={{ style={{
flexDirection: 'row', flexDirection: 'row',

View File

@@ -1,13 +1,11 @@
import React from 'react'; import React from 'react';
import {Platform} from 'react-native'; import { ActivityIndicator, Platform, TouchableOpacity, View } from 'react-native';
import {ActivityIndicator, TouchableOpacity, View} from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { useSafeAreaInsets } from 'react-native-safe-area-context';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { useTracked } from '../../provider'; import { useTracked } from '../../provider';
import { DDS } from '../../services/DeviceDetection'; import { DDS } from '../../services/DeviceDetection';
import { eSendEvent, ToastEvent } from '../../services/EventManager'; import { eSendEvent, ToastEvent } from '../../services/EventManager';
import Sync from '../../services/Sync'; import Sync from '../../services/Sync';
import { doInBackground } from '../../utils';
import { eOpenLoginDialog } from '../../utils/Events'; import { eOpenLoginDialog } from '../../utils/Events';
import { SIZE } from '../../utils/SizeUtils'; import { SIZE } from '../../utils/SizeUtils';
import Heading from '../Typography/Heading'; import Heading from '../Typography/Heading';
@@ -82,7 +80,7 @@ export const UserSection = () => {
{user && ( {user && (
<TouchableOpacity <TouchableOpacity
activeOpacity={0.8} activeOpacity={0.8}
onPress={async () => await doInBackground(async ()=>await Sync.run('local'))} onPress={async ()=>await Sync.run('local')}
style={{ style={{
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center', alignItems: 'center',

View File

@@ -221,7 +221,7 @@ export const PremiumComponent = ({close, promo}) => {
? promo.text ? promo.text
: user : user
? `Subscribe for ${product?.localizedPrice || '$4.49'} / mo` ? `Subscribe for ${product?.localizedPrice || '$4.49'} / mo`
: 'Start Your Free 14 Day Trial' : 'Start Your 14 Day Free Trial'
} }
type="accent" type="accent"
height={60} height={60}

View File

@@ -79,7 +79,7 @@ const SimpleList = ({
}, [listData, deviceMode, loading]); }, [listData, deviceMode, loading]);
const _onRefresh = async () => { const _onRefresh = async () => {
await doInBackground(async () => await Sync.run('local')); await Sync.run('local');
if (refreshCallback) { if (refreshCallback) {
refreshCallback(); refreshCallback();
} }

View File

@@ -1,23 +1,20 @@
import {updateEvent} from '../components/DialogManager/recievers'; import {updateEvent} from '../components/DialogManager/recievers';
import {Actions} from '../provider/Actions'; import {Actions} from '../provider/Actions';
import {doInBackground} from '../utils';
import {db} from '../utils/DB'; import {db} from '../utils/DB';
import {eOpenLoginDialog} from '../utils/Events'; import {eOpenLoginDialog} from '../utils/Events';
import {eSendEvent, ToastEvent} from './EventManager'; import {eSendEvent, ToastEvent} from './EventManager';
import {
beginBackgroundTask,
endBackgroundTask,
} from 'react-native-begin-background-task';
import {Platform} from 'react-native';
const run = async (context = 'global') => { const run = async (context = 'global') => {
updateEvent({ updateEvent({
type: Actions.SYNCING, type: Actions.SYNCING,
syncing: true, syncing: true,
}); });
try { try {
await doInBackground(async () => {
await db.sync(); await db.sync();
});
ToastEvent.show({ ToastEvent.show({
heading: 'Sync complete', heading: 'Sync complete',
type: 'success', type: 'success',
@@ -56,7 +53,6 @@ const run = async (context = 'global') => {
type: Actions.SYNCING, type: Actions.SYNCING,
syncing: false, syncing: false,
}); });
} }
}; };

View File

@@ -195,10 +195,13 @@ export async function doInBackground(cb) {
await cb(); await cb();
await endBackgroundTask(bgTaskId); await endBackgroundTask(bgTaskId);
} else { } else {
return new Promise(async (res, rej) => {
await BackgroundService.start(async () => { await BackgroundService.start(async () => {
await cb(); await cb();
await BackgroundService.stop(); await BackgroundService.stop();
res('done');
}, bgTaskOptions); }, bgTaskOptions);
});
} }
} }