sync again

This commit is contained in:
zeppi 2021-01-21 14:50:51 -05:00 committed by Sean Yesmunt
parent 855d13e735
commit 2adfa8b6b6
6 changed files with 36 additions and 31 deletions

View file

@ -14,13 +14,8 @@ import {
} from 'redux/selectors/settings'; } from 'redux/selectors/settings';
import { selectIsUpgradeAvailable, selectAutoUpdateDownloaded, selectModal } from 'redux/selectors/app'; import { selectIsUpgradeAvailable, selectAutoUpdateDownloaded, selectModal } from 'redux/selectors/app';
import { doGetWalletSyncPreference, doSetLanguage } from 'redux/actions/settings'; import { doGetWalletSyncPreference, doSetLanguage } from 'redux/actions/settings';
import { doSyncSubscribe } from 'redux/actions/sync'; import { doSyncLoop } from 'redux/actions/sync';
import { import { doDownloadUpgradeRequested, doSignIn, doGetAndPopulatePreferences } from 'redux/actions/app';
doDownloadUpgradeRequested,
doSignIn,
doGetAndPopulatePreferences,
doAnalyticsTagSync,
} from 'redux/actions/app';
import App from './view'; import App from './view';
const select = state => ({ const select = state => ({
@ -41,7 +36,6 @@ const select = state => ({
}); });
const perform = dispatch => ({ const perform = dispatch => ({
analyticsTagSync: () => dispatch(doAnalyticsTagSync()),
fetchAccessToken: () => dispatch(doFetchAccessToken()), fetchAccessToken: () => dispatch(doFetchAccessToken()),
fetchChannelListMine: () => dispatch(doFetchChannelListMine()), fetchChannelListMine: () => dispatch(doFetchChannelListMine()),
setLanguage: language => dispatch(doSetLanguage(language)), setLanguage: language => dispatch(doSetLanguage(language)),
@ -49,7 +43,7 @@ const perform = dispatch => ({
requestDownloadUpgrade: () => dispatch(doDownloadUpgradeRequested()), requestDownloadUpgrade: () => dispatch(doDownloadUpgradeRequested()),
updatePreferences: () => dispatch(doGetAndPopulatePreferences()), updatePreferences: () => dispatch(doGetAndPopulatePreferences()),
getWalletSyncPref: () => dispatch(doGetWalletSyncPreference()), getWalletSyncPref: () => dispatch(doGetWalletSyncPreference()),
syncSubscribe: () => dispatch(doSyncSubscribe()), syncLoop: noInterval => dispatch(doSyncLoop(noInterval)),
setReferrer: (referrer, doClaim) => dispatch(doUserSetReferrer(referrer, doClaim)), setReferrer: (referrer, doClaim) => dispatch(doUserSetReferrer(referrer, doClaim)),
}); });

View file

@ -74,10 +74,9 @@ type Props = {
syncEnabled: boolean, syncEnabled: boolean,
rewards: Array<Reward>, rewards: Array<Reward>,
setReferrer: (string, boolean) => void, setReferrer: (string, boolean) => void,
analyticsTagSync: () => void,
isAuthenticated: boolean, isAuthenticated: boolean,
socketConnect: () => void, socketConnect: () => void,
syncSubscribe: () => void, syncLoop: (?boolean) => void,
syncEnabled: boolean, syncEnabled: boolean,
currentModal: any, currentModal: any,
syncFatalError: boolean, syncFatalError: boolean,
@ -104,7 +103,7 @@ function App(props: Props) {
rewards, rewards,
setReferrer, setReferrer,
isAuthenticated, isAuthenticated,
syncSubscribe, syncLoop,
currentModal, currentModal,
syncFatalError, syncFatalError,
} = props; } = props;
@ -147,6 +146,7 @@ function App(props: Props) {
function handleAnalyticsDismiss() { function handleAnalyticsDismiss() {
setShowAnalyticsNag(false); setShowAnalyticsNag(false);
} }
// @endif // @endif
useEffect(() => { useEffect(() => {
if (userId) { if (userId) {
@ -270,11 +270,20 @@ function App(props: Props) {
// ready for sync syncs, however after signin when hasVerifiedEmail, that syncs too. // ready for sync syncs, however after signin when hasVerifiedEmail, that syncs too.
useEffect(() => { useEffect(() => {
// signInSyncPref is cleared after sharedState loop. // signInSyncPref is cleared after sharedState loop.
const syncLoopWithoutInterval = () => syncLoop(true);
if (readyForSync && hasVerifiedEmail) { if (readyForSync && hasVerifiedEmail) {
// In case we are syncing. // In case we are syncing.
syncSubscribe(); syncLoop();
// @if TARGET='web'
window.addEventListener('focus', syncLoopWithoutInterval);
// @endif
} }
}, [readyForSync, hasVerifiedEmail, syncSubscribe]); // @if TARGET='web'
return () => {
window.removeEventListener('focus', syncLoopWithoutInterval);
};
// @endif
}, [readyForSync, hasVerifiedEmail, syncLoop]);
// We know someone is logging in or not when we get their user object // We know someone is logging in or not when we get their user object
// We'll use this to determine when it's time to pull preferences // We'll use this to determine when it's time to pull preferences

View file

@ -49,7 +49,7 @@ import {
import { selectDaemonSettings, makeSelectClientSetting } from 'redux/selectors/settings'; import { selectDaemonSettings, makeSelectClientSetting } from 'redux/selectors/settings';
import { selectUser, selectUserVerifiedEmail } from 'redux/selectors/user'; import { selectUser, selectUserVerifiedEmail } from 'redux/selectors/user';
// import { selectDaemonSettings } from 'redux/selectors/settings'; // import { selectDaemonSettings } from 'redux/selectors/settings';
import { doSyncSubscribe, doSetPrefsReady } from 'redux/actions/sync'; import { doSyncLoop, doSetPrefsReady } from 'redux/actions/sync';
import { doAuthenticate } from 'redux/actions/user'; import { doAuthenticate } from 'redux/actions/user';
import { lbrySettings as config, version as appVersion } from 'package.json'; import { lbrySettings as config, version as appVersion } from 'package.json';
import analytics, { SHARE_INTERNAL } from 'analytics'; import analytics, { SHARE_INTERNAL } from 'analytics';
@ -679,7 +679,7 @@ export function doHandleSyncComplete(error, hasNewData) {
} }
export function doSyncWithPreferences() { export function doSyncWithPreferences() {
return dispatch => dispatch(doSyncSubscribe()); return dispatch => dispatch(doSyncLoop());
} }
export function doToggleInterestedInYoutubeSync() { export function doToggleInterestedInYoutubeSync() {

View file

@ -5,7 +5,7 @@ import analytics from 'analytics';
import SUPPORTED_LANGUAGES from 'constants/supported_languages'; import SUPPORTED_LANGUAGES from 'constants/supported_languages';
import { launcher } from 'util/autoLaunch'; import { launcher } from 'util/autoLaunch';
import { makeSelectClientSetting } from 'redux/selectors/settings'; import { makeSelectClientSetting } from 'redux/selectors/settings';
import { doGetSyncDesktop, doSyncUnsubscribe, doSetSyncLock } from 'redux/actions/sync'; import { doSyncLoop, doSyncUnsubscribe, doSetSyncLock } from 'redux/actions/sync';
import { doAlertWaitingForSync, doGetAndPopulatePreferences } from 'redux/actions/app'; import { doAlertWaitingForSync, doGetAndPopulatePreferences } from 'redux/actions/app';
import { selectPrefsReady } from 'redux/selectors/sync'; import { selectPrefsReady } from 'redux/selectors/sync';
import { Lbryio } from 'lbryinc'; import { Lbryio } from 'lbryinc';
@ -246,7 +246,7 @@ export function doEnterSettingsPage() {
} }
dispatch(doSyncUnsubscribe()); dispatch(doSyncUnsubscribe());
if (syncEnabled && hasVerifiedEmail) { if (syncEnabled && hasVerifiedEmail) {
await dispatch(doGetSyncDesktop()); await dispatch(doSyncLoop(true));
} else { } else {
await dispatch(doGetAndPopulatePreferences()); await dispatch(doGetAndPopulatePreferences());
} }
@ -263,7 +263,7 @@ export function doExitSettingsPage() {
} }
dispatch(doSetSyncLock(false)); dispatch(doSetSyncLock(false));
dispatch(doPushSettingsToPrefs()); dispatch(doPushSettingsToPrefs());
// syncSubscribe is restarted in store.js sharedStateCB if necessary // syncLoop is restarted in store.js sharedStateCB if necessary
}; };
} }

View file

@ -103,9 +103,9 @@ export const doGetSyncDesktop = (cb?, password) => (dispatch, getState) => {
}); });
}; };
export function doSyncSubscribe() { export function doSyncLoop(noInterval) {
return (dispatch, getState) => { return (dispatch, getState) => {
if (syncTimer) clearInterval(syncTimer); if (!noInterval && syncTimer) clearInterval(syncTimer);
const state = getState(); const state = getState();
const hasVerifiedEmail = selectUserVerifiedEmail(state); const hasVerifiedEmail = selectUserVerifiedEmail(state);
const syncEnabled = makeSelectClientSetting(SETTINGS.ENABLE_SYNC)(state); const syncEnabled = makeSelectClientSetting(SETTINGS.ENABLE_SYNC)(state);
@ -113,14 +113,16 @@ export function doSyncSubscribe() {
if (hasVerifiedEmail && syncEnabled && !syncLocked) { if (hasVerifiedEmail && syncEnabled && !syncLocked) {
dispatch(doGetSyncDesktop((error, hasNewData) => dispatch(doHandleSyncComplete(error, hasNewData)))); dispatch(doGetSyncDesktop((error, hasNewData) => dispatch(doHandleSyncComplete(error, hasNewData))));
dispatch(doAnalyticsTagSync()); dispatch(doAnalyticsTagSync());
syncTimer = setInterval(() => { if (!noInterval) {
const state = getState(); syncTimer = setInterval(() => {
const syncEnabled = makeSelectClientSetting(SETTINGS.ENABLE_SYNC)(state); const state = getState();
if (syncEnabled) { const syncEnabled = makeSelectClientSetting(SETTINGS.ENABLE_SYNC)(state);
dispatch(doGetSyncDesktop((error, hasNewData) => dispatch(doHandleSyncComplete(error, hasNewData)))); if (syncEnabled) {
dispatch(doAnalyticsTagSync()); dispatch(doGetSyncDesktop((error, hasNewData) => dispatch(doHandleSyncComplete(error, hasNewData))));
} dispatch(doAnalyticsTagSync());
}, SYNC_INTERVAL); }
}, SYNC_INTERVAL);
}
} }
}; };
} }

View file

@ -10,7 +10,7 @@ import { createMemoryHistory, createBrowserHistory } from 'history';
import { routerMiddleware } from 'connected-react-router'; import { routerMiddleware } from 'connected-react-router';
import createRootReducer from './reducers'; import createRootReducer from './reducers';
import { Lbry, buildSharedStateMiddleware, ACTIONS as LBRY_REDUX_ACTIONS } from 'lbry-redux'; import { Lbry, buildSharedStateMiddleware, ACTIONS as LBRY_REDUX_ACTIONS } from 'lbry-redux';
import { doSyncSubscribe } from 'redux/actions/sync'; import { doSyncLoop } from 'redux/actions/sync';
import { getAuthToken } from 'util/saved-passwords'; import { getAuthToken } from 'util/saved-passwords';
import { generateInitialUrl } from 'util/url'; import { generateInitialUrl } from 'util/url';
import { X_LBRY_AUTH_TOKEN } from 'constants/token'; import { X_LBRY_AUTH_TOKEN } from 'constants/token';
@ -159,7 +159,7 @@ const sharedStateFilters = {
}; };
const sharedStateCb = ({ dispatch, getState }) => { const sharedStateCb = ({ dispatch, getState }) => {
dispatch(doSyncSubscribe()); dispatch(doSyncLoop());
}; };
const populateAuthTokenHeader = () => { const populateAuthTokenHeader = () => {