2019-02-22 06:01:59 +01:00
|
|
|
// @if TARGET='app'
|
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';
|
2017-12-28 00:48:11 +01:00
|
|
|
import { ipcRenderer, remote } from 'electron';
|
2019-02-22 06:01:59 +01:00
|
|
|
// @endif
|
2019-03-05 05:46:57 +01:00
|
|
|
import path from 'path';
|
2018-11-07 23:44:38 +01:00
|
|
|
import * as ACTIONS from 'constants/action_types';
|
2018-10-29 18:23:53 +01:00
|
|
|
import * as MODALS from 'constants/modal_types';
|
2019-08-14 05:04:08 +02:00
|
|
|
import {
|
|
|
|
Lbry,
|
|
|
|
doBalanceSubscribe,
|
|
|
|
doFetchFileInfosAndPublishedClaims,
|
|
|
|
doError,
|
|
|
|
makeSelectClaimForUri,
|
|
|
|
makeSelectClaimIsMine,
|
2019-09-26 21:31:27 +02:00
|
|
|
doPopulateSharedUserState,
|
2019-09-26 18:07:11 +02:00
|
|
|
doFetchChannelListMine,
|
2019-10-04 19:29:57 +02:00
|
|
|
doClearPublish,
|
2019-10-15 06:20:12 +02:00
|
|
|
doPreferenceGet,
|
|
|
|
doToast,
|
2019-10-30 08:51:41 +01:00
|
|
|
doClearSupport,
|
2019-08-14 05:04:08 +02:00
|
|
|
} from 'lbry-redux';
|
2018-04-18 06:03:01 +02:00
|
|
|
import Native from 'native';
|
2019-11-18 19:30:15 +01:00
|
|
|
import { doFetchDaemonSettings, doSetAutoLaunch } from 'redux/actions/settings';
|
2017-04-07 07:15:22 +02:00
|
|
|
import {
|
2017-12-28 00:48:11 +01:00
|
|
|
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,
|
2018-08-06 19:25:30 +02:00
|
|
|
selectUpgradeTimer,
|
2018-11-28 17:58:47 +01:00
|
|
|
selectModal,
|
2017-12-21 18:32:51 +01:00
|
|
|
} from 'redux/selectors/app';
|
2019-10-22 19:57:32 +02:00
|
|
|
import { doAuthenticate, doGetSync } from 'lbryinc';
|
2018-09-24 05:44:42 +02:00
|
|
|
import { lbrySettings as config, version as appVersion } from 'package.json';
|
2019-08-14 05:04:08 +02:00
|
|
|
import analytics from 'analytics';
|
2019-11-01 17:19:28 +01:00
|
|
|
import { doSignOutCleanup, deleteSavedPassword, getSavedPassword } from 'util/saved-passwords';
|
2017-12-21 18:32:51 +01:00
|
|
|
|
2019-02-22 06:01:59 +01:00
|
|
|
// @if TARGET='app'
|
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');
|
2019-02-22 06:01:59 +01:00
|
|
|
// @endif
|
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
|
|
|
|
2018-11-28 17:58:47 +01:00
|
|
|
export function doOpenModal(id, modalProps = {}) {
|
|
|
|
return {
|
|
|
|
type: ACTIONS.SHOW_MODAL,
|
|
|
|
data: {
|
|
|
|
id,
|
|
|
|
modalProps,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function doHideModal() {
|
|
|
|
return {
|
|
|
|
type: ACTIONS.HIDE_MODAL,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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) => {
|
2019-02-22 06:01:59 +01:00
|
|
|
// @if TARGET='app'
|
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-10-29 18:23:53 +01:00
|
|
|
dispatch(doHideModal());
|
2018-11-28 17:58:47 +01:00
|
|
|
dispatch(doOpenModal(MODALS.DOWNLOADING));
|
2019-02-22 06:01:59 +01:00
|
|
|
// @endif
|
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.
|
|
|
|
|
2019-10-03 00:57:11 +02:00
|
|
|
return dispatch => {
|
2020-01-15 05:34:28 +01:00
|
|
|
if (['win32', 'darwin'].includes(process.platform) || !!process.env.APPIMAGE) {
|
2018-03-15 01:22:54 +01:00
|
|
|
// electron-updater behavior
|
2019-10-03 00:57:11 +02:00
|
|
|
dispatch(doOpenModal(MODALS.AUTO_UPDATE_DOWNLOADED));
|
2018-03-15 01:22:54 +01:00
|
|
|
} else {
|
|
|
|
// Old behavior for Linux
|
|
|
|
dispatch(doDownloadUpgrade());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-08-07 16:02:11 +02:00
|
|
|
export function doClearUpgradeTimer() {
|
2018-08-07 15:33:06 +02:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
const state = getState();
|
2018-08-07 16:02:11 +02:00
|
|
|
|
|
|
|
if (selectUpgradeTimer(state)) {
|
|
|
|
clearInterval(selectUpgradeTimer(state));
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.CLEAR_UPGRADE_TIMER,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function doAutoUpdate() {
|
|
|
|
return dispatch => {
|
2018-01-16 06:38:23 +01:00
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.AUTO_UPDATE_DOWNLOADED,
|
|
|
|
});
|
|
|
|
|
2018-11-28 17:58:47 +01:00
|
|
|
dispatch(doOpenModal(MODALS.AUTO_UPDATE_DOWNLOADED));
|
2018-08-07 15:33:06 +02:00
|
|
|
|
2018-08-07 16:02:11 +02:00
|
|
|
dispatch(doClearUpgradeTimer());
|
2017-12-08 13:14:37 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-01-17 11:50:02 +01:00
|
|
|
export function doAutoUpdateDeclined() {
|
2018-08-07 16:02:11 +02:00
|
|
|
return dispatch => {
|
|
|
|
dispatch(doClearUpgradeTimer());
|
2018-08-06 19:25:30 +02:00
|
|
|
|
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) {
|
2019-07-23 10:05:51 +02:00
|
|
|
console.error(err); // eslint-disable-line no-console
|
2017-04-07 07:15:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-01-15 05:34:28 +01:00
|
|
|
if (['win32', 'darwin'].includes(process.platform) || !!process.env.APPIMAGE) {
|
|
|
|
// On Windows, Mac, and AppImage, updates happen silently through
|
2018-03-15 01:22:54 +01:00
|
|
|
// 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 &&
|
2018-11-28 17:58:47 +01:00
|
|
|
!selectModal(state) &&
|
2018-03-15 01:22:54 +01:00
|
|
|
(!selectIsUpgradeSkipped(state) || remoteVersion !== selectRemoteVersion(state))
|
|
|
|
) {
|
2018-11-28 17:58:47 +01:00
|
|
|
dispatch(doOpenModal(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 => {
|
2019-05-07 23:38:29 +02:00
|
|
|
const checkUpgradeTimer = setInterval(() => dispatch(doCheckUpgradeAvailable()), 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 => {
|
2019-02-22 06:01:59 +01:00
|
|
|
// @if TARGET='app'
|
2017-12-21 18:32:51 +01:00
|
|
|
Lbry.version().then(({ lbrynet_version: lbrynetVersion }) => {
|
2018-07-11 06:14:50 +02:00
|
|
|
// Avoid the incompatible daemon modal if running in dev mode
|
2019-04-15 05:45:13 +02:00
|
|
|
// Lets you run a different daemon than the one specified in package.json
|
2019-01-10 02:38:26 +01:00
|
|
|
if (config.lbrynetDaemonVersion === lbrynetVersion) {
|
2018-07-11 06:14:50 +02:00
|
|
|
return dispatch({
|
2018-05-11 01:06:41 +02:00
|
|
|
type: ACTIONS.DAEMON_VERSION_MATCH,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-07-19 23:05:08 +02:00
|
|
|
dispatch({
|
2018-05-11 01:06:41 +02:00
|
|
|
type: ACTIONS.DAEMON_VERSION_MISMATCH,
|
2017-07-19 23:05:08 +02:00
|
|
|
});
|
2018-07-11 06:14:50 +02:00
|
|
|
|
2018-11-28 17:58:47 +01:00
|
|
|
return dispatch(doOpenModal(MODALS.INCOMPATIBLE_DAEMON));
|
2017-07-19 23:05:08 +02:00
|
|
|
});
|
2019-02-22 06:01:59 +01:00
|
|
|
// @endif
|
|
|
|
// @if TARGET='web'
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.DAEMON_VERSION_MATCH,
|
|
|
|
});
|
|
|
|
// @endif
|
2017-07-19 23:05:08 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-07-18 21:48:30 +02:00
|
|
|
export function doNotifyEncryptWallet() {
|
|
|
|
return dispatch => {
|
2018-11-28 17:58:47 +01:00
|
|
|
dispatch(doOpenModal(MODALS.WALLET_ENCRYPT));
|
2018-07-18 21:48:30 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function doNotifyDecryptWallet() {
|
|
|
|
return dispatch => {
|
2018-11-28 17:58:47 +01:00
|
|
|
dispatch(doOpenModal(MODALS.WALLET_DECRYPT));
|
2018-07-18 21:48:30 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function doNotifyUnlockWallet() {
|
|
|
|
return dispatch => {
|
2018-11-28 17:58:47 +01:00
|
|
|
dispatch(doOpenModal(MODALS.WALLET_UNLOCK));
|
2018-07-18 21:48:30 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-26 18:28:08 +02:00
|
|
|
export function doNotifyForgetPassword(props) {
|
2019-08-20 14:29:59 +02:00
|
|
|
return dispatch => {
|
2019-09-26 18:28:08 +02:00
|
|
|
dispatch(doOpenModal(MODALS.WALLET_PASSWORD_UNSAVE, props));
|
2019-08-20 14:29:59 +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-11-28 17:58:47 +01:00
|
|
|
dispatch(doError(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-09-24 05:44:42 +02:00
|
|
|
dispatch(doAuthenticate(appVersion));
|
2017-12-21 18:32:51 +01:00
|
|
|
dispatch({ type: ACTIONS.DAEMON_READY });
|
2019-03-29 15:23:32 +01:00
|
|
|
|
2019-02-22 06:01:59 +01:00
|
|
|
// @if TARGET='app'
|
2019-04-15 05:45:13 +02:00
|
|
|
dispatch(doBalanceSubscribe());
|
2019-11-18 19:30:15 +01:00
|
|
|
dispatch(doSetAutoLaunch());
|
2019-09-26 18:07:11 +02:00
|
|
|
dispatch(doFetchDaemonSettings());
|
2017-09-07 15:38:44 +02:00
|
|
|
dispatch(doFetchFileInfosAndPublishedClaims());
|
2017-11-16 22:39:10 +01:00
|
|
|
if (!selectIsUpgradeSkipped(state)) {
|
|
|
|
dispatch(doCheckUpgradeAvailable());
|
|
|
|
}
|
|
|
|
dispatch(doCheckUpgradeSubscribe());
|
2019-02-22 06:01:59 +01:00
|
|
|
// @endif
|
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() {
|
2019-10-04 19:29:57 +02:00
|
|
|
return dispatch => {
|
2019-07-23 10:05:51 +02:00
|
|
|
// Need to update this to work with new version of redux-persist
|
|
|
|
// Leaving for now
|
|
|
|
// const reducersToClear = whiteListedReducers.filter(reducerKey => reducerKey !== 'tags');
|
|
|
|
// window.cacheStore.purge(reducersToClear);
|
2019-07-23 22:13:06 +02:00
|
|
|
window.localStorage.clear();
|
2019-10-30 08:51:41 +01:00
|
|
|
dispatch(doClearSupport());
|
2019-10-04 19:29:57 +02:00
|
|
|
return dispatch(doClearPublish());
|
2017-06-16 07:43:43 +02:00
|
|
|
};
|
|
|
|
}
|
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 () => {
|
2019-02-22 06:01:59 +01:00
|
|
|
// @if TARGET='app'
|
2017-07-19 23:05:08 +02:00
|
|
|
remote.app.quit();
|
2019-02-22 06:01:59 +01:00
|
|
|
// @endif
|
2017-07-19 23:05:08 +02:00
|
|
|
};
|
|
|
|
}
|
2017-08-25 21:05:00 +02:00
|
|
|
|
2018-03-16 00:04:15 +01:00
|
|
|
export function doQuitAnyDaemon() {
|
|
|
|
return dispatch => {
|
2019-02-22 06:01:59 +01:00
|
|
|
// @if TARGET='app'
|
2019-02-18 18:33:02 +01:00
|
|
|
Lbry.stop()
|
|
|
|
.catch(() => {
|
|
|
|
try {
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
execSync('taskkill /im lbrynet.exe /t /f');
|
|
|
|
} else {
|
|
|
|
execSync('pkill lbrynet');
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
dispatch(doAlertError(`Quitting daemon failed due to: ${error.message}`));
|
|
|
|
}
|
2019-02-22 06:01:59 +01:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
dispatch(doQuit());
|
2019-02-18 18:33:02 +01:00
|
|
|
});
|
2019-02-22 06:01:59 +01:00
|
|
|
// @endif
|
2018-03-16 00:04:15 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-07-27 23:17:25 +02:00
|
|
|
export function doChangeMute(muted) {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.VOLUME_MUTED,
|
|
|
|
data: {
|
|
|
|
muted,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-11-07 23:44:38 +01:00
|
|
|
export function doClickCommentButton() {
|
|
|
|
return {
|
|
|
|
type: ACTIONS.ADD_COMMENT,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-02-21 23:45:17 +01:00
|
|
|
export function doToggleSearchExpanded() {
|
|
|
|
return {
|
|
|
|
type: ACTIONS.TOGGLE_SEARCH_EXPANDED,
|
|
|
|
};
|
|
|
|
}
|
2019-08-14 05:04:08 +02:00
|
|
|
|
|
|
|
export function doAnalyticsView(uri, timeToStart) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const state = getState();
|
|
|
|
const { txid, nout, claim_id: claimId } = makeSelectClaimForUri(uri)(state);
|
|
|
|
const claimIsMine = makeSelectClaimIsMine(uri)(state);
|
|
|
|
const outpoint = `${txid}:${nout}`;
|
|
|
|
|
|
|
|
if (claimIsMine) {
|
2019-09-21 18:45:52 +02:00
|
|
|
return Promise.resolve();
|
2019-08-14 05:04:08 +02:00
|
|
|
}
|
|
|
|
|
2019-09-18 20:41:20 +02:00
|
|
|
return analytics.apiLogView(uri, outpoint, claimId, timeToStart);
|
2019-08-14 05:04:08 +02:00
|
|
|
};
|
|
|
|
}
|
2019-09-26 18:07:11 +02:00
|
|
|
|
|
|
|
export function doSignIn() {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
// @if TARGET='web'
|
|
|
|
dispatch(doBalanceSubscribe());
|
|
|
|
dispatch(doFetchChannelListMine());
|
2019-10-01 06:53:33 +02:00
|
|
|
// @endif
|
2019-09-26 18:07:11 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function doSignOut() {
|
|
|
|
return dispatch => {
|
2019-11-01 17:19:28 +01:00
|
|
|
doSignOutCleanup()
|
2019-09-26 18:07:11 +02:00
|
|
|
.then(() => {
|
2019-10-03 23:40:54 +02:00
|
|
|
// @if TARGET='web'
|
|
|
|
window.persistor.purge();
|
|
|
|
// @endif
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
location.reload();
|
|
|
|
});
|
2019-09-26 18:07:11 +02:00
|
|
|
})
|
|
|
|
.catch(() => location.reload());
|
|
|
|
};
|
|
|
|
}
|
2019-10-15 23:23:51 +02:00
|
|
|
|
2019-12-11 21:09:27 +01:00
|
|
|
export function doGetAndPopulatePreferences() {
|
2019-10-15 23:23:51 +02:00
|
|
|
return dispatch => {
|
2019-12-11 21:09:27 +01:00
|
|
|
function successCb(savedPreferences) {
|
|
|
|
if (savedPreferences !== null) {
|
|
|
|
dispatch(doPopulateSharedUserState(savedPreferences));
|
2019-10-15 23:23:51 +02:00
|
|
|
}
|
2019-12-11 21:09:27 +01:00
|
|
|
}
|
2019-10-15 23:23:51 +02:00
|
|
|
|
2019-12-11 21:09:27 +01:00
|
|
|
function failCb() {
|
|
|
|
deleteSavedPassword().then(() => {
|
|
|
|
dispatch(
|
|
|
|
doToast({
|
|
|
|
isError: true,
|
|
|
|
message: __('Unable to load your saved preferences.'),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2020-01-02 17:30:27 +01:00
|
|
|
|
2019-12-11 21:09:27 +01:00
|
|
|
doPreferenceGet('shared', successCb, failCb);
|
|
|
|
};
|
|
|
|
}
|
2019-10-15 23:23:51 +02:00
|
|
|
|
2019-12-11 21:09:27 +01:00
|
|
|
export function doSyncWithPreferences() {
|
|
|
|
return dispatch => {
|
|
|
|
function handleSyncComplete() {
|
|
|
|
// we just got sync data, better update our channels
|
|
|
|
dispatch(doFetchChannelListMine());
|
|
|
|
dispatch(doGetAndPopulatePreferences());
|
2019-10-15 23:23:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return getSavedPassword().then(password => {
|
|
|
|
const passwordArgument = password === null ? '' : password;
|
|
|
|
|
2019-10-16 07:41:49 +02:00
|
|
|
dispatch(doGetSync(passwordArgument, handleSyncComplete));
|
2019-10-15 23:23:51 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|