Move App component's actions to doDaemonReady action
This commit is contained in:
parent
e0aa6e3646
commit
96ab1bf2e2
3 changed files with 21 additions and 30 deletions
|
@ -13,13 +13,15 @@ import { doBalanceSubscribe } from "actions/wallet";
|
||||||
import { doAuthenticate } from "actions/user";
|
import { doAuthenticate } from "actions/user";
|
||||||
import { doFetchFileInfosAndPublishedClaims } from "actions/file_info";
|
import { doFetchFileInfosAndPublishedClaims } from "actions/file_info";
|
||||||
import * as modals from "constants/modal_types";
|
import * as modals from "constants/modal_types";
|
||||||
import { selectBalance } from "../selectors/wallet";
|
import { doFetchRewardedContent } from "actions/content";
|
||||||
|
import { selectCurrentModal } from "../selectors/app";
|
||||||
|
|
||||||
const { remote, ipcRenderer, shell } = require("electron");
|
const { remote, ipcRenderer, shell } = require("electron");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const { download } = remote.require("electron-dl");
|
const { download } = remote.require("electron-dl");
|
||||||
const fs = remote.require("fs");
|
const fs = remote.require("fs");
|
||||||
const { lbrySettings: config } = require("../../../app/package.json");
|
const { lbrySettings: config } = require("../../../app/package.json");
|
||||||
|
const CHECK_UPGRADE_INTERVAL = 10 * 60 * 1000;
|
||||||
|
|
||||||
export function doOpenModal(modal, modalProps = {}) {
|
export function doOpenModal(modal, modalProps = {}) {
|
||||||
return {
|
return {
|
||||||
|
@ -131,21 +133,21 @@ export function doCheckUpgradeAvailable() {
|
||||||
return function(dispatch, getState) {
|
return function(dispatch, getState) {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
dispatch({
|
dispatch({
|
||||||
type: types.CHECK_UPGRADE_STARTED,
|
type: types.CHECK_UPGRADE_START,
|
||||||
});
|
});
|
||||||
|
|
||||||
const success = ({ remoteVersion, upgradeAvailable }) => {
|
const success = ({ remoteVersion, upgradeAvailable }) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: types.CHECK_UPGRADE_COMPLETED,
|
type: types.CHECK_UPGRADE_SUCCESS,
|
||||||
data: {
|
data: {
|
||||||
upgradeAvailable,
|
upgradeAvailable,
|
||||||
remoteVersion,
|
remoteVersion,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// If there's an available upgrade and the user hasn't skipped it or if there's a newer one, show un upgrade modal
|
|
||||||
if (
|
if (
|
||||||
upgradeAvailable &&
|
upgradeAvailable &&
|
||||||
|
!selectCurrentModal(state) &&
|
||||||
(!selectIsUpgradeSkipped(state) ||
|
(!selectIsUpgradeSkipped(state) ||
|
||||||
remoteVersion !== selectRemoteVersion(state))
|
remoteVersion !== selectRemoteVersion(state))
|
||||||
) {
|
) {
|
||||||
|
@ -158,27 +160,27 @@ export function doCheckUpgradeAvailable() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const failure = () => {
|
const fail = () => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: types.CHECK_UPGRADE_FAILED,
|
type: types.CHECK_UPGRADE_FAIL,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
lbry.getAppVersionInfo().then(success, failure);
|
lbry.getAppVersionInfo().then(success, fail);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Initiate a timer that will check for an app upgrade every 10 minutes.
|
Initiate a timer that will check for an app upgrade every 10 minutes.
|
||||||
*/
|
*/
|
||||||
export function doInitCheckUpgradeTimer() {
|
export function doCheckUpgradeSubscribe() {
|
||||||
return function(dispatch) {
|
return function(dispatch) {
|
||||||
const checkUpgradeTimer = setInterval(
|
const checkUpgradeTimer = setInterval(
|
||||||
() => dispatch(doCheckUpgradeAvailable()),
|
() => dispatch(doCheckUpgradeAvailable()),
|
||||||
600000
|
CHECK_UPGRADE_INTERVAL
|
||||||
);
|
);
|
||||||
dispatch({
|
dispatch({
|
||||||
type: types.CHECK_UPGRADE_TIMER_INITIATED,
|
type: types.CHECK_UPGRADE_SUBSCRIBE,
|
||||||
data: { checkUpgradeTimer },
|
data: { checkUpgradeTimer },
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -212,11 +214,18 @@ export function doAlertError(errorList) {
|
||||||
|
|
||||||
export function doDaemonReady() {
|
export function doDaemonReady() {
|
||||||
return function(dispatch, getState) {
|
return function(dispatch, getState) {
|
||||||
|
const state = getState();
|
||||||
|
|
||||||
dispatch(doAuthenticate());
|
dispatch(doAuthenticate());
|
||||||
dispatch({ type: types.DAEMON_READY });
|
dispatch({ type: types.DAEMON_READY });
|
||||||
dispatch(doFetchDaemonSettings());
|
dispatch(doFetchDaemonSettings());
|
||||||
dispatch(doBalanceSubscribe());
|
dispatch(doBalanceSubscribe());
|
||||||
dispatch(doFetchFileInfosAndPublishedClaims());
|
dispatch(doFetchFileInfosAndPublishedClaims());
|
||||||
|
dispatch(doFetchRewardedContent());
|
||||||
|
if (!selectIsUpgradeSkipped(state)) {
|
||||||
|
dispatch(doCheckUpgradeAvailable());
|
||||||
|
}
|
||||||
|
dispatch(doCheckUpgradeSubscribe());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,9 @@ import React from "react";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { selectPageTitle } from "selectors/navigation";
|
import { selectPageTitle } from "selectors/navigation";
|
||||||
import { selectUser } from "selectors/user";
|
import { selectUser } from "selectors/user";
|
||||||
import { doCheckUpgradeAvailable, doAlertError } from "actions/app";
|
import { doAlertError } from "actions/app";
|
||||||
import { doRecordScroll } from "actions/navigation";
|
import { doRecordScroll } from "actions/navigation";
|
||||||
import { doFetchRewardedContent } from "actions/content";
|
|
||||||
import App from "./view";
|
import App from "./view";
|
||||||
import { doInitCheckUpgradeTimer } from "../../actions/app";
|
|
||||||
|
|
||||||
const select = (state, props) => ({
|
const select = (state, props) => ({
|
||||||
pageTitle: selectPageTitle(state),
|
pageTitle: selectPageTitle(state),
|
||||||
|
@ -15,9 +13,6 @@ const select = (state, props) => ({
|
||||||
|
|
||||||
const perform = dispatch => ({
|
const perform = dispatch => ({
|
||||||
alertError: errorList => dispatch(doAlertError(errorList)),
|
alertError: errorList => dispatch(doAlertError(errorList)),
|
||||||
checkUpgradeAvailable: () => dispatch(doCheckUpgradeAvailable()),
|
|
||||||
initCheckUpgradeTimer: () => dispatch(doInitCheckUpgradeTimer()),
|
|
||||||
fetchRewardedContent: () => dispatch(doFetchRewardedContent()),
|
|
||||||
recordScroll: scrollPosition => dispatch(doRecordScroll(scrollPosition)),
|
recordScroll: scrollPosition => dispatch(doRecordScroll(scrollPosition)),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -7,25 +7,12 @@ import lbry from "lbry";
|
||||||
|
|
||||||
class App extends React.PureComponent {
|
class App extends React.PureComponent {
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
const {
|
const { alertError } = this.props;
|
||||||
alertError,
|
|
||||||
checkUpgradeAvailable,
|
|
||||||
initCheckUpgradeTimer,
|
|
||||||
fetchRewardedContent,
|
|
||||||
} = this.props;
|
|
||||||
|
|
||||||
document.addEventListener("unhandledError", event => {
|
document.addEventListener("unhandledError", event => {
|
||||||
alertError(event.detail);
|
alertError(event.detail);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!this.props.upgradeSkipped) {
|
|
||||||
checkUpgradeAvailable();
|
|
||||||
}
|
|
||||||
|
|
||||||
initCheckUpgradeTimer();
|
|
||||||
|
|
||||||
fetchRewardedContent();
|
|
||||||
|
|
||||||
this.scrollListener = () => this.props.recordScroll(window.scrollY);
|
this.scrollListener = () => this.props.recordScroll(window.scrollY);
|
||||||
|
|
||||||
window.addEventListener("scroll", this.scrollListener);
|
window.addEventListener("scroll", this.scrollListener);
|
||||||
|
|
Loading…
Reference in a new issue