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

@@ -1,45 +1,45 @@
import NetInfo from '@react-native-community/netinfo'; import NetInfo from '@react-native-community/netinfo';
import { EV, EVENTS } from 'notes-core/common'; import {EV, EVENTS} from 'notes-core/common';
import React, { useEffect } from 'react'; import React, {useEffect} from 'react';
import { Appearance, AppState, Linking, Platform } from 'react-native'; import {Appearance, AppState, Linking, Platform} from 'react-native';
import RNExitApp from 'react-native-exit-app'; import RNExitApp from 'react-native-exit-app';
import * as RNIap from 'react-native-iap'; 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 SplashScreen from 'react-native-splash-screen';
import { updateEvent } from './src/components/DialogManager/recievers'; import {updateEvent} from './src/components/DialogManager/recievers';
import { useTracked } from './src/provider'; import {useTracked} from './src/provider';
import { Actions } from './src/provider/Actions'; import {Actions} from './src/provider/Actions';
import Backup from './src/services/Backup'; import Backup from './src/services/Backup';
import BiometricService from './src/services/BiometricService'; import BiometricService from './src/services/BiometricService';
import { 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';
import SettingsService from './src/services/SettingsService'; import SettingsService from './src/services/SettingsService';
import Sync from './src/services/Sync'; import Sync from './src/services/Sync';
import { APP_VERSION, doInBackground, editing } from './src/utils'; import {APP_VERSION, doInBackground, editing} from './src/utils';
import { updateStatusBarColor } from './src/utils/Colors'; import {updateStatusBarColor} from './src/utils/Colors';
import { db } from './src/utils/DB'; import {db} from './src/utils/DB';
import { import {
eClearEditor, eClearEditor,
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';
import { sleep } from './src/utils/TimeUtils'; import {sleep} from './src/utils/TimeUtils';
import { getNote, getWebviewInit } from './src/views/Editor/Functions'; import {getNote, getWebviewInit} from './src/views/Editor/Functions';
let prevTransactionId = null; let prevTransactionId = null;
let subsriptionSuccessListener; let subsriptionSuccessListener;
@@ -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()}); });
} catch (e) { dispatch({type: Actions.LAST_SYNC, lastSync: await db.lastSynced()});
dispatch({type: Actions.SYNCING, syncing: false}); } catch (e) {
} finally { dispatch({type: Actions.SYNCING, syncing: false});
dispatch({type: Actions.SYNCING, syncing: false}); } finally {
} 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();
user = await db.user.fetchUser(true); await doInBackground(async () => {
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

@@ -37,4 +37,6 @@
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** { -keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
**[] $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,22 +91,21 @@ 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',
onAction: function () { onAction: function () {
tinymce.activeEditor.execCommand('Delete'); tinymce.activeEditor.execCommand('Delete');
}, },
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) {
@@ -146,11 +144,11 @@ function init_tiny(size) {
}); });
}); });
editor.on('focus', function() { editor.on('focus', function () {
reactNativeEventHandler('focus', 'editor'); reactNativeEventHandler('focus', 'editor');
}); });
editor.on('SetContent', function(event) { editor.on('SetContent', function (event) {
if (!event.paste) { if (!event.paste) {
reactNativeEventHandler('noteLoaded', true); reactNativeEventHandler('noteLoaded', true);
} }
@@ -160,24 +158,24 @@ function init_tiny(size) {
} }
}); });
editor.on('ScrollIntoView', function(e) { editor.on('ScrollIntoView', function (e) {
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 = '';
const onChange = function(event) { const onChange = function (event) {
clearTimeout(changeTimer); clearTimeout(changeTimer);
changeTimer = null; changeTimer = null;
changeTimer = setTimeout(function() { changeTimer = setTimeout(function () {
if (event.type === 'nodechange' && !event.selectionChange) return; if (event.type === 'nodechange' && !event.selectionChange) return;
if (isLoading) { if (isLoading) {
isLoading = false; isLoading = false;
@@ -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 = {
@@ -149,7 +148,7 @@ const Input = ({
paddingVertical: 0, paddingVertical: 0,
paddingBottom: 2.5, paddingBottom: 2.5,
flexGrow: 1, flexGrow: 1,
height:35, height: 35,
}; };
return ( return (
@@ -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,18 +1,16 @@
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';
import Paragraph from '../Typography/Paragraph'; import Paragraph from '../Typography/Paragraph';
import {TimeSince} from './TimeSince'; import { TimeSince } from './TimeSince';
export const UserSection = () => { export const UserSection = () => {
const [state] = useTracked(); const [state] = useTracked();
@@ -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 db.sync(); await doInBackground(async () => {
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 {
await BackgroundService.start(async () => { return new Promise(async (res, rej) => {
await cb(); await BackgroundService.start(async () => {
await BackgroundService.stop(); await cb();
},bgTaskOptions); await BackgroundService.stop();
res('done');
}, bgTaskOptions);
});
} }
} }