This repository has been archived on 2025-09-19. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
repertory-ui/src/redux/actions/install_actions.js
Scott E. Graves 02697aca1e Fix version
2019-06-08 14:08:32 -05:00

128 lines
4.5 KiB
JavaScript

import * as Constants from '../../constants';
import {createAction} from 'redux-starter-kit';
import {getIPCRenderer} from '../../utils';
import {notifyError} from './error_actions';
import {setAllowDownload} from './download_actions';
import {
setActiveRelease,
setInstalledVersion,
setReleaseUpgradeAvailable
} from './release_version_actions';
const ipcRenderer = getIPCRenderer();
export const checkInstalled = (dependencies, version) => {
return (dispatch, getState) => {
const checkInstalledComplete = (event, arg) => {
ipcRenderer.removeListener(Constants.IPC_Check_Installed_Reply, checkInstalledComplete);
const result = arg.data;
const updateState = () => {
const installedVersion = result.Success && result.Exists ? result.Version : 'none';
const state = getState();
let upgradeAvailable = false;
if (installedVersion !== 'none') {
const latestVersion = state.relver.VersionLookup[Constants.RELEASE_TYPES[state.relver.Release]].length - 1;
let version = state.relver.Version;
if (version === -1) {
version = latestVersion;
dispatch(setActiveRelease(state.relver.Release, version));
} else {
upgradeAvailable = version !== latestVersion;
}
}
dispatch(setReleaseUpgradeAvailable(upgradeAvailable));
dispatch(setAllowDownload(true));
dispatch(setInstalledVersion(installedVersion));
dispatch(setMissingDependencies(result.Dependencies));
};
if (result.Success) {
updateState();
} else {
dispatch(notifyError(result.Error, false, updateState));
}
};
ipcRenderer.on(Constants.IPC_Check_Installed_Reply, checkInstalledComplete);
ipcRenderer.send(Constants.IPC_Check_Installed, {
Dependencies: dependencies,
Version: version,
});
};
};
export const installDependency = (source, url, completedCallback) => {
return (dispatch, getState) => {
if (ipcRenderer && !getState().install.InstallActive) {
dispatch(setInstallActive(Constants.INSTALL_TYPES.Dependency));
const installDependencyComplete = (event, arg) => {
ipcRenderer.removeListener(Constants.IPC_Install_Dependency_Reply, installDependencyComplete);
dispatch(setInstallComplete(arg.data));
completedCallback(source, url, arg.data);
};
ipcRenderer.on(Constants.IPC_Install_Dependency_Reply, installDependencyComplete);
ipcRenderer.send(Constants.IPC_Install_Dependency, {
Source: source,
URL: url,
});
}
};
};
export const installRelease = (source, version, completedCallback) => {
return (dispatch, getState) => {
if (ipcRenderer && !getState().install.InstallActive) {
dispatch(setInstallActive(Constants.INSTALL_TYPES.Release));
const extractReleaseComplete = (event, arg) => {
ipcRenderer.removeListener(Constants.IPC_Extract_Release_Complete, extractReleaseComplete);
ipcRenderer.sendSync(Constants.IPC_Delete_File, {
FilePath: source,
});
dispatch(setInstallComplete(arg.data));
completedCallback(source, version, arg.data);
};
ipcRenderer.on(Constants.IPC_Extract_Release_Complete, extractReleaseComplete);
ipcRenderer.send(Constants.IPC_Extract_Release, {
Source: source,
Version: version,
});
}
};
};
export const installUpgrade = (source, sha256, signature, skipVerification, completedCallback) => {
return (dispatch, getState) => {
if (ipcRenderer && !getState().install.InstallActive) {
dispatch(setInstallActive(Constants.INSTALL_TYPES.Dependency));
const installUpgradeComplete = (event, arg) => {
ipcRenderer.removeListener(Constants.IPC_Install_Upgrade_Reply, installUpgradeComplete);
ipcRenderer.sendSync(Constants.IPC_Delete_File, {
FilePath: source,
});
dispatch(setInstallComplete(arg.data));
completedCallback(source, arg.data);
};
ipcRenderer.on(Constants.IPC_Install_Upgrade_Reply, installUpgradeComplete);
ipcRenderer.send(Constants.IPC_Install_Upgrade, {
Sha256: sha256,
Signature: signature,
SkipVerification: skipVerification,
Source: source,
});
}
};
};
export const setInstallActive = createAction('install/setInstallActive');
export const setInstallComplete = createAction('install/setInstallComplete');
export const setMissingDependencies = createAction('install/setMissingDependencies');