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

View file

@ -74,10 +74,9 @@ type Props = {
syncEnabled: boolean,
rewards: Array<Reward>,
setReferrer: (string, boolean) => void,
analyticsTagSync: () => void,
isAuthenticated: boolean,
socketConnect: () => void,
syncSubscribe: () => void,
syncLoop: (?boolean) => void,
syncEnabled: boolean,
currentModal: any,
syncFatalError: boolean,
@ -104,7 +103,7 @@ function App(props: Props) {
rewards,
setReferrer,
isAuthenticated,
syncSubscribe,
syncLoop,
currentModal,
syncFatalError,
} = props;
@ -147,6 +146,7 @@ function App(props: Props) {
function handleAnalyticsDismiss() {
setShowAnalyticsNag(false);
}
// @endif
useEffect(() => {
if (userId) {
@ -270,11 +270,20 @@ function App(props: Props) {
// ready for sync syncs, however after signin when hasVerifiedEmail, that syncs too.
useEffect(() => {
// signInSyncPref is cleared after sharedState loop.
const syncLoopWithoutInterval = () => syncLoop(true);
if (readyForSync && hasVerifiedEmail) {
// 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'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 { selectUser, selectUserVerifiedEmail } from 'redux/selectors/user';
// 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 { lbrySettings as config, version as appVersion } from 'package.json';
import analytics, { SHARE_INTERNAL } from 'analytics';
@ -679,7 +679,7 @@ export function doHandleSyncComplete(error, hasNewData) {
}
export function doSyncWithPreferences() {
return dispatch => dispatch(doSyncSubscribe());
return dispatch => dispatch(doSyncLoop());
}
export function doToggleInterestedInYoutubeSync() {

View file

@ -5,7 +5,7 @@ import analytics from 'analytics';
import SUPPORTED_LANGUAGES from 'constants/supported_languages';
import { launcher } from 'util/autoLaunch';
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 { selectPrefsReady } from 'redux/selectors/sync';
import { Lbryio } from 'lbryinc';
@ -246,7 +246,7 @@ export function doEnterSettingsPage() {
}
dispatch(doSyncUnsubscribe());
if (syncEnabled && hasVerifiedEmail) {
await dispatch(doGetSyncDesktop());
await dispatch(doSyncLoop(true));
} else {
await dispatch(doGetAndPopulatePreferences());
}
@ -263,7 +263,7 @@ export function doExitSettingsPage() {
}
dispatch(doSetSyncLock(false));
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) => {
if (syncTimer) clearInterval(syncTimer);
if (!noInterval && syncTimer) clearInterval(syncTimer);
const state = getState();
const hasVerifiedEmail = selectUserVerifiedEmail(state);
const syncEnabled = makeSelectClientSetting(SETTINGS.ENABLE_SYNC)(state);
@ -113,14 +113,16 @@ export function doSyncSubscribe() {
if (hasVerifiedEmail && syncEnabled && !syncLocked) {
dispatch(doGetSyncDesktop((error, hasNewData) => dispatch(doHandleSyncComplete(error, hasNewData))));
dispatch(doAnalyticsTagSync());
syncTimer = setInterval(() => {
const state = getState();
const syncEnabled = makeSelectClientSetting(SETTINGS.ENABLE_SYNC)(state);
if (syncEnabled) {
dispatch(doGetSyncDesktop((error, hasNewData) => dispatch(doHandleSyncComplete(error, hasNewData))));
dispatch(doAnalyticsTagSync());
}
}, SYNC_INTERVAL);
if (!noInterval) {
syncTimer = setInterval(() => {
const state = getState();
const syncEnabled = makeSelectClientSetting(SETTINGS.ENABLE_SYNC)(state);
if (syncEnabled) {
dispatch(doGetSyncDesktop((error, hasNewData) => dispatch(doHandleSyncComplete(error, hasNewData))));
dispatch(doAnalyticsTagSync());
}
}, SYNC_INTERVAL);
}
}
};
}

View file

@ -10,7 +10,7 @@ import { createMemoryHistory, createBrowserHistory } from 'history';
import { routerMiddleware } from 'connected-react-router';
import createRootReducer from './reducers';
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 { generateInitialUrl } from 'util/url';
import { X_LBRY_AUTH_TOKEN } from 'constants/token';
@ -159,7 +159,7 @@ const sharedStateFilters = {
};
const sharedStateCb = ({ dispatch, getState }) => {
dispatch(doSyncSubscribe());
dispatch(doSyncLoop());
};
const populateAuthTokenHeader = () => {