From feb19bdea9d1ce2893c4633949dddbff77f2f83d Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Thu, 9 Nov 2017 21:07:02 -0300 Subject: [PATCH 1/7] Add App upgrade button to the header --- ui/js/component/header/index.js | 4 ++++ ui/js/component/header/view.jsx | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/ui/js/component/header/index.js b/ui/js/component/header/index.js index 08d5bb9cb..5c2cf9dac 100644 --- a/ui/js/component/header/index.js +++ b/ui/js/component/header/index.js @@ -11,6 +11,7 @@ import { doHistoryBack, doHistoryForward, } from "actions/navigation"; +import { doDownloadUpgrade } from "actions/app"; import Header from "./view"; const select = state => ({ @@ -18,12 +19,15 @@ const select = state => ({ isForwardDisabled: selectIsForwardDisabled(state), balance: formatCredits(selectBalance(state) || 0, 1), publish: __("Publish"), + upgrade: __("Upgrade"), + upgradeSkipped: true, }); const perform = dispatch => ({ navigate: path => dispatch(doNavigate(path)), back: () => dispatch(doHistoryBack()), forward: () => dispatch(doHistoryForward()), + downloadUpgrade: () => dispatch(doDownloadUpgrade()), }); export default connect(select, perform)(Header); diff --git a/ui/js/component/header/view.jsx b/ui/js/component/header/view.jsx index 89f6df923..c5308029e 100644 --- a/ui/js/component/header/view.jsx +++ b/ui/js/component/header/view.jsx @@ -6,11 +6,14 @@ export const Header = props => { const { balance, back, + downloadUpgrade, forward, isBackDisabled, isForwardDisabled, navigate, publish, + upgradeLabel, + upgradeSkipped, } = props; return ( ); }; From 9e0f8adb585f51f974b590aa63db2beedc51b372 Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Fri, 10 Nov 2017 11:55:34 -0300 Subject: [PATCH 2/7] Add prominent upgrade button when upgrade is pending --- ui/js/component/header/index.js | 5 +++-- ui/js/component/header/view.jsx | 23 ++++++++++++----------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/ui/js/component/header/index.js b/ui/js/component/header/index.js index 5c2cf9dac..280db1415 100644 --- a/ui/js/component/header/index.js +++ b/ui/js/component/header/index.js @@ -1,6 +1,7 @@ import React from "react"; import { formatCredits } from "util/formatCredits"; import { connect } from "react-redux"; +import { selectUpgradeSkipped } from "selectors/app"; import { selectIsBackDisabled, selectIsForwardDisabled, @@ -19,8 +20,8 @@ const select = state => ({ isForwardDisabled: selectIsForwardDisabled(state), balance: formatCredits(selectBalance(state) || 0, 1), publish: __("Publish"), - upgrade: __("Upgrade"), - upgradeSkipped: true, + upgradeLabel: __("Upgrade App"), + upgradeSkipped: selectUpgradeSkipped(state), }); const perform = dispatch => ({ diff --git a/ui/js/component/header/view.jsx b/ui/js/component/header/view.jsx index c5308029e..ffb4ff729 100644 --- a/ui/js/component/header/view.jsx +++ b/ui/js/component/header/view.jsx @@ -80,17 +80,18 @@ export const Header = props => { title={__("Settings")} /> - HEY I'M HER E - {upgradeSkipped - ?
- downloadUpgrade()} - button="primary button--flat" - icon="icon-upload" - label={upgradeLabel} - /> -
- : ""} + {upgradeSkipped ? ( +
+ downloadUpgrade()} + button="primary button--flat" + icon="icon-arrow-up" + label={upgradeLabel} + /> +
+ ) : ( + "" + )} ); }; From 03c9a14c71c564604bc66687c4e4176009f8fd7f Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Tue, 14 Nov 2017 22:50:21 -0300 Subject: [PATCH 3/7] Add timer for checking for app upgrades --- ui/js/actions/app.js | 90 +++++++++++++++++++++++---------- ui/js/component/app/index.js | 8 ++- ui/js/component/app/view.jsx | 5 ++ ui/js/constants/action_types.js | 5 ++ ui/js/reducers/app.js | 15 +++++- ui/js/selectors/app.js | 18 ++++--- 6 files changed, 106 insertions(+), 35 deletions(-) diff --git a/ui/js/actions/app.js b/ui/js/actions/app.js index 0ccc6a977..8679000ca 100644 --- a/ui/js/actions/app.js +++ b/ui/js/actions/app.js @@ -5,12 +5,15 @@ import { selectUpgradeDownloadPath, selectUpgradeDownloadItem, selectUpgradeFilename, + selectIsUpgradeSkipped, + selectRemoteVersion, } from "selectors/app"; import { doFetchDaemonSettings } from "actions/settings"; import { doBalanceSubscribe } from "actions/wallet"; import { doAuthenticate } from "actions/user"; import { doFetchFileInfosAndPublishedClaims } from "actions/file_info"; import * as modals from "constants/modal_types"; +import { selectBalance } from "../selectors/wallet"; const { remote, ipcRenderer, shell } = require("electron"); const path = require("path"); @@ -63,33 +66,31 @@ export function doDownloadUpgrade() { const state = getState(); // Make a new directory within temp directory so the filename is guaranteed to be available const dir = fs.mkdtempSync( - remote.app.getPath("temp") + require("path").sep - ), + remote.app.getPath("temp") + require("path").sep + ), upgradeFilename = selectUpgradeFilename(state); let options = { onProgress: p => dispatch(doUpdateDownloadProgress(Math.round(p * 100))), directory: dir, }; - download( - remote.getCurrentWindow(), - selectUpdateUrl(state), - options - ).then(downloadItem => { - /** + download(remote.getCurrentWindow(), selectUpdateUrl(state), options).then( + downloadItem => { + /** * TODO: get the download path directly from the download object. It should just be * downloadItem.getSavePath(), but the copy on the main process is being garbage collected * too soon. */ - dispatch({ - type: types.UPGRADE_DOWNLOAD_COMPLETED, - data: { - downloadItem, - path: path.join(dir, upgradeFilename), - }, - }); - }); + dispatch({ + type: types.UPGRADE_DOWNLOAD_COMPLETED, + data: { + downloadItem, + path: path.join(dir, upgradeFilename), + }, + }); + } + ); dispatch({ type: types.UPGRADE_DOWNLOAD_STARTED, @@ -129,15 +130,25 @@ export function doCancelUpgrade() { export function doCheckUpgradeAvailable() { return function(dispatch, getState) { const state = getState(); + dispatch({ + type: types.CHECK_UPGRADE_STARTED, + }); - lbry.getAppVersionInfo().then(({ remoteVersion, upgradeAvailable }) => { - if (upgradeAvailable) { - dispatch({ - type: types.UPDATE_VERSION, - data: { - version: remoteVersion, - }, - }); + const success = ({ remoteVersion, upgradeAvailable }) => { + dispatch({ + type: types.CHECK_UPGRADE_COMPLETED, + data: { + upgradeAvailable, + 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 ( + upgradeAvailable && + (!selectIsUpgradeSkipped(state) || + remoteVersion !== selectRemoteVersion(state)) + ) { dispatch({ type: types.OPEN_MODAL, data: { @@ -145,6 +156,30 @@ export function doCheckUpgradeAvailable() { }, }); } + }; + + const failure = () => { + dispatch({ + type: types.CHECK_UPGRADE_FAILED, + }); + }; + + lbry.getAppVersionInfo().then(success, failure); + }; +} + +/* + Initiate a timer that will check for an app upgrade every 10 minutes. + */ +export function doInitCheckUpgradeTimer() { + return function(dispatch) { + const checkUpgradeTimer = setInterval( + () => dispatch(doCheckUpgradeAvailable()), + 600000 + ); + dispatch({ + type: types.CHECK_UPGRADE_TIMER_INITIATED, + data: { checkUpgradeTimer }, }); }; } @@ -153,9 +188,10 @@ export function doCheckDaemonVersion() { return function(dispatch, getState) { lbry.version().then(({ lbrynet_version }) => { dispatch({ - type: config.lbrynetDaemonVersion == lbrynet_version - ? types.DAEMON_VERSION_MATCH - : types.DAEMON_VERSION_MISMATCH, + type: + config.lbrynetDaemonVersion == lbrynet_version + ? types.DAEMON_VERSION_MATCH + : types.DAEMON_VERSION_MISMATCH, }); }); }; diff --git a/ui/js/component/app/index.js b/ui/js/component/app/index.js index 06ff45f18..f4d8c451b 100644 --- a/ui/js/component/app/index.js +++ b/ui/js/component/app/index.js @@ -2,10 +2,15 @@ import React from "react"; import { connect } from "react-redux"; import { selectPageTitle } from "selectors/navigation"; import { selectUser } from "selectors/user"; -import { doCheckUpgradeAvailable, doAlertError } from "actions/app"; +import { + doCheckUpgradeAvailable, + doStartUpgradeCheckTimer, + doAlertError, +} from "actions/app"; import { doRecordScroll } from "actions/navigation"; import { doFetchRewardedContent } from "actions/content"; import App from "./view"; +import { doInitCheckUpgradeTimer } from "../../actions/app"; const select = (state, props) => ({ pageTitle: selectPageTitle(state), @@ -15,6 +20,7 @@ const select = (state, props) => ({ const perform = dispatch => ({ alertError: errorList => dispatch(doAlertError(errorList)), checkUpgradeAvailable: () => dispatch(doCheckUpgradeAvailable()), + initCheckUpgradeTimer: () => dispatch(doInitCheckUpgradeTimer()), fetchRewardedContent: () => dispatch(doFetchRewardedContent()), recordScroll: scrollPosition => dispatch(doRecordScroll(scrollPosition)), }); diff --git a/ui/js/component/app/view.jsx b/ui/js/component/app/view.jsx index 17e0ec030..c23e5d0c8 100644 --- a/ui/js/component/app/view.jsx +++ b/ui/js/component/app/view.jsx @@ -10,6 +10,7 @@ class App extends React.PureComponent { const { alertError, checkUpgradeAvailable, + initCheckUpgradeTimer, fetchRewardedContent, } = this.props; @@ -21,6 +22,8 @@ class App extends React.PureComponent { checkUpgradeAvailable(); } + initCheckUpgradeTimer(); + fetchRewardedContent(); this.scrollListener = () => this.props.recordScroll(window.scrollY); @@ -30,6 +33,8 @@ class App extends React.PureComponent { this.setTitleFromProps(this.props); } + componentDidMount() {} + componentWillUnmount() { window.removeEventListener("scroll", this.scrollListener); } diff --git a/ui/js/constants/action_types.js b/ui/js/constants/action_types.js index 9a9143070..47c653524 100644 --- a/ui/js/constants/action_types.js +++ b/ui/js/constants/action_types.js @@ -20,7 +20,12 @@ export const UPGRADE_DOWNLOAD_STARTED = "UPGRADE_DOWNLOAD_STARTED"; export const UPGRADE_DOWNLOAD_COMPLETED = "UPGRADE_DOWNLOAD_COMPLETED"; export const UPGRADE_DOWNLOAD_PROGRESSED = "UPGRADE_DOWNLOAD_PROGRESSED"; export const CHECK_UPGRADE_AVAILABLE = "CHECK_UPGRADE_AVAILABLE"; +export const CHECK_UPGRADE_STARTED = "CHECK_UPGRADE_STARTED"; +export const CHECK_UPGRADE_COMPLETED = "CHECK_UPGRADE_COMPLETED"; +export const CHECK_UPGRADE_FAILED = "CHECK_UPGRADE_FAILED"; +export const CHECK_UPGRADE_TIMER_INITIATED = "CHECK_UPGRADE_TIMER_INITIATED"; export const UPDATE_VERSION = "UPDATE_VERSION"; +export const UPDATE_REMOTE_VERSION = "UPDATE_REMOTE_VERSION"; export const SKIP_UPGRADE = "SKIP_UPGRADE"; export const START_UPGRADE = "START_UPGRADE"; diff --git a/ui/js/reducers/app.js b/ui/js/reducers/app.js index d7bc2cd6b..6155ea4c0 100644 --- a/ui/js/reducers/app.js +++ b/ui/js/reducers/app.js @@ -64,7 +64,7 @@ reducers[types.SKIP_UPGRADE] = function(state, action) { sessionStorage.setItem("upgradeSkipped", true); return Object.assign({}, state, { - upgradeSkipped: true, + isUpgradeSkipped: true, modal: null, }); }; @@ -75,6 +75,19 @@ reducers[types.UPDATE_VERSION] = function(state, action) { }); }; +reducers[types.CHECK_UPGRADE_COMPLETED] = function(state, action) { + return Object.assign({}, state, { + isUpgradeAvailable: action.data.upgradeAvailable, + remoteVersion: action.data.remoteVersion, + }); +}; + +reducers[types.CHECK_UPGRADE_TIMER_INITIATED] = function(state, action) { + return Object.assign({}, state, { + checkUpgradeTimer: action.data.checkUpgradeTimer, + }); +}; + reducers[types.OPEN_MODAL] = function(state, action) { return Object.assign({}, state, { modal: action.data.modal, diff --git a/ui/js/selectors/app.js b/ui/js/selectors/app.js index c721916c0..24c2f2b95 100644 --- a/ui/js/selectors/app.js +++ b/ui/js/selectors/app.js @@ -20,13 +20,19 @@ export const selectUpdateUrl = createSelector(selectPlatform, platform => { } }); -export const selectVersion = createSelector(_selectState, state => { - return state.version; -}); +export const selectRemoteVersion = createSelector( + _selectState, + state => state.remoteVersion +); + +export const selectIsUpgradeAvailable = createSelector( + _selectState, + state => state.isUpgradeAvailable +); export const selectUpgradeFilename = createSelector( selectPlatform, - selectVersion, + selectRemoteVersion, (platform, version) => { switch (platform) { case "darwin": @@ -56,9 +62,9 @@ export const selectDownloadComplete = createSelector( state => state.upgradeDownloadCompleted ); -export const selectUpgradeSkipped = createSelector( +export const selectIsUpgradeSkipped = createSelector( _selectState, - state => state.upgradeSkipped + state => state.isUpgradeSkipped ); export const selectUpgradeDownloadPath = createSelector( From 09be36e367d3b0727c47b4703511fdc1d2b2ef19 Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Tue, 14 Nov 2017 22:51:06 -0300 Subject: [PATCH 4/7] Show Upgrade App button if an upgrade is available --- ui/js/component/header/index.js | 6 +++--- ui/js/component/header/view.jsx | 22 +++++++++------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/ui/js/component/header/index.js b/ui/js/component/header/index.js index 280db1415..fe81b277c 100644 --- a/ui/js/component/header/index.js +++ b/ui/js/component/header/index.js @@ -1,7 +1,6 @@ import React from "react"; import { formatCredits } from "util/formatCredits"; import { connect } from "react-redux"; -import { selectUpgradeSkipped } from "selectors/app"; import { selectIsBackDisabled, selectIsForwardDisabled, @@ -12,16 +11,17 @@ import { doHistoryBack, doHistoryForward, } from "actions/navigation"; -import { doDownloadUpgrade } from "actions/app"; import Header from "./view"; +import { selectIsUpgradeAvailable } from "../../selectors/app"; +import { doDownloadUpgrade } from "../../actions/app"; const select = state => ({ isBackDisabled: selectIsBackDisabled(state), isForwardDisabled: selectIsForwardDisabled(state), + isUpgradeAvailable: selectIsUpgradeAvailable(state), balance: formatCredits(selectBalance(state) || 0, 1), publish: __("Publish"), upgradeLabel: __("Upgrade App"), - upgradeSkipped: selectUpgradeSkipped(state), }); const perform = dispatch => ({ diff --git a/ui/js/component/header/view.jsx b/ui/js/component/header/view.jsx index ffb4ff729..3f8853aa0 100644 --- a/ui/js/component/header/view.jsx +++ b/ui/js/component/header/view.jsx @@ -6,14 +6,14 @@ export const Header = props => { const { balance, back, - downloadUpgrade, forward, isBackDisabled, isForwardDisabled, + isUpgradeAvailable, navigate, publish, upgradeLabel, - upgradeSkipped, + downloadUpgrade, } = props; return ( ); From e0aa6e364619d0704d34cab1e1842f0057a882c8 Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Thu, 16 Nov 2017 17:26:00 -0300 Subject: [PATCH 5/7] Remove unused code --- ui/js/component/app/index.js | 6 +----- ui/js/component/app/view.jsx | 2 -- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/ui/js/component/app/index.js b/ui/js/component/app/index.js index f4d8c451b..4b49f92cf 100644 --- a/ui/js/component/app/index.js +++ b/ui/js/component/app/index.js @@ -2,11 +2,7 @@ import React from "react"; import { connect } from "react-redux"; import { selectPageTitle } from "selectors/navigation"; import { selectUser } from "selectors/user"; -import { - doCheckUpgradeAvailable, - doStartUpgradeCheckTimer, - doAlertError, -} from "actions/app"; +import { doCheckUpgradeAvailable, doAlertError } from "actions/app"; import { doRecordScroll } from "actions/navigation"; import { doFetchRewardedContent } from "actions/content"; import App from "./view"; diff --git a/ui/js/component/app/view.jsx b/ui/js/component/app/view.jsx index c23e5d0c8..9ec001bd1 100644 --- a/ui/js/component/app/view.jsx +++ b/ui/js/component/app/view.jsx @@ -33,8 +33,6 @@ class App extends React.PureComponent { this.setTitleFromProps(this.props); } - componentDidMount() {} - componentWillUnmount() { window.removeEventListener("scroll", this.scrollListener); } From 96ab1bf2e2fbcdfc1685c9282de07ba827d34b84 Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Thu, 16 Nov 2017 18:39:10 -0300 Subject: [PATCH 6/7] Move App component's actions to doDaemonReady action --- ui/js/actions/app.js | 29 +++++++++++++++++++---------- ui/js/component/app/index.js | 7 +------ ui/js/component/app/view.jsx | 15 +-------------- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/ui/js/actions/app.js b/ui/js/actions/app.js index 8679000ca..e26bb3ff5 100644 --- a/ui/js/actions/app.js +++ b/ui/js/actions/app.js @@ -13,13 +13,15 @@ import { doBalanceSubscribe } from "actions/wallet"; import { doAuthenticate } from "actions/user"; import { doFetchFileInfosAndPublishedClaims } from "actions/file_info"; 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 path = require("path"); const { download } = remote.require("electron-dl"); const fs = remote.require("fs"); const { lbrySettings: config } = require("../../../app/package.json"); +const CHECK_UPGRADE_INTERVAL = 10 * 60 * 1000; export function doOpenModal(modal, modalProps = {}) { return { @@ -131,21 +133,21 @@ export function doCheckUpgradeAvailable() { return function(dispatch, getState) { const state = getState(); dispatch({ - type: types.CHECK_UPGRADE_STARTED, + type: types.CHECK_UPGRADE_START, }); const success = ({ remoteVersion, upgradeAvailable }) => { dispatch({ - type: types.CHECK_UPGRADE_COMPLETED, + type: types.CHECK_UPGRADE_SUCCESS, data: { upgradeAvailable, 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 ( upgradeAvailable && + !selectCurrentModal(state) && (!selectIsUpgradeSkipped(state) || remoteVersion !== selectRemoteVersion(state)) ) { @@ -158,27 +160,27 @@ export function doCheckUpgradeAvailable() { } }; - const failure = () => { + const fail = () => { 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. */ -export function doInitCheckUpgradeTimer() { +export function doCheckUpgradeSubscribe() { return function(dispatch) { const checkUpgradeTimer = setInterval( () => dispatch(doCheckUpgradeAvailable()), - 600000 + CHECK_UPGRADE_INTERVAL ); dispatch({ - type: types.CHECK_UPGRADE_TIMER_INITIATED, + type: types.CHECK_UPGRADE_SUBSCRIBE, data: { checkUpgradeTimer }, }); }; @@ -212,11 +214,18 @@ export function doAlertError(errorList) { export function doDaemonReady() { return function(dispatch, getState) { + const state = getState(); + dispatch(doAuthenticate()); dispatch({ type: types.DAEMON_READY }); dispatch(doFetchDaemonSettings()); dispatch(doBalanceSubscribe()); dispatch(doFetchFileInfosAndPublishedClaims()); + dispatch(doFetchRewardedContent()); + if (!selectIsUpgradeSkipped(state)) { + dispatch(doCheckUpgradeAvailable()); + } + dispatch(doCheckUpgradeSubscribe()); }; } diff --git a/ui/js/component/app/index.js b/ui/js/component/app/index.js index 4b49f92cf..52ca853ef 100644 --- a/ui/js/component/app/index.js +++ b/ui/js/component/app/index.js @@ -2,11 +2,9 @@ import React from "react"; import { connect } from "react-redux"; import { selectPageTitle } from "selectors/navigation"; import { selectUser } from "selectors/user"; -import { doCheckUpgradeAvailable, doAlertError } from "actions/app"; +import { doAlertError } from "actions/app"; import { doRecordScroll } from "actions/navigation"; -import { doFetchRewardedContent } from "actions/content"; import App from "./view"; -import { doInitCheckUpgradeTimer } from "../../actions/app"; const select = (state, props) => ({ pageTitle: selectPageTitle(state), @@ -15,9 +13,6 @@ const select = (state, props) => ({ const perform = dispatch => ({ alertError: errorList => dispatch(doAlertError(errorList)), - checkUpgradeAvailable: () => dispatch(doCheckUpgradeAvailable()), - initCheckUpgradeTimer: () => dispatch(doInitCheckUpgradeTimer()), - fetchRewardedContent: () => dispatch(doFetchRewardedContent()), recordScroll: scrollPosition => dispatch(doRecordScroll(scrollPosition)), }); diff --git a/ui/js/component/app/view.jsx b/ui/js/component/app/view.jsx index 9ec001bd1..eea6ffcfe 100644 --- a/ui/js/component/app/view.jsx +++ b/ui/js/component/app/view.jsx @@ -7,25 +7,12 @@ import lbry from "lbry"; class App extends React.PureComponent { componentWillMount() { - const { - alertError, - checkUpgradeAvailable, - initCheckUpgradeTimer, - fetchRewardedContent, - } = this.props; + const { alertError } = this.props; document.addEventListener("unhandledError", event => { alertError(event.detail); }); - if (!this.props.upgradeSkipped) { - checkUpgradeAvailable(); - } - - initCheckUpgradeTimer(); - - fetchRewardedContent(); - this.scrollListener = () => this.props.recordScroll(window.scrollY); window.addEventListener("scroll", this.scrollListener); From a578a6b31de7eb9e8a483d8ec7fb099a3c4cbd32 Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Thu, 16 Nov 2017 18:39:10 -0300 Subject: [PATCH 7/7] Update code according to code review. --- ui/js/actions/app.js | 29 +++++++++++++++++++---------- ui/js/component/app/index.js | 7 +------ ui/js/component/app/view.jsx | 15 +-------------- ui/js/component/header/index.js | 2 -- ui/js/component/header/view.jsx | 6 ++---- ui/js/constants/action_types.js | 8 ++++---- ui/js/reducers/app.js | 4 ++-- 7 files changed, 29 insertions(+), 42 deletions(-) diff --git a/ui/js/actions/app.js b/ui/js/actions/app.js index 8679000ca..e26bb3ff5 100644 --- a/ui/js/actions/app.js +++ b/ui/js/actions/app.js @@ -13,13 +13,15 @@ import { doBalanceSubscribe } from "actions/wallet"; import { doAuthenticate } from "actions/user"; import { doFetchFileInfosAndPublishedClaims } from "actions/file_info"; 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 path = require("path"); const { download } = remote.require("electron-dl"); const fs = remote.require("fs"); const { lbrySettings: config } = require("../../../app/package.json"); +const CHECK_UPGRADE_INTERVAL = 10 * 60 * 1000; export function doOpenModal(modal, modalProps = {}) { return { @@ -131,21 +133,21 @@ export function doCheckUpgradeAvailable() { return function(dispatch, getState) { const state = getState(); dispatch({ - type: types.CHECK_UPGRADE_STARTED, + type: types.CHECK_UPGRADE_START, }); const success = ({ remoteVersion, upgradeAvailable }) => { dispatch({ - type: types.CHECK_UPGRADE_COMPLETED, + type: types.CHECK_UPGRADE_SUCCESS, data: { upgradeAvailable, 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 ( upgradeAvailable && + !selectCurrentModal(state) && (!selectIsUpgradeSkipped(state) || remoteVersion !== selectRemoteVersion(state)) ) { @@ -158,27 +160,27 @@ export function doCheckUpgradeAvailable() { } }; - const failure = () => { + const fail = () => { 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. */ -export function doInitCheckUpgradeTimer() { +export function doCheckUpgradeSubscribe() { return function(dispatch) { const checkUpgradeTimer = setInterval( () => dispatch(doCheckUpgradeAvailable()), - 600000 + CHECK_UPGRADE_INTERVAL ); dispatch({ - type: types.CHECK_UPGRADE_TIMER_INITIATED, + type: types.CHECK_UPGRADE_SUBSCRIBE, data: { checkUpgradeTimer }, }); }; @@ -212,11 +214,18 @@ export function doAlertError(errorList) { export function doDaemonReady() { return function(dispatch, getState) { + const state = getState(); + dispatch(doAuthenticate()); dispatch({ type: types.DAEMON_READY }); dispatch(doFetchDaemonSettings()); dispatch(doBalanceSubscribe()); dispatch(doFetchFileInfosAndPublishedClaims()); + dispatch(doFetchRewardedContent()); + if (!selectIsUpgradeSkipped(state)) { + dispatch(doCheckUpgradeAvailable()); + } + dispatch(doCheckUpgradeSubscribe()); }; } diff --git a/ui/js/component/app/index.js b/ui/js/component/app/index.js index 4b49f92cf..52ca853ef 100644 --- a/ui/js/component/app/index.js +++ b/ui/js/component/app/index.js @@ -2,11 +2,9 @@ import React from "react"; import { connect } from "react-redux"; import { selectPageTitle } from "selectors/navigation"; import { selectUser } from "selectors/user"; -import { doCheckUpgradeAvailable, doAlertError } from "actions/app"; +import { doAlertError } from "actions/app"; import { doRecordScroll } from "actions/navigation"; -import { doFetchRewardedContent } from "actions/content"; import App from "./view"; -import { doInitCheckUpgradeTimer } from "../../actions/app"; const select = (state, props) => ({ pageTitle: selectPageTitle(state), @@ -15,9 +13,6 @@ const select = (state, props) => ({ const perform = dispatch => ({ alertError: errorList => dispatch(doAlertError(errorList)), - checkUpgradeAvailable: () => dispatch(doCheckUpgradeAvailable()), - initCheckUpgradeTimer: () => dispatch(doInitCheckUpgradeTimer()), - fetchRewardedContent: () => dispatch(doFetchRewardedContent()), recordScroll: scrollPosition => dispatch(doRecordScroll(scrollPosition)), }); diff --git a/ui/js/component/app/view.jsx b/ui/js/component/app/view.jsx index 9ec001bd1..eea6ffcfe 100644 --- a/ui/js/component/app/view.jsx +++ b/ui/js/component/app/view.jsx @@ -7,25 +7,12 @@ import lbry from "lbry"; class App extends React.PureComponent { componentWillMount() { - const { - alertError, - checkUpgradeAvailable, - initCheckUpgradeTimer, - fetchRewardedContent, - } = this.props; + const { alertError } = this.props; document.addEventListener("unhandledError", event => { alertError(event.detail); }); - if (!this.props.upgradeSkipped) { - checkUpgradeAvailable(); - } - - initCheckUpgradeTimer(); - - fetchRewardedContent(); - this.scrollListener = () => this.props.recordScroll(window.scrollY); window.addEventListener("scroll", this.scrollListener); diff --git a/ui/js/component/header/index.js b/ui/js/component/header/index.js index fe81b277c..c78d7bc8c 100644 --- a/ui/js/component/header/index.js +++ b/ui/js/component/header/index.js @@ -20,8 +20,6 @@ const select = state => ({ isForwardDisabled: selectIsForwardDisabled(state), isUpgradeAvailable: selectIsUpgradeAvailable(state), balance: formatCredits(selectBalance(state) || 0, 1), - publish: __("Publish"), - upgradeLabel: __("Upgrade App"), }); const perform = dispatch => ({ diff --git a/ui/js/component/header/view.jsx b/ui/js/component/header/view.jsx index 3f8853aa0..7bbf9899e 100644 --- a/ui/js/component/header/view.jsx +++ b/ui/js/component/header/view.jsx @@ -11,8 +11,6 @@ export const Header = props => { isForwardDisabled, isUpgradeAvailable, navigate, - publish, - upgradeLabel, downloadUpgrade, } = props; return ( @@ -61,7 +59,7 @@ export const Header = props => { onClick={() => navigate("/publish")} button="primary button--flat" icon="icon-upload" - label={publish} + label={__("Publish")} />
@@ -85,7 +83,7 @@ export const Header = props => { onClick={() => downloadUpgrade()} button="primary button--flat" icon="icon-arrow-up" - label={upgradeLabel} + label={__("Upgrade App")} /> )} diff --git a/ui/js/constants/action_types.js b/ui/js/constants/action_types.js index 47c653524..b2f88f31f 100644 --- a/ui/js/constants/action_types.js +++ b/ui/js/constants/action_types.js @@ -20,10 +20,10 @@ export const UPGRADE_DOWNLOAD_STARTED = "UPGRADE_DOWNLOAD_STARTED"; export const UPGRADE_DOWNLOAD_COMPLETED = "UPGRADE_DOWNLOAD_COMPLETED"; export const UPGRADE_DOWNLOAD_PROGRESSED = "UPGRADE_DOWNLOAD_PROGRESSED"; export const CHECK_UPGRADE_AVAILABLE = "CHECK_UPGRADE_AVAILABLE"; -export const CHECK_UPGRADE_STARTED = "CHECK_UPGRADE_STARTED"; -export const CHECK_UPGRADE_COMPLETED = "CHECK_UPGRADE_COMPLETED"; -export const CHECK_UPGRADE_FAILED = "CHECK_UPGRADE_FAILED"; -export const CHECK_UPGRADE_TIMER_INITIATED = "CHECK_UPGRADE_TIMER_INITIATED"; +export const CHECK_UPGRADE_START = "CHECK_UPGRADE_START"; +export const CHECK_UPGRADE_SUCCESS = "CHECK_UPGRADE_SUCCESS"; +export const CHECK_UPGRADE_FAIL = "CHECK_UPGRADE_FAIL"; +export const CHECK_UPGRADE_SUBSCRIBE = "CHECK_UPGRADE_SUBSCRIBE"; export const UPDATE_VERSION = "UPDATE_VERSION"; export const UPDATE_REMOTE_VERSION = "UPDATE_REMOTE_VERSION"; export const SKIP_UPGRADE = "SKIP_UPGRADE"; diff --git a/ui/js/reducers/app.js b/ui/js/reducers/app.js index 6155ea4c0..b44e84ccb 100644 --- a/ui/js/reducers/app.js +++ b/ui/js/reducers/app.js @@ -75,14 +75,14 @@ reducers[types.UPDATE_VERSION] = function(state, action) { }); }; -reducers[types.CHECK_UPGRADE_COMPLETED] = function(state, action) { +reducers[types.CHECK_UPGRADE_SUCCESS] = function(state, action) { return Object.assign({}, state, { isUpgradeAvailable: action.data.upgradeAvailable, remoteVersion: action.data.remoteVersion, }); }; -reducers[types.CHECK_UPGRADE_TIMER_INITIATED] = function(state, action) { +reducers[types.CHECK_UPGRADE_SUBSCRIBE] = function(state, action) { return Object.assign({}, state, { checkUpgradeTimer: action.data.checkUpgradeTimer, });