2020-11-16 12:36:41 +05:00
|
|
|
import * as NetInfo from '@react-native-community/netinfo';
|
2021-01-05 11:05:52 +05:00
|
|
|
import {EV} from 'notes-core/common';
|
|
|
|
|
import React, {useEffect} from 'react';
|
2020-11-24 16:59:12 +05:00
|
|
|
import {
|
|
|
|
|
Appearance,
|
|
|
|
|
AppState,
|
|
|
|
|
Linking,
|
|
|
|
|
NativeModules,
|
|
|
|
|
Platform,
|
2021-01-05 11:05:52 +05:00
|
|
|
StatusBar,
|
2020-11-24 16:59:12 +05:00
|
|
|
} from 'react-native';
|
2020-12-09 22:16:22 +05:00
|
|
|
import * as RNIap from 'react-native-iap';
|
2021-01-05 11:05:52 +05:00
|
|
|
import {enabled} from 'react-native-privacy-snapshot';
|
|
|
|
|
import {SafeAreaProvider} from 'react-native-safe-area-context';
|
2020-12-10 09:54:48 +05:00
|
|
|
import SplashScreen from 'react-native-splash-screen';
|
2021-01-05 11:05:52 +05:00
|
|
|
import {RootView} from './initializer.root';
|
|
|
|
|
import {useTracked} from './src/provider';
|
|
|
|
|
import {Actions} from './src/provider/Actions';
|
2020-12-20 23:01:35 +05:00
|
|
|
import Backup from './src/services/Backup';
|
2021-01-05 11:05:52 +05:00
|
|
|
import {DDS} from './src/services/DeviceDetection';
|
2020-10-24 13:47:31 +05:00
|
|
|
import {
|
2020-11-24 16:59:12 +05:00
|
|
|
eSendEvent,
|
2020-10-24 13:47:31 +05:00
|
|
|
eSubscribeEvent,
|
2021-01-05 11:05:52 +05:00
|
|
|
eUnSubscribeEvent,
|
2020-10-24 13:47:31 +05:00
|
|
|
} from './src/services/EventManager';
|
2020-12-10 09:54:48 +05:00
|
|
|
import IntentService from './src/services/IntentService';
|
2020-12-16 14:57:58 +05:00
|
|
|
import {
|
|
|
|
|
clearMessage,
|
|
|
|
|
setEmailVerifyMessage,
|
2021-01-05 11:05:52 +05:00
|
|
|
setLoginMessage,
|
2020-12-16 14:57:58 +05:00
|
|
|
} from './src/services/Message';
|
2020-12-10 09:54:48 +05:00
|
|
|
import Navigation from './src/services/Navigation';
|
|
|
|
|
import PremiumService from './src/services/PremiumService';
|
2020-12-20 23:03:02 +05:00
|
|
|
import SettingsService from './src/services/SettingsService';
|
2020-12-20 23:01:35 +05:00
|
|
|
import Sync from './src/services/Sync';
|
2021-01-05 11:05:52 +05:00
|
|
|
import {
|
2021-01-05 15:18:30 +05:00
|
|
|
APP_VERSION,
|
2021-01-05 11:05:52 +05:00
|
|
|
editing,
|
|
|
|
|
getAppIsIntialized,
|
|
|
|
|
getIntentOnAppLoadProcessed,
|
|
|
|
|
setAppIsInitialized,
|
|
|
|
|
setIntentOnAppLoadProcessed,
|
|
|
|
|
} from './src/utils';
|
|
|
|
|
import {COLOR_SCHEME} from './src/utils/Colors';
|
|
|
|
|
import {db} from './src/utils/DB';
|
2020-12-06 09:53:17 +05:00
|
|
|
import {
|
2020-12-09 22:16:22 +05:00
|
|
|
eClosePremiumDialog,
|
2020-12-23 13:25:10 +05:00
|
|
|
eCloseProgressDialog,
|
2020-12-06 09:53:17 +05:00
|
|
|
eDispatchAction,
|
|
|
|
|
eOnLoadNote,
|
2020-12-16 20:02:24 +05:00
|
|
|
eOpenLoginDialog,
|
2020-12-09 22:16:22 +05:00
|
|
|
eOpenPendingDialog,
|
2020-12-16 20:02:24 +05:00
|
|
|
eOpenProgressDialog,
|
2020-12-14 14:03:35 +05:00
|
|
|
eOpenSideMenu,
|
2021-01-05 11:05:52 +05:00
|
|
|
refreshNotesPage,
|
2020-12-06 09:53:17 +05:00
|
|
|
} from './src/utils/Events';
|
2021-01-05 11:05:52 +05:00
|
|
|
import {MMKV} from './src/utils/mmkv';
|
|
|
|
|
import {tabBarRef} from './src/utils/Refs';
|
|
|
|
|
import {sleep} from './src/utils/TimeUtils';
|
|
|
|
|
import {getNote, setIntent} from './src/views/Editor/Functions';
|
2020-11-24 16:59:12 +05:00
|
|
|
const {ReceiveSharingIntent} = NativeModules;
|
2020-11-17 16:18:43 +05:00
|
|
|
|
2020-11-23 11:30:55 +05:00
|
|
|
let Sentry = null;
|
2020-12-09 22:16:22 +05:00
|
|
|
let hasPurchased = false;
|
2020-12-20 23:01:35 +05:00
|
|
|
|
|
|
|
|
function updateStatusBarColor() {
|
|
|
|
|
StatusBar.setBarStyle(
|
|
|
|
|
COLOR_SCHEME.night ? 'light-content' : 'dark-content',
|
|
|
|
|
true,
|
|
|
|
|
);
|
|
|
|
|
if (Platform.OS === 'android') {
|
|
|
|
|
StatusBar.setBackgroundColor('transparent', true);
|
|
|
|
|
StatusBar.setTranslucent(true, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-18 18:18:27 +05:00
|
|
|
const onAppStateChanged = async (state) => {
|
|
|
|
|
if (state === 'active') {
|
2020-12-20 23:01:35 +05:00
|
|
|
updateStatusBarColor();
|
2020-11-18 18:18:27 +05:00
|
|
|
if (SettingsService.get().privacyScreen) {
|
|
|
|
|
enabled(false);
|
2021-01-05 11:05:52 +05:00
|
|
|
}
|
2020-12-29 17:18:20 +05:00
|
|
|
if (getAppIsIntialized()) {
|
2020-11-23 15:57:31 +05:00
|
|
|
await MMKV.removeItem('appState');
|
2020-11-24 18:12:35 +05:00
|
|
|
}
|
2020-12-06 09:53:17 +05:00
|
|
|
try {
|
2020-12-29 17:18:20 +05:00
|
|
|
if (getIntentOnAppLoadProcessed()) {
|
2020-12-06 09:53:17 +05:00
|
|
|
if (Platform.OS === 'android') {
|
2021-01-06 16:21:50 +05:00
|
|
|
console.log('calling intent from here too');
|
2020-12-20 23:01:35 +05:00
|
|
|
let intent = await ReceiveSharingIntent.getFileNames();
|
2021-01-06 16:21:50 +05:00
|
|
|
console.log("INTENT RECIEVED",intent);
|
2020-12-20 23:01:35 +05:00
|
|
|
if (intent) {
|
|
|
|
|
IntentService.setIntent(intent);
|
|
|
|
|
IntentService.check(loadIntent);
|
2020-12-06 09:53:17 +05:00
|
|
|
}
|
2021-01-06 16:21:50 +05:00
|
|
|
ReceiveSharingIntent.clearFileNames();
|
2020-11-24 16:59:12 +05:00
|
|
|
}
|
2020-12-29 11:26:01 +05:00
|
|
|
} else {
|
|
|
|
|
if (!db || !db.notes) return;
|
|
|
|
|
if (!getNote()) {
|
|
|
|
|
eSendEvent('nointent');
|
|
|
|
|
} else {
|
|
|
|
|
SplashScreen.hide();
|
|
|
|
|
}
|
2020-11-24 16:59:12 +05:00
|
|
|
}
|
2020-12-20 23:01:35 +05:00
|
|
|
} catch (e) {}
|
2020-11-18 18:18:27 +05:00
|
|
|
} else {
|
2020-12-30 15:20:16 +05:00
|
|
|
if (editing.currentlyEditing && getAppIsIntialized()) {
|
2020-11-23 15:57:31 +05:00
|
|
|
let state = JSON.stringify({
|
|
|
|
|
editing: editing.currentlyEditing,
|
|
|
|
|
note: getNote(),
|
|
|
|
|
});
|
|
|
|
|
await MMKV.setItem('appState', state);
|
2020-11-23 11:30:55 +05:00
|
|
|
}
|
|
|
|
|
|
2020-11-18 18:18:27 +05:00
|
|
|
if (SettingsService.get().privacyScreen) {
|
|
|
|
|
enabled(true);
|
|
|
|
|
}
|
2020-11-16 12:18:59 +05:00
|
|
|
}
|
2020-11-16 12:13:02 +05:00
|
|
|
};
|
|
|
|
|
|
2020-12-20 23:01:35 +05:00
|
|
|
function loadIntent(event) {
|
|
|
|
|
if (event) {
|
2020-12-22 12:38:31 +05:00
|
|
|
setIntent();
|
2020-12-20 23:01:35 +05:00
|
|
|
eSendEvent(eOnLoadNote, event);
|
|
|
|
|
tabBarRef.current?.goToPage(1);
|
|
|
|
|
Navigation.closeDrawer();
|
|
|
|
|
} else {
|
|
|
|
|
eSendEvent('nointent');
|
|
|
|
|
SplashScreen.hide();
|
|
|
|
|
sleep(300).then(() => eSendEvent(eOpenSideMenu));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-16 12:36:41 +05:00
|
|
|
const onNetworkStateChanged = (netInfo) => {
|
2020-12-14 14:03:35 +05:00
|
|
|
/* let message = 'Internet connection restored';
|
2020-11-16 12:36:41 +05:00
|
|
|
let type = 'success';
|
|
|
|
|
if (!netInfo.isConnected || !netInfo.isInternetReachable) {
|
|
|
|
|
message = 'No internet connection';
|
|
|
|
|
type = 'error';
|
|
|
|
|
}
|
|
|
|
|
db.user?.get().then((user) => {
|
2020-12-20 23:01:35 +05:00
|
|
|
if (user && intentOnAppLoadProcessed) {
|
2020-11-16 12:36:41 +05:00
|
|
|
ToastEvent.show(message, type);
|
|
|
|
|
}
|
2020-12-12 10:04:34 +05:00
|
|
|
}); */
|
2020-11-16 12:36:41 +05:00
|
|
|
};
|
|
|
|
|
|
2019-11-15 01:17:59 +05:00
|
|
|
const App = () => {
|
2020-12-22 12:38:31 +05:00
|
|
|
const [, dispatch] = useTracked();
|
2020-11-16 12:36:41 +05:00
|
|
|
|
2020-12-20 23:01:35 +05:00
|
|
|
let subsriptionSuccessListerner;
|
|
|
|
|
let subsriptionErrorListener;
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
eSubscribeEvent(eDispatchAction, (type) => {
|
|
|
|
|
dispatch(type);
|
|
|
|
|
});
|
|
|
|
|
attachIAPListeners();
|
|
|
|
|
AppState.addEventListener('change', onAppStateChanged);
|
|
|
|
|
eSubscribeEvent('nointent', loadMainApp);
|
|
|
|
|
Appearance.addChangeListener(SettingsService.setTheme);
|
|
|
|
|
let unsub = NetInfo.addEventListener(onNetworkStateChanged);
|
|
|
|
|
Linking.addEventListener('url', onUrlRecieved);
|
|
|
|
|
EV.subscribe('db:refresh', onSyncComplete);
|
|
|
|
|
EV.subscribe('db:sync', partialSync);
|
|
|
|
|
EV.subscribe('user:loggedOut', onLogout);
|
|
|
|
|
EV.subscribe('user:checkStatus', PremiumService.onUserStatusCheck);
|
|
|
|
|
return () => {
|
2021-01-06 16:21:50 +05:00
|
|
|
setIntentOnAppLoadProcessed(false);
|
|
|
|
|
setAppIsInitialized(false);
|
2020-12-20 23:01:35 +05:00
|
|
|
EV.subscribe('db:refresh', onSyncComplete);
|
|
|
|
|
EV.unsubscribe('user:loggedOut', onLogout);
|
|
|
|
|
EV.unsubscribe('db:sync', partialSync);
|
|
|
|
|
EV.unsubscribe('user:checkStatus', PremiumService.onUserStatusCheck);
|
|
|
|
|
eUnSubscribeEvent(eDispatchAction, (type) => {
|
|
|
|
|
dispatch(type);
|
|
|
|
|
});
|
|
|
|
|
eUnSubscribeEvent('nointent', loadMainApp);
|
|
|
|
|
AppState.removeEventListener('change', onAppStateChanged);
|
|
|
|
|
Appearance.removeChangeListener(SettingsService.setTheme);
|
|
|
|
|
Linking.removeEventListener('url', onUrlRecieved);
|
|
|
|
|
unsub();
|
|
|
|
|
unsubIAP();
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2020-12-29 11:26:01 +05:00
|
|
|
SettingsService.init().then((r) => console.log);
|
2020-12-20 23:01:35 +05:00
|
|
|
dispatch({
|
|
|
|
|
type: Actions.DEVICE_MODE,
|
|
|
|
|
state: DDS.isLargeTablet()
|
|
|
|
|
? 'tablet'
|
|
|
|
|
: DDS.isSmallTab
|
|
|
|
|
? 'smallTablet'
|
|
|
|
|
: 'mobile',
|
|
|
|
|
});
|
|
|
|
|
db.init().catch(console.log).finally(runAfterInit);
|
|
|
|
|
}, []);
|
2020-10-12 11:24:56 +05:00
|
|
|
|
2020-12-20 23:01:35 +05:00
|
|
|
const onSyncComplete = async () => {
|
|
|
|
|
dispatch({type: Actions.ALL});
|
2020-12-28 14:22:23 +05:00
|
|
|
dispatch({type: Actions.LAST_SYNC, lastSync: await db.lastSynced()});
|
2020-11-16 12:36:41 +05:00
|
|
|
};
|
|
|
|
|
|
2020-12-20 23:01:35 +05:00
|
|
|
const onUrlRecieved = async (res) => {
|
2020-12-29 17:18:20 +05:00
|
|
|
if (getIntentOnAppLoadProcessed()) {
|
2020-12-06 09:53:17 +05:00
|
|
|
let url = res ? res.url : '';
|
|
|
|
|
try {
|
2020-12-16 14:57:58 +05:00
|
|
|
if (Platform.OS === 'ios' && url.startsWith('ShareMedia://dataUrl')) {
|
2020-12-20 23:01:35 +05:00
|
|
|
let intent = await ReceiveSharingIntent.getFileNames(url);
|
|
|
|
|
intent = IntentService.iosSortedData(intent);
|
2020-12-16 14:57:58 +05:00
|
|
|
|
2020-12-20 23:01:35 +05:00
|
|
|
if (intent) {
|
|
|
|
|
IntentService.setIntent(intent);
|
|
|
|
|
IntentService.check(loadIntent);
|
2020-12-16 14:57:58 +05:00
|
|
|
}
|
2021-01-05 11:05:52 +05:00
|
|
|
} else if (
|
|
|
|
|
url.startsWith('https://app.notesnook.com/account/verified')
|
|
|
|
|
) {
|
2020-12-23 13:25:10 +05:00
|
|
|
await onEmailVerified();
|
2021-01-05 00:23:19 +05:00
|
|
|
} else {
|
|
|
|
|
return;
|
2020-12-06 09:53:17 +05:00
|
|
|
}
|
2020-12-20 23:01:35 +05:00
|
|
|
} catch (e) {}
|
2020-12-06 09:53:17 +05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-23 13:25:10 +05:00
|
|
|
const onEmailVerified = async () => {
|
2021-01-04 14:04:48 +05:00
|
|
|
let user = await db.user.fetchUser(true);
|
2020-12-23 13:25:10 +05:00
|
|
|
dispatch({type: Actions.USER, user: user});
|
2020-12-29 11:57:04 +05:00
|
|
|
if (!user) return;
|
2020-12-23 13:25:10 +05:00
|
|
|
let message =
|
|
|
|
|
user?.subscription?.type === 2
|
|
|
|
|
? 'Thank you for signing up for Notesnook Beta Program. Enjoy all premium features for free for the next 3 months.'
|
|
|
|
|
: 'Your Notesnook Pro Trial has been activated. Enjoy all premium features for free for the next 14 days!';
|
|
|
|
|
eSendEvent(eOpenProgressDialog, {
|
|
|
|
|
title: 'Email Confirmed!',
|
|
|
|
|
paragraph: message,
|
|
|
|
|
noProgress: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (user?.isEmailConfirmed) {
|
|
|
|
|
clearMessage(dispatch);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-09 22:16:22 +05:00
|
|
|
const attachIAPListeners = () => {
|
|
|
|
|
if (Platform.OS === 'ios') {
|
|
|
|
|
RNIap.getReceiptIOS()
|
|
|
|
|
.then((r) => {
|
|
|
|
|
hasPurchased = true;
|
|
|
|
|
processReceipt(r);
|
|
|
|
|
})
|
|
|
|
|
.catch(console.log)
|
|
|
|
|
.finally(() => {
|
|
|
|
|
subsriptionSuccessListerner = RNIap.purchaseUpdatedListener(
|
|
|
|
|
onSuccessfulSubscription,
|
|
|
|
|
);
|
|
|
|
|
subsriptionErrorListener = RNIap.purchaseErrorListener(
|
|
|
|
|
onSubscriptionError,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
subsriptionSuccessListerner = RNIap.purchaseUpdatedListener(
|
|
|
|
|
onSuccessfulSubscription,
|
|
|
|
|
);
|
|
|
|
|
subsriptionErrorListener = RNIap.purchaseErrorListener(
|
|
|
|
|
onSubscriptionError,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-20 23:01:35 +05:00
|
|
|
const partialSync = async () => {
|
2020-12-10 15:26:02 +05:00
|
|
|
try {
|
|
|
|
|
dispatch({type: Actions.SYNCING, syncing: true});
|
|
|
|
|
await db.sync(false);
|
2020-12-16 14:57:58 +05:00
|
|
|
dispatch({type: Actions.LAST_SYNC, lastSync: await db.lastSynced()});
|
2020-12-10 15:26:02 +05:00
|
|
|
} catch (e) {
|
|
|
|
|
} finally {
|
|
|
|
|
dispatch({type: Actions.SYNCING, syncing: false});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-16 20:02:24 +05:00
|
|
|
const onLogout = (reason) => {
|
2021-01-05 11:05:52 +05:00
|
|
|
dispatch({type: Actions.USER, user: null});
|
|
|
|
|
dispatch({type: Actions.CLEAR_ALL});
|
|
|
|
|
dispatch({type: Actions.SYNCING, syncing: false});
|
|
|
|
|
setLoginMessage(dispatch);
|
2020-12-16 20:02:24 +05:00
|
|
|
eSendEvent(eOpenProgressDialog, {
|
2021-01-05 11:05:52 +05:00
|
|
|
title: reason ? reason : 'User Logged Out',
|
|
|
|
|
paragraph: `You have been logged out of your account.`,
|
2020-12-28 14:22:23 +05:00
|
|
|
action: async () => {
|
|
|
|
|
eSendEvent(eCloseProgressDialog);
|
2020-12-29 11:26:01 +05:00
|
|
|
await sleep(50);
|
2020-12-16 20:02:24 +05:00
|
|
|
eSendEvent(eOpenLoginDialog);
|
|
|
|
|
},
|
2020-12-23 13:25:10 +05:00
|
|
|
icon: 'logout',
|
2020-12-16 20:02:24 +05:00
|
|
|
actionText: 'Login Again',
|
|
|
|
|
noProgress: true,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-09 22:16:22 +05:00
|
|
|
unsubIAP = () => {
|
|
|
|
|
if (subsriptionSuccessListerner) {
|
|
|
|
|
subsriptionSuccessListerner?.remove();
|
|
|
|
|
subsriptionSuccessListerner = null;
|
|
|
|
|
}
|
|
|
|
|
if (subsriptionErrorListener) {
|
|
|
|
|
subsriptionErrorListener?.remove();
|
|
|
|
|
subsriptionErrorListener = null;
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-12-09 13:09:55 +05:00
|
|
|
|
2020-12-09 22:16:22 +05:00
|
|
|
const loadMainApp = () => {
|
2020-12-22 12:38:31 +05:00
|
|
|
dispatch({type: Actions.INTENT_MODE, state: false});
|
2020-11-24 16:59:12 +05:00
|
|
|
dispatch({type: Actions.ALL});
|
2020-12-20 23:01:35 +05:00
|
|
|
setCurrentUser().then(console.log).catch(console.log);
|
|
|
|
|
Backup.checkAndRun().then((r) => r);
|
2020-12-29 17:18:20 +05:00
|
|
|
sleep(500).then(() => setAppIsInitialized(true));
|
2020-11-24 16:59:12 +05:00
|
|
|
db.notes.init().then(() => {
|
|
|
|
|
dispatch({type: Actions.NOTES});
|
2020-12-16 15:55:36 +05:00
|
|
|
dispatch({type: Actions.FAVORITES});
|
2020-12-16 20:02:24 +05:00
|
|
|
eSendEvent(refreshNotesPage);
|
2020-11-24 16:59:12 +05:00
|
|
|
dispatch({type: Actions.LOADING, loading: false});
|
2020-11-26 11:20:38 +05:00
|
|
|
SettingsService.setAppLoaded();
|
2020-11-24 16:59:12 +05:00
|
|
|
});
|
2020-12-09 22:16:22 +05:00
|
|
|
SplashScreen.hide();
|
2020-12-23 13:25:10 +05:00
|
|
|
Linking.getInitialURL().then(async (url) => {
|
|
|
|
|
if (url && url.startsWith('https://notesnook.com')) {
|
|
|
|
|
await onEmailVerified();
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-01-05 11:05:52 +05:00
|
|
|
setIntentOnAppLoadProcessed(true);
|
2021-01-05 15:18:30 +05:00
|
|
|
sleep(300).then(() => {
|
|
|
|
|
eSendEvent(eOpenSideMenu);
|
|
|
|
|
db.version()
|
|
|
|
|
.then((ver) => {
|
2021-01-05 15:20:04 +05:00
|
|
|
if (ver.mobile > APP_VERSION) {
|
2021-01-05 15:18:30 +05:00
|
|
|
eSendEvent('updateDialog', ver);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(console.log);
|
|
|
|
|
});
|
|
|
|
|
|
2020-11-23 17:36:13 +05:00
|
|
|
//Sentry = require('@sentry/react-native');
|
2020-11-24 16:59:12 +05:00
|
|
|
// Sentry.init({
|
|
|
|
|
// dsn:
|
|
|
|
|
// 'https://317a5c31caf64d1e9b27abf15eb1a554@o477952.ingest.sentry.io/5519681',
|
|
|
|
|
// });
|
2020-11-23 11:30:55 +05:00
|
|
|
};
|
|
|
|
|
|
2020-12-20 23:01:35 +05:00
|
|
|
const setCurrentUser = async () => {
|
2020-11-23 11:30:55 +05:00
|
|
|
try {
|
2021-01-04 14:04:48 +05:00
|
|
|
let user = await db.user.getUser(true);
|
2020-11-23 11:30:55 +05:00
|
|
|
if (user) {
|
2020-12-16 14:57:58 +05:00
|
|
|
clearMessage(dispatch);
|
|
|
|
|
if (!user.isEmailConfirmed) {
|
|
|
|
|
setEmailVerifyMessage(dispatch);
|
|
|
|
|
}
|
2020-12-07 14:34:14 +05:00
|
|
|
dispatch({type: Actions.USER, user: user});
|
2020-12-20 23:01:35 +05:00
|
|
|
await Sync.run();
|
2020-11-23 11:30:55 +05:00
|
|
|
await startSyncer();
|
|
|
|
|
} else {
|
|
|
|
|
setLoginMessage(dispatch);
|
|
|
|
|
}
|
2020-12-20 23:01:35 +05:00
|
|
|
} catch (e) {}
|
2020-11-15 12:16:22 +05:00
|
|
|
};
|
|
|
|
|
|
2020-11-23 11:30:55 +05:00
|
|
|
const runAfterInit = () => {
|
2020-12-07 16:04:22 +05:00
|
|
|
let isIntent = false;
|
2020-11-24 16:59:12 +05:00
|
|
|
IntentService.getIntent()
|
|
|
|
|
.then(() => {
|
2020-12-22 12:38:31 +05:00
|
|
|
IntentService.check((event) => {
|
|
|
|
|
SplashScreen.hide();
|
|
|
|
|
loadIntent(event);
|
2021-01-05 11:05:52 +05:00
|
|
|
setIntentOnAppLoadProcessed(true);
|
2020-12-22 12:38:31 +05:00
|
|
|
dispatch({type: Actions.ALL});
|
|
|
|
|
isIntent = true;
|
|
|
|
|
dispatch({type: Actions.INTENT_MODE, state: true});
|
|
|
|
|
ReceiveSharingIntent.clearFileNames();
|
|
|
|
|
});
|
2020-11-24 16:59:12 +05:00
|
|
|
})
|
2020-12-07 16:04:22 +05:00
|
|
|
.catch((e) => console.log)
|
|
|
|
|
.finally(() => {
|
|
|
|
|
if (!isIntent) {
|
2020-12-22 12:38:31 +05:00
|
|
|
dispatch({type: Actions.INTENT_MODE, state: false});
|
2020-12-07 16:04:22 +05:00
|
|
|
ReceiveSharingIntent.clearFileNames();
|
2021-01-05 11:05:52 +05:00
|
|
|
setIntentOnAppLoadProcessed(true);
|
2020-12-07 16:04:22 +05:00
|
|
|
loadMainApp();
|
|
|
|
|
}
|
2020-11-24 16:59:12 +05:00
|
|
|
});
|
2020-11-23 11:30:55 +05:00
|
|
|
};
|
|
|
|
|
|
2020-12-09 22:16:22 +05:00
|
|
|
const onSuccessfulSubscription = (subscription) => {
|
|
|
|
|
if (hasPurchased) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const receipt = subscription.transactionReceipt;
|
|
|
|
|
processReceipt(receipt);
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
eSendEvent(eClosePremiumDialog);
|
|
|
|
|
eSendEvent(eOpenPendingDialog);
|
|
|
|
|
}, 500);
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-20 23:01:35 +05:00
|
|
|
const onSubscriptionError = (error) => {};
|
2020-12-09 22:16:22 +05:00
|
|
|
|
2020-12-10 13:06:59 +05:00
|
|
|
const processReceipt = (receipt) => {
|
2020-12-10 15:26:02 +05:00
|
|
|
return;
|
2020-12-10 13:06:59 +05:00
|
|
|
if (receipt) {
|
|
|
|
|
if (Platform.OS === 'ios') {
|
|
|
|
|
fetch('http://192.168.10.5:8100/webhooks/assn', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
2020-12-10 15:26:02 +05:00
|
|
|
receipt_data: receipt,
|
2020-12-10 13:06:59 +05:00
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
},
|
2020-12-09 22:16:22 +05:00
|
|
|
})
|
2020-12-10 13:06:59 +05:00
|
|
|
.then((r) => {
|
|
|
|
|
console.log(r.status, 'STATUS');
|
|
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
|
|
|
|
console.log(e, 'ERROR');
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-12-09 22:16:22 +05:00
|
|
|
}
|
2020-12-10 13:06:59 +05:00
|
|
|
};
|
2020-12-09 22:16:22 +05:00
|
|
|
|
2020-10-24 13:47:31 +05:00
|
|
|
return (
|
2020-11-23 11:30:55 +05:00
|
|
|
<SafeAreaProvider>
|
2020-12-22 12:38:31 +05:00
|
|
|
<RootView />
|
2020-11-23 11:30:55 +05:00
|
|
|
</SafeAreaProvider>
|
2020-10-24 13:47:31 +05:00
|
|
|
);
|
2019-11-15 01:17:59 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default App;
|