2018-03-16 00:04:15 +01:00
|
|
|
import { execSync } from 'child_process';
|
2018-03-08 00:03:45 +01:00
|
|
|
import isDev from 'electron-is-dev';
|
|
|
|
import path from 'path';
|
2017-12-28 00:48:11 +01:00
|
|
|
import * as MODALS from 'constants/modal_types';
|
|
|
|
import { ipcRenderer, remote } from 'electron';
|
2018-04-23 07:04:11 +02:00
|
|
|
import {
|
|
|
|
ACTIONS,
|
|
|
|
Lbry,
|
|
|
|
doBalanceSubscribe,
|
|
|
|
doFetchFileInfosAndPublishedClaims,
|
|
|
|
doNotify,
|
|
|
|
} from 'lbry-redux';
|
2018-04-18 06:03:01 +02:00
|
|
|
import Native from 'native';
|
2017-12-28 00:48:11 +01:00
|
|
|
import { doFetchRewardedContent } from 'redux/actions/content';
|
|
|
|
import { doFetchDaemonSettings } from 'redux/actions/settings';
|
2018-04-18 06:03:01 +02:00
|
|
|
import { doAuthNavigate } from 'redux/actions/navigation';
|
2018-03-26 19:26:02 +02:00
|
|
|
import { doAuthenticate } from 'redux/actions/user';
|
2018-02-24 01:24:00 +01:00
|
|
|
import { doPause } from 'redux/actions/media';
|
2018-03-06 08:44:36 +01:00
|
|
|
import { doCheckSubscriptions } from 'redux/actions/subscriptions';
|
2017-04-07 07:15:22 +02:00
|
|
|
import {
|
2017-12-28 00:48:11 +01:00
|
|
|
selectCurrentModal,
|
|
|
|
selectIsUpgradeSkipped,
|
2017-04-07 07:15:22 +02:00
|
|
|
selectUpdateUrl,
|
|
|
|
selectUpgradeDownloadItem,
|
2017-12-28 00:48:11 +01:00
|
|
|
selectUpgradeDownloadPath,
|
2017-07-29 01:31:10 +02:00
|
|
|
selectUpgradeFilename,
|
2018-01-17 11:50:02 +01:00
|
|
|
selectAutoUpdateDeclined,
|
2018-03-15 01:22:54 +01:00
|
|
|
selectRemoteVersion,
|
2017-12-21 18:32:51 +01:00
|
|
|
} from 'redux/selectors/app';
|
2018-03-08 00:03:45 +01:00
|
|
|
import { lbrySettings as config } from 'package.json';
|
2017-12-21 18:32:51 +01:00
|
|
|
|
2017-12-08 13:14:37 +01:00
|
|
|
const { autoUpdater } = remote.require('electron-updater');
|
2017-12-21 18:32:51 +01:00
|
|
|
const { download } = remote.require('electron-dl');
|
|
|
|
const Fs = remote.require('fs');
|
2017-12-13 22:36:30 +01:00
|
|
|
|
2017-11-16 22:39:10 +01:00
|
|
|
const CHECK_UPGRADE_INTERVAL = 10 * 60 * 1000;
|
2017-04-07 07:15:22 +02:00
|
|
|
|
|
|
|
export function doUpdateDownloadProgress(percent) {
|
|
|
|
return {
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.UPGRADE_DOWNLOAD_PROGRESSED,
|
2017-04-07 07:15:22 +02:00
|
|
|
data: {
|
2017-12-13 22:36:30 +01:00
|
|
|
percent,
|
2017-06-06 23:19:12 +02:00
|
|
|
},
|
|
|
|
};
|
2017-04-07 07:15:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function doSkipUpgrade() {
|
|
|
|
return {
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.SKIP_UPGRADE,
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-07 07:15:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function doStartUpgrade() {
|
2017-12-28 00:48:11 +01:00
|
|
|
return (dispatch, getState) => {
|
2017-06-06 23:19:12 +02:00
|
|
|
const state = getState();
|
|
|
|
const upgradeDownloadPath = selectUpgradeDownloadPath(state);
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
ipcRenderer.send('upgrade', upgradeDownloadPath);
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-07 07:15:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function doDownloadUpgrade() {
|
2017-12-28 00:48:11 +01:00
|
|
|
return (dispatch, getState) => {
|
2017-06-06 23:19:12 +02:00
|
|
|
const state = getState();
|
2017-04-07 07:15:22 +02:00
|
|
|
// Make a new directory within temp directory so the filename is guaranteed to be available
|
2018-03-08 00:03:45 +01:00
|
|
|
const dir = Fs.mkdtempSync(remote.app.getPath('temp') + path.sep);
|
2017-12-21 18:32:51 +01:00
|
|
|
const upgradeFilename = selectUpgradeFilename(state);
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-12-13 22:36:30 +01:00
|
|
|
const options = {
|
2017-06-06 23:19:12 +02:00
|
|
|
onProgress: p => dispatch(doUpdateDownloadProgress(Math.round(p * 100))),
|
2017-04-07 07:15:22 +02:00
|
|
|
directory: dir,
|
|
|
|
};
|
2017-12-21 18:32:51 +01:00
|
|
|
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.
|
|
|
|
*/
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.UPGRADE_DOWNLOAD_COMPLETED,
|
|
|
|
data: {
|
|
|
|
downloadItem,
|
2018-03-08 00:03:45 +01:00
|
|
|
path: path.join(dir, upgradeFilename),
|
2017-12-21 18:32:51 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2017-04-07 07:15:22 +02:00
|
|
|
|
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.UPGRADE_DOWNLOAD_STARTED,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2018-04-23 07:04:11 +02:00
|
|
|
dispatch(doNotify({
|
|
|
|
id: MODALS.DOWNLOADING,
|
|
|
|
}));
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-07 07:15:22 +02:00
|
|
|
}
|
|
|
|
|
2018-03-15 01:22:54 +01:00
|
|
|
export function doDownloadUpgradeRequested() {
|
|
|
|
// This means the user requested an upgrade by clicking the "upgrade" button in the navbar.
|
|
|
|
// If on Mac and Windows, we do some new behavior for the auto-update system.
|
|
|
|
// This will probably be reorganized once we get auto-update going on Linux and remove
|
|
|
|
// the old logic.
|
|
|
|
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
// Pause video if needed
|
|
|
|
dispatch(doPause());
|
|
|
|
|
|
|
|
const autoUpdateDeclined = selectAutoUpdateDeclined(state);
|
|
|
|
|
|
|
|
if (['win32', 'darwin'].includes(process.platform)) {
|
|
|
|
// electron-updater behavior
|
|
|
|
if (autoUpdateDeclined) {
|
|
|
|
// The user declined an update before, so show the "confirm" dialog
|
2018-04-23 07:04:11 +02:00
|
|
|
dispatch(doNotify({
|
|
|
|
id: MODALS.AUTO_UPDATE_CONFIRM
|
|
|
|
}));
|
2018-03-15 01:22:54 +01:00
|
|
|
} else {
|
|
|
|
// The user was never shown the original update dialog (e.g. because they were
|
|
|
|
// watching a video). So show the inital "update downloaded" dialog.
|
2018-04-23 07:04:11 +02:00
|
|
|
dispatch(doNotify({
|
|
|
|
id: MODALS.AUTO_UPDATE_DOWNLOADED
|
|
|
|
}));
|
2018-03-15 01:22:54 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Old behavior for Linux
|
|
|
|
dispatch(doDownloadUpgrade());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-12-08 13:14:37 +01:00
|
|
|
export function doAutoUpdate() {
|
2018-03-08 00:03:45 +01:00
|
|
|
return dispatch => {
|
2018-01-16 06:38:23 +01:00
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.AUTO_UPDATE_DOWNLOADED,
|
|
|
|
});
|
|
|
|
|
2018-04-23 07:04:11 +02:00
|
|
|
dispatch(doNotify({
|
|
|
|
id: MODALS.AUTO_UPDATE_DOWNLOADED
|
|
|
|
}));
|
2017-12-08 13:14:37 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-01-17 11:50:02 +01:00
|
|
|
export function doAutoUpdateDeclined() {
|
2018-03-08 00:03:45 +01:00
|
|
|
return dispatch => {
|
2018-01-17 11:50:02 +01:00
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.AUTO_UPDATE_DECLINED,
|
|
|
|
});
|
2018-02-24 01:24:00 +01:00
|
|
|
};
|
2018-01-17 11:50:02 +01:00
|
|
|
}
|
|
|
|
|
2017-04-07 07:15:22 +02:00
|
|
|
export function doCancelUpgrade() {
|
2017-12-28 00:48:11 +01:00
|
|
|
return (dispatch, getState) => {
|
2017-06-06 23:19:12 +02:00
|
|
|
const state = getState();
|
|
|
|
const upgradeDownloadItem = selectUpgradeDownloadItem(state);
|
2017-04-07 07:15:22 +02:00
|
|
|
|
|
|
|
if (upgradeDownloadItem) {
|
|
|
|
/*
|
|
|
|
* Right now the remote reference to the download item gets garbage collected as soon as the
|
|
|
|
* the download is over (maybe even earlier), so trying to cancel a finished download may
|
|
|
|
* throw an error.
|
|
|
|
*/
|
|
|
|
try {
|
|
|
|
upgradeDownloadItem.cancel();
|
|
|
|
} catch (err) {
|
2018-03-08 00:03:45 +01:00
|
|
|
// eslint-disable-next-line no-console
|
2017-06-06 23:19:12 +02:00
|
|
|
console.error(err);
|
2017-04-07 07:15:22 +02:00
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
dispatch({ type: ACTIONS.UPGRADE_CANCELLED });
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-07 07:15:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function doCheckUpgradeAvailable() {
|
2017-12-28 00:48:11 +01:00
|
|
|
return (dispatch, getState) => {
|
2017-06-06 23:19:12 +02:00
|
|
|
const state = getState();
|
2017-11-15 02:50:21 +01:00
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.CHECK_UPGRADE_START,
|
2017-11-15 02:50:21 +01:00
|
|
|
});
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2018-03-15 01:22:54 +01:00
|
|
|
if (['win32', 'darwin'].includes(process.platform)) {
|
|
|
|
// On Windows and Mac, updates happen silently through
|
|
|
|
// electron-updater.
|
|
|
|
const autoUpdateDeclined = selectAutoUpdateDeclined(state);
|
2018-01-24 21:42:49 +01:00
|
|
|
|
2018-03-15 01:22:54 +01:00
|
|
|
if (!autoUpdateDeclined && !isDev) {
|
|
|
|
autoUpdater.checkForUpdates();
|
|
|
|
}
|
|
|
|
return;
|
2017-12-08 13:14:37 +01:00
|
|
|
}
|
2018-03-15 01:22:54 +01:00
|
|
|
|
|
|
|
const success = ({ remoteVersion, upgradeAvailable }) => {
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.CHECK_UPGRADE_SUCCESS,
|
|
|
|
data: {
|
|
|
|
upgradeAvailable,
|
|
|
|
remoteVersion,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (
|
|
|
|
upgradeAvailable &&
|
|
|
|
!selectCurrentModal(state) &&
|
|
|
|
(!selectIsUpgradeSkipped(state) || remoteVersion !== selectRemoteVersion(state))
|
|
|
|
) {
|
2018-04-23 07:04:11 +02:00
|
|
|
dispatch(doNotify({
|
|
|
|
id: MODALS.UPGRADE
|
|
|
|
}));
|
2018-03-15 01:22:54 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const fail = () => {
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.CHECK_UPGRADE_FAIL,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-04-18 06:03:01 +02:00
|
|
|
Native.getAppVersionInfo().then(success, fail);
|
2017-11-15 02:50:21 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Initiate a timer that will check for an app upgrade every 10 minutes.
|
|
|
|
*/
|
2017-11-16 22:39:10 +01:00
|
|
|
export function doCheckUpgradeSubscribe() {
|
2017-12-28 00:48:11 +01:00
|
|
|
return dispatch => {
|
2017-11-15 02:50:21 +01:00
|
|
|
const checkUpgradeTimer = setInterval(
|
|
|
|
() => dispatch(doCheckUpgradeAvailable()),
|
2017-11-16 22:39:10 +01:00
|
|
|
CHECK_UPGRADE_INTERVAL
|
2017-11-15 02:50:21 +01:00
|
|
|
);
|
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.CHECK_UPGRADE_SUBSCRIBE,
|
2017-11-15 02:50:21 +01:00
|
|
|
data: { checkUpgradeTimer },
|
2017-04-07 07:15:22 +02:00
|
|
|
});
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-07 07:15:22 +02:00
|
|
|
}
|
|
|
|
|
2017-07-19 23:05:08 +02:00
|
|
|
export function doCheckDaemonVersion() {
|
2017-12-28 00:48:11 +01:00
|
|
|
return dispatch => {
|
2017-12-21 18:32:51 +01:00
|
|
|
Lbry.version().then(({ lbrynet_version: lbrynetVersion }) => {
|
2017-07-19 23:05:08 +02:00
|
|
|
dispatch({
|
2017-11-24 15:31:05 +01:00
|
|
|
type:
|
2017-12-21 18:32:51 +01:00
|
|
|
config.lbrynetDaemonVersion === lbrynetVersion
|
|
|
|
? ACTIONS.DAEMON_VERSION_MATCH
|
|
|
|
: ACTIONS.DAEMON_VERSION_MISMATCH,
|
2017-07-19 23:05:08 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-04-07 07:15:22 +02:00
|
|
|
export function doAlertError(errorList) {
|
2017-12-28 00:48:11 +01:00
|
|
|
return dispatch => {
|
2018-04-23 07:04:11 +02:00
|
|
|
dispatch(
|
|
|
|
doNotify({
|
|
|
|
id: MODALS.ERROR,
|
|
|
|
error: errorList,
|
|
|
|
})
|
|
|
|
);
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-07 07:15:22 +02:00
|
|
|
}
|
|
|
|
|
2017-04-22 15:17:01 +02:00
|
|
|
export function doDaemonReady() {
|
2017-12-28 00:48:11 +01:00
|
|
|
return (dispatch, getState) => {
|
2017-11-16 22:39:10 +01:00
|
|
|
const state = getState();
|
|
|
|
|
2018-03-26 19:26:02 +02:00
|
|
|
dispatch(doAuthenticate());
|
2017-12-21 18:32:51 +01:00
|
|
|
dispatch({ type: ACTIONS.DAEMON_READY });
|
2017-06-08 02:56:52 +02:00
|
|
|
dispatch(doFetchDaemonSettings());
|
2017-09-23 00:59:28 +02:00
|
|
|
dispatch(doBalanceSubscribe());
|
2017-09-07 15:38:44 +02:00
|
|
|
dispatch(doFetchFileInfosAndPublishedClaims());
|
2017-11-16 22:39:10 +01:00
|
|
|
dispatch(doFetchRewardedContent());
|
|
|
|
if (!selectIsUpgradeSkipped(state)) {
|
|
|
|
dispatch(doCheckUpgradeAvailable());
|
|
|
|
}
|
|
|
|
dispatch(doCheckUpgradeSubscribe());
|
2018-03-06 08:44:36 +01:00
|
|
|
dispatch(doCheckSubscriptions());
|
2017-06-08 02:56:52 +02:00
|
|
|
};
|
2017-04-22 15:17:01 +02:00
|
|
|
}
|
2017-05-23 09:21:21 +02:00
|
|
|
|
2017-06-16 07:43:43 +02:00
|
|
|
export function doClearCache() {
|
2017-12-28 00:48:11 +01:00
|
|
|
return () => {
|
2017-06-16 07:43:43 +02:00
|
|
|
window.cacheStore.purge();
|
|
|
|
|
|
|
|
return Promise.resolve();
|
|
|
|
};
|
|
|
|
}
|
2017-07-19 23:05:08 +02:00
|
|
|
|
2017-07-29 21:22:17 +02:00
|
|
|
export function doQuit() {
|
2017-12-28 00:48:11 +01:00
|
|
|
return () => {
|
2017-07-19 23:05:08 +02:00
|
|
|
remote.app.quit();
|
|
|
|
};
|
|
|
|
}
|
2017-08-25 21:05:00 +02:00
|
|
|
|
2018-03-16 00:04:15 +01:00
|
|
|
export function doQuitAnyDaemon() {
|
|
|
|
return dispatch => {
|
|
|
|
try {
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
execSync('taskkill /im lbrynet-daemon.exe /t /f');
|
|
|
|
} else {
|
|
|
|
execSync('pkill lbrynet-daemon');
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
dispatch(doAlertError(`Quitting daemon failed due to: ${error.message}`));
|
|
|
|
} finally {
|
|
|
|
dispatch(doQuit());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-08-25 21:05:00 +02:00
|
|
|
export function doChangeVolume(volume) {
|
2017-12-28 00:48:11 +01:00
|
|
|
return dispatch => {
|
2017-08-25 21:05:00 +02:00
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.VOLUME_CHANGED,
|
2017-08-25 21:05:00 +02:00
|
|
|
data: {
|
|
|
|
volume,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2017-12-23 03:09:06 +01:00
|
|
|
|
|
|
|
export function doConditionalAuthNavigate(newSession) {
|
2017-12-28 00:48:11 +01:00
|
|
|
return (dispatch, getState) => {
|
2017-12-23 03:09:06 +01:00
|
|
|
const state = getState();
|
2017-12-26 14:25:26 +01:00
|
|
|
if (newSession || selectCurrentModal(state) !== 'email_collection') {
|
2017-12-23 03:09:06 +01:00
|
|
|
dispatch(doAuthNavigate());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|