Redux changes and refactoring
This commit is contained in:
@@ -119,7 +119,7 @@ function createWindow() {
|
||||
// Unmount all items
|
||||
for (const i in mountedLocations) {
|
||||
const data = mountedData[mountedLocations[i]];
|
||||
helpers.stopMountProcessSync(data.DataDirectory, data.Version, data.StorageType);
|
||||
helpers.stopMountProcessSync(data.Version, data.StorageType);
|
||||
}
|
||||
|
||||
mountedLocations = [];
|
||||
@@ -223,10 +223,10 @@ const loadUiSettings = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const monitorMount = (sender, storageType, dataDirectory, version, pid, location) => {
|
||||
const monitorMount = (sender, storageType, version, pid, location) => {
|
||||
manualMountDetection[storageType] = setInterval(() => {
|
||||
helpers
|
||||
.detectRepertoryMounts(dataDirectory, version)
|
||||
.detectRepertoryMounts(version)
|
||||
.then(result => {
|
||||
if (result[storageType].PID !== pid) {
|
||||
if (result[storageType].PID === -1) {
|
||||
@@ -252,7 +252,7 @@ const monitorMount = (sender, storageType, dataDirectory, version, pid, location
|
||||
};
|
||||
|
||||
const saveUiSettings = () => {
|
||||
const settingFile = path.join(helpers.resolvePath(Constants.DATA_LOCATIONS[os.platform()]), 'ui.json');
|
||||
const settingFile = path.join(helpers.getDataDirectory(), 'ui.json');
|
||||
try {
|
||||
fs.writeFileSync(settingFile, JSON.stringify({
|
||||
launch_hidden: launchHidden,
|
||||
@@ -288,9 +288,8 @@ ipcMain.on(Constants.IPC_Browse_Directory + '_sync', (event, data) => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Check_Daemon_Version, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
helpers
|
||||
.checkDaemonVersion(dataDirectory, data.Version, data.StorageType)
|
||||
.checkDaemonVersion(data.Version, data.StorageType)
|
||||
.then(code => {
|
||||
standardIPCReply(event, Constants.IPC_Check_Daemon_Version_Reply, {
|
||||
Valid: (code === 0),
|
||||
@@ -304,9 +303,8 @@ ipcMain.on(Constants.IPC_Check_Daemon_Version, (event, data) => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Check_Daemon_Version + '_sync', (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
helpers
|
||||
.checkDaemonVersion(dataDirectory, data.Version, data.StorageType)
|
||||
.checkDaemonVersion(data.Version, data.StorageType)
|
||||
.then(code => {
|
||||
event.returnValue = {
|
||||
data: {
|
||||
@@ -361,8 +359,7 @@ ipcMain.on(Constants.IPC_Check_Dependency_Installed + '_sync', (event, data) =>
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Check_Installed, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
const destination = path.join(dataDirectory, data.Version);
|
||||
const destination = path.join(helpers.getDataDirectory(), data.Version);
|
||||
helpers
|
||||
.getMissingDependencies(data.Dependencies)
|
||||
.then((dependencies) => {
|
||||
@@ -493,9 +490,8 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
|
||||
mainWindowTray.setImage(image);
|
||||
};
|
||||
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
helpers
|
||||
.detectRepertoryMounts(dataDirectory, data.Version)
|
||||
.detectRepertoryMounts(data.Version)
|
||||
.then((results) => {
|
||||
let storageData = {};
|
||||
let locations = {};
|
||||
@@ -510,7 +506,7 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
|
||||
if (storageData[provider].PID !== -1) {
|
||||
expectedUnmount[provider] = false;
|
||||
if (firstMountCheck) {
|
||||
monitorMount(event.sender, provider, dataDirectory, data.Version, storageData[provider].PID, storageData[provider].Location);
|
||||
monitorMount(event.sender, provider, data.Version, storageData[provider].PID, storageData[provider].Location);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -540,8 +536,7 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Download_File, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
const destination = path.join(dataDirectory, data.Filename);
|
||||
const destination = path.join(helpers.getDataDirectory(), data.Filename);
|
||||
helpers.downloadFile(data.URL, destination, (progress) => {
|
||||
standardIPCReply(event, Constants.IPC_Download_File_Progress, {
|
||||
Destination: destination,
|
||||
@@ -557,8 +552,7 @@ ipcMain.on(Constants.IPC_Download_File, (event, data) => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Extract_Release, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
const destination = path.join(dataDirectory, data.Version);
|
||||
const destination = path.join(helpers.getDataDirectory(), data.Version);
|
||||
helpers.mkDirByPathSync(destination);
|
||||
|
||||
const stream = fs.createReadStream(data.Source);
|
||||
@@ -598,9 +592,8 @@ ipcMain.on(Constants.IPC_Extract_Release, (event, data) => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Get_Config, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
helpers
|
||||
.getConfig(dataDirectory, data.Version, data.StorageType)
|
||||
.getConfig(data.Version, data.StorageType)
|
||||
.then((data) => {
|
||||
if (data.Code === 0) {
|
||||
standardIPCReply(event, Constants.IPC_Get_Config_Reply, {
|
||||
@@ -616,9 +609,8 @@ ipcMain.on(Constants.IPC_Get_Config, (event, data) => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Get_Config_Template, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
helpers
|
||||
.getConfigTemplate(dataDirectory, data.Version, data.StorageType)
|
||||
.getConfigTemplate(data.Version, data.StorageType)
|
||||
.then((data) => {
|
||||
standardIPCReply(event, Constants.IPC_Get_Config_Template_Reply, {
|
||||
Template: data,
|
||||
@@ -630,37 +622,35 @@ ipcMain.on(Constants.IPC_Get_Config_Template, (event, data) => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Get_Platform, (event) => {
|
||||
let platform = os.platform();
|
||||
const platform = os.platform();
|
||||
if (platform === 'linux') {
|
||||
const scriptFile = path.join(os.tmpdir(), 'repertory_detect_linux.sh');
|
||||
fs.writeFileSync(scriptFile, detectScript);
|
||||
helpers
|
||||
.executeScript(scriptFile)
|
||||
.then(data => {
|
||||
platform = data.replace(/(\r\n|\n|\r)/gm,"");
|
||||
event.sender.send(Constants.IPC_Get_Platform_Reply, {
|
||||
OSPlatform: os.platform(),
|
||||
AppPlatform: data.replace(/(\r\n|\n|\r)/gm,""),
|
||||
Platform: platform,
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
event.sender.send(Constants.IPC_Get_Platform_Reply, {
|
||||
OSPlatform: os.platform(),
|
||||
AppPlatform: platform,
|
||||
Platform: platform,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
event.sender.send(Constants.IPC_Get_Platform_Reply, {
|
||||
OSPlatform: os.platform(),
|
||||
AppPlatform: platform,
|
||||
Platform: platform,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Get_State, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data);
|
||||
helpers.mkDirByPathSync(dataDirectory);
|
||||
const configFile = path.join(dataDirectory, 'settings.json');
|
||||
ipcMain.on(Constants.IPC_Get_State, event => {
|
||||
helpers.mkDirByPathSync(helpers.getDataDirectory());
|
||||
const configFile = path.join(helpers.getDataDirectory(), 'settings.json');
|
||||
if (fs.existsSync(configFile)) {
|
||||
event.sender.send(Constants.IPC_Get_State_Reply, {
|
||||
data: JSON.parse(fs.readFileSync(configFile, 'utf8')),
|
||||
@@ -815,14 +805,12 @@ ipcMain.on(Constants.IPC_Install_Upgrade, (event, data) => {
|
||||
|
||||
ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => {
|
||||
expectedUnmount[data.StorageType] = false;
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
|
||||
if (mountedLocations.indexOf(data.Location) !== -1) {
|
||||
console.log(data.StorageType + ' already mounted: ' + data.Location);
|
||||
} else {
|
||||
mountedLocations.push(data.Location);
|
||||
mountedData[data.Location] = {
|
||||
DataDirectory: dataDirectory,
|
||||
Version: data.Version,
|
||||
StorageType: data.StorageType,
|
||||
};
|
||||
@@ -839,7 +827,7 @@ ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => {
|
||||
}, error || Error(data.StorageType + ' Unmounted'));
|
||||
};
|
||||
helpers
|
||||
.executeMount(dataDirectory, data.Version, data.StorageType, data.Location, data.NoConsoleSupported, (error, pid) => {
|
||||
.executeMount(data.Version, data.StorageType, data.Location, data.NoConsoleSupported, (error, pid) => {
|
||||
errorHandler(pid, error);
|
||||
})
|
||||
.then(() => {
|
||||
@@ -854,18 +842,16 @@ ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Save_State, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
helpers.mkDirByPathSync(dataDirectory);
|
||||
const configFile = path.join(dataDirectory, 'settings.json');
|
||||
helpers.mkDirByPathSync(helpers.getDataDirectory());
|
||||
const configFile = path.join(helpers.getDataDirectory(), 'settings.json');
|
||||
fs.writeFileSync(configFile, JSON.stringify(data.State), 'utf8');
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Set_Config_Values, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
const setConfigValue = (i) => {
|
||||
if (i < data.Items.length) {
|
||||
helpers
|
||||
.setConfigValue(data.Items[i].Name, data.Items[i].Value, dataDirectory, data.StorageType, data.Version)
|
||||
.setConfigValue(data.Items[i].Name, data.Items[i].Value, data.StorageType, data.Version)
|
||||
.then(() => {
|
||||
setConfigValue(++i);
|
||||
})
|
||||
@@ -895,10 +881,9 @@ ipcMain.on(Constants.IPC_Show_Window + '_sync', event => {
|
||||
ipcMain.on(Constants.IPC_Unmount_Drive, (event, data) => {
|
||||
clearManualMountDetection(data.StorageType);
|
||||
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
expectedUnmount[data.StorageType] = true;
|
||||
helpers
|
||||
.stopMountProcess(dataDirectory, data.Version, data.StorageType)
|
||||
.stopMountProcess(data.Version, data.StorageType)
|
||||
.then((result)=> {
|
||||
console.log(result);
|
||||
})
|
||||
|
||||
70
src/App.js
70
src/App.js
@@ -42,14 +42,12 @@ class App extends IPCContainer {
|
||||
this.setRequestHandler(Constants.IPC_Install_Dependency_Reply, this.onInstallDependencyReply);
|
||||
this.setRequestHandler(Constants.IPC_Install_Upgrade_Reply, this.onInstallUpgradeReply);
|
||||
|
||||
this.sendRequest(Constants.IPC_Get_State, Constants.DATA_LOCATIONS[this.props.platform]);
|
||||
this.sendRequest(Constants.IPC_Get_State);
|
||||
Scheduler.scheduleJob('23 11 * * *', this.updateCheckScheduledJob);
|
||||
}
|
||||
|
||||
state = {
|
||||
AllowDownload: false,
|
||||
AutoMountProcessed: false,
|
||||
ConfigStorageType: null,
|
||||
DisplayError: false,
|
||||
DisplayMainContent: false,
|
||||
Error: null,
|
||||
@@ -106,7 +104,6 @@ class App extends IPCContainer {
|
||||
|
||||
this.sendRequest(Constants.IPC_Check_Installed, {
|
||||
Dependencies: dependencies,
|
||||
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
||||
Version: selectedVersion,
|
||||
});
|
||||
}
|
||||
@@ -137,7 +134,6 @@ class App extends IPCContainer {
|
||||
if (data.Success) {
|
||||
const selectedVersion = this.getSelectedVersion();
|
||||
this.sendRequest(Constants.IPC_Extract_Release, {
|
||||
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
||||
Source: data.Destination,
|
||||
Version: selectedVersion,
|
||||
});
|
||||
@@ -157,7 +153,7 @@ class App extends IPCContainer {
|
||||
};
|
||||
|
||||
grabReleases = () => {
|
||||
if (this.props.platform !== 'unknown') {
|
||||
if (this.props.Platform !== 'unknown') {
|
||||
this.sendRequest(Constants.IPC_Grab_Releases);
|
||||
this.sendRequest(Constants.IPC_Grab_UI_Releases);
|
||||
}
|
||||
@@ -187,18 +183,6 @@ class App extends IPCContainer {
|
||||
});
|
||||
};
|
||||
|
||||
handleConfigClicked = (storageType) => {
|
||||
this.setState({
|
||||
ConfigStorageType: storageType,
|
||||
})
|
||||
};
|
||||
|
||||
handleConfigClosed = () => {
|
||||
this.setState({
|
||||
ConfigStorageType: null,
|
||||
});
|
||||
};
|
||||
|
||||
handleDependencyDownload = (url) => {
|
||||
this.setState({
|
||||
DownloadActive: true,
|
||||
@@ -206,7 +190,6 @@ class App extends IPCContainer {
|
||||
DownloadName: this.extractFileNameFromURL(url),
|
||||
}, ()=> {
|
||||
this.sendRequest(Constants.IPC_Download_File, {
|
||||
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
||||
Filename: this.state.DownloadName,
|
||||
URL: url,
|
||||
});
|
||||
@@ -246,7 +229,6 @@ class App extends IPCContainer {
|
||||
DownloadName: fileName,
|
||||
}, () => {
|
||||
this.sendRequest(Constants.IPC_Download_File, {
|
||||
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
||||
Filename: this.state.DownloadName,
|
||||
URL: this.state.LocationsLookup[selectedVersion].urls[0],
|
||||
});
|
||||
@@ -261,8 +243,7 @@ class App extends IPCContainer {
|
||||
}, ()=> {
|
||||
const url = this.state.UpgradeData.urls[0];
|
||||
this.sendRequest(Constants.IPC_Download_File, {
|
||||
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
||||
Filename: this.props.platform === 'win32' ? 'upgrade.exe' : this.extractFileNameFromURL(url),
|
||||
Filename: this.props.Platform === 'win32' ? 'upgrade.exe' : this.extractFileNameFromURL(url),
|
||||
URL: url,
|
||||
});
|
||||
});
|
||||
@@ -295,8 +276,8 @@ class App extends IPCContainer {
|
||||
|
||||
installUpgrade = data => {
|
||||
if (data.Success) {
|
||||
const sha256 = this.state.LocationsLookup[this.props.platform][this.state.VersionLookup[this.props.platform][0]].sha256;
|
||||
const signature = this.state.LocationsLookup[this.props.platform][this.state.VersionLookup[this.props.platform][0]].sig;
|
||||
const sha256 = this.state.LocationsLookup[this.props.Platform][this.state.VersionLookup[this.props.Platform][0]].sha256;
|
||||
const signature = this.state.LocationsLookup[this.props.Platform][this.state.VersionLookup[this.props.Platform][0]].sig;
|
||||
this.sendRequest(Constants.IPC_Install_Upgrade, {
|
||||
Sha256: sha256,
|
||||
Signature: signature,
|
||||
@@ -313,10 +294,6 @@ class App extends IPCContainer {
|
||||
}
|
||||
};
|
||||
|
||||
notifyAutoMountProcessed = () => {
|
||||
this.setState({AutoMountProcessed: true});
|
||||
};
|
||||
|
||||
onCheckInstalledReply = (event, arg) => {
|
||||
const action = () => {
|
||||
const installedVersion = arg.data.Success && arg.data.Exists ? arg.data.Version : 'none';
|
||||
@@ -431,13 +408,13 @@ class App extends IPCContainer {
|
||||
.get(Constants.RELEASES_URL)
|
||||
.then(response => {
|
||||
const versionLookup = {
|
||||
Alpha: response.data.Versions.Alpha[this.props.platform],
|
||||
Beta: response.data.Versions.Beta[this.props.platform],
|
||||
RC: response.data.Versions.RC[this.props.platform],
|
||||
Release: response.data.Versions.Release[this.props.platform],
|
||||
Alpha: response.data.Versions.Alpha[this.props.Platform],
|
||||
Beta: response.data.Versions.Beta[this.props.Platform],
|
||||
RC: response.data.Versions.RC[this.props.Platform],
|
||||
Release: response.data.Versions.Release[this.props.Platform],
|
||||
};
|
||||
const locationsLookup = {
|
||||
...response.data.Locations[this.props.platform],
|
||||
...response.data.Locations[this.props.Platform],
|
||||
};
|
||||
|
||||
window.localStorage.setItem('releases', JSON.stringify({
|
||||
@@ -466,13 +443,13 @@ class App extends IPCContainer {
|
||||
.then(response => {
|
||||
const data = response.data;
|
||||
if (data.Versions &&
|
||||
data.Versions[this.props.platform] &&
|
||||
(data.Versions[this.props.platform].length > 0) &&
|
||||
(data.Versions[this.props.platform][0] !== this.props.version)) {
|
||||
data.Versions[this.props.Platform] &&
|
||||
(data.Versions[this.props.Platform].length > 0) &&
|
||||
(data.Versions[this.props.Platform][0] !== this.props.version)) {
|
||||
this.setState({
|
||||
UpgradeAvailable: true,
|
||||
UpgradeDismissed: false,
|
||||
UpgradeData: data.Locations[this.props.platform][data.Versions[this.props.platform][0]],
|
||||
UpgradeData: data.Locations[this.props.Platform][data.Versions[this.props.Platform][0]],
|
||||
});
|
||||
}
|
||||
}).catch(() => {
|
||||
@@ -529,7 +506,6 @@ class App extends IPCContainer {
|
||||
}
|
||||
|
||||
this.sendRequest(Constants.IPC_Save_State, {
|
||||
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
||||
State: state
|
||||
});
|
||||
};
|
||||
@@ -546,7 +522,7 @@ class App extends IPCContainer {
|
||||
};
|
||||
|
||||
updateCheckScheduledJob = () => {
|
||||
if (this.props.platform !== 'unknown') {
|
||||
if (this.props.Platform !== 'unknown') {
|
||||
this.grabReleases();
|
||||
}
|
||||
};
|
||||
@@ -593,7 +569,7 @@ class App extends IPCContainer {
|
||||
this.state.LocationsLookup[selectedVersion].no_console_supported;
|
||||
|
||||
const showConfig = !missingDependencies &&
|
||||
this.state.ConfigStorageType &&
|
||||
this.props.DisplayConfiguration &&
|
||||
allowConfig;
|
||||
|
||||
const showUpgrade = this.state.UpgradeAvailable &&
|
||||
@@ -621,10 +597,7 @@ class App extends IPCContainer {
|
||||
if (showConfig) {
|
||||
configDisplay = (
|
||||
<Modal>
|
||||
<Configuration closed={this.handleConfigClosed}
|
||||
directory={Constants.DATA_LOCATIONS[this.props.platform]}
|
||||
errorHandler={this.setErrorState}
|
||||
storageType={this.state.ConfigStorageType}
|
||||
<Configuration errorHandler={this.setErrorState}
|
||||
version={selectedVersion} />
|
||||
</Modal>
|
||||
);
|
||||
@@ -695,14 +668,9 @@ class App extends IPCContainer {
|
||||
allowSiaPrime={allowSiaPrime}
|
||||
noConsoleSupported={noConsoleSupported}
|
||||
autoMountChanged={this.handleAutoMountChanged}
|
||||
autoMountProcessed={this.notifyAutoMountProcessed}
|
||||
autoRestartChanged={this.handleAutoRestartChanged}
|
||||
changed={this.handleMountLocationChanged}
|
||||
configClicked={this.handleConfigClicked}
|
||||
directory={Constants.DATA_LOCATIONS[this.props.platform]}
|
||||
errorHandler={this.setErrorState}
|
||||
platform={this.props.platform}
|
||||
processAutoMount={!this.state.AutoMountProcessed}
|
||||
version={this.state.InstalledVersion}/>
|
||||
</div>
|
||||
));
|
||||
@@ -752,7 +720,9 @@ class App extends IPCContainer {
|
||||
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
MountsBusy: state.mounts.MountsBusy
|
||||
DisplayConfiguration: state.mounts.DisplayConfiguration,
|
||||
MountsBusy: state.mounts.MountsBusy,
|
||||
Platform: state.common.Platform,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React from 'react';
|
||||
import './MountItem.css';
|
||||
import {connect} from "react-redux";
|
||||
import DropDown from '../UI/DropDown/DropDown';
|
||||
import Button from '../UI/Button/Button';
|
||||
import Loader from 'react-loader-spinner';
|
||||
@@ -8,7 +9,13 @@ import Grid from '../UI/Grid/Grid';
|
||||
import configureImage from '../../assets/images/configure.png';
|
||||
import RootElem from '../../hoc/RootElem/RootElem';
|
||||
|
||||
export default props => {
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
Platform: state.common.Platform,
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(props => {
|
||||
let configButton = null;
|
||||
let secondRow = 6;
|
||||
if (props.allowConfig) {
|
||||
@@ -27,7 +34,7 @@ export default props => {
|
||||
|
||||
let inputColumnSpan;
|
||||
let inputControls = null;
|
||||
if (props.platform === 'win32') {
|
||||
if (props.Platform === 'win32') {
|
||||
inputColumnSpan = 20;
|
||||
inputControls = <DropDown changed={props.changed}
|
||||
colSpan={inputColumnSpan}
|
||||
@@ -121,4 +128,4 @@ export default props => {
|
||||
{autoRestartControl}
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
});
|
||||
@@ -1,10 +1,12 @@
|
||||
import React from 'react';
|
||||
import './Configuration.css';
|
||||
import {connect} from 'react-redux';
|
||||
import Box from '../../components/UI/Box/Box';
|
||||
import Button from '../../components/UI/Button/Button';
|
||||
import ConfigurationItem from '../../components/ConfigurationItem/ConfigurationItem';
|
||||
import Modal from '../../components/UI/Modal/Modal';
|
||||
import IPCContainer from '../IPCContainer/IPCContainer';
|
||||
import {displayConfiguration} from "../../redux/actions/mount_actions";
|
||||
|
||||
const Constants = require('../../constants');
|
||||
|
||||
@@ -16,8 +18,7 @@ class Configuration extends IPCContainer {
|
||||
this.setRequestHandler(Constants.IPC_Set_Config_Values_Reply, this.onSetConfigValuesReply);
|
||||
|
||||
this.sendRequest(Constants.IPC_Get_Config_Template, {
|
||||
Directory: this.props.directory,
|
||||
StorageType: this.props.storageType,
|
||||
StorageType: this.props.DisplayConfiguration,
|
||||
Version: this.props.version,
|
||||
});
|
||||
}
|
||||
@@ -67,7 +68,7 @@ class Configuration extends IPCContainer {
|
||||
ChangedObjectLookup: changedObjectLookup,
|
||||
});
|
||||
} else {
|
||||
this.props.closed();
|
||||
this.props.hideConfiguration();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -151,20 +152,19 @@ class Configuration extends IPCContainer {
|
||||
Template: arg.data.Template,
|
||||
}, ()=> {
|
||||
this.sendRequest(Constants.IPC_Get_Config, {
|
||||
Directory: this.props.directory,
|
||||
StorageType: this.props.storageType,
|
||||
StorageType: this.props.DisplayConfiguration,
|
||||
Version: this.props.version,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this.props.errorHandler(arg.data.Error, () => {
|
||||
this.props.closed();
|
||||
this.props.hideConfiguration();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
onSetConfigValuesReply = () => {
|
||||
this.props.closed();
|
||||
this.props.hideConfiguration();
|
||||
};
|
||||
|
||||
saveAndClose = () => {
|
||||
@@ -191,9 +191,8 @@ class Configuration extends IPCContainer {
|
||||
}
|
||||
|
||||
this.sendRequest(Constants.IPC_Set_Config_Values, {
|
||||
Directory: this.props.directory,
|
||||
Items: changedItems,
|
||||
StorageType: this.props.storageType,
|
||||
StorageType: this.props.DisplayConfiguration,
|
||||
Version: this.props.version,
|
||||
});
|
||||
});
|
||||
@@ -209,7 +208,7 @@ class Configuration extends IPCContainer {
|
||||
<table width='100%'><tbody>
|
||||
<tr>
|
||||
<td align='center' width='50%'><Button clicked={this.saveAndClose} disabled={this.state.Saving}>Yes</Button></td>
|
||||
<td align='center' width='50%'><Button clicked={this.props.closed} disabled={this.state.Saving}>No</Button></td>
|
||||
<td align='center' width='50%'><Button clicked={this.props.hideConfiguration} disabled={this.state.Saving}>No</Button></td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
</Box>
|
||||
@@ -264,7 +263,7 @@ class Configuration extends IPCContainer {
|
||||
<b style={{cursor: 'pointer'}}
|
||||
onClick={this.checkSaveRequired}>X</b>
|
||||
</div>
|
||||
<h1 style={{width: '100%', textAlign: 'center'}}>{this.props.storageType + ' Configuration'}</h1>
|
||||
<h1 style={{width: '100%', textAlign: 'center'}}>{this.props.DisplayConfiguration + ' Configuration'}</h1>
|
||||
<div style={{overflowY: 'auto', height: '90%'}}>
|
||||
{objectItems}
|
||||
{(configurationItems.length > 0) ? <h1>Settings</h1> : null}
|
||||
@@ -276,4 +275,16 @@ class Configuration extends IPCContainer {
|
||||
}
|
||||
}
|
||||
|
||||
export default Configuration;
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
DisplayConfiguration: state.mounts.DisplayConfiguration,
|
||||
}
|
||||
};
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
hideConfiguration: () => dispatch(displayConfiguration(null)),
|
||||
}
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(Configuration);
|
||||
@@ -6,7 +6,7 @@ import './MountItems.css';
|
||||
import Modal from '../../components/UI/Modal/Modal';
|
||||
import MountItem from '../../components/MountItem/MountItem';
|
||||
import IPCContainer from '../IPCContainer/IPCContainer';
|
||||
import {setBusy} from '../../redux/actions/mount_actions';
|
||||
import {displayConfiguration, setAutoMountProcessed, setBusy} from '../../redux/actions/mount_actions';
|
||||
|
||||
const Constants = require('../../constants');
|
||||
|
||||
@@ -71,7 +71,6 @@ class MountItems extends IPCContainer {
|
||||
if (!this.state.DisplayRetry) {
|
||||
this.props.setMountsBusy(true);
|
||||
this.sendRequest(Constants.IPC_Detect_Mounts, {
|
||||
Directory: this.props.directory,
|
||||
Version: this.props.version,
|
||||
});
|
||||
}
|
||||
@@ -88,7 +87,7 @@ class MountItems extends IPCContainer {
|
||||
};
|
||||
|
||||
handleMountLocationChanged = (storageType, value) => {
|
||||
if (this.props.platform === 'win32') {
|
||||
if (this.props.Platform === 'win32') {
|
||||
this.props.changed(storageType, this.state[storageType].DriveLetters[value]);
|
||||
} else {
|
||||
this.props.changed(storageType, value);
|
||||
@@ -102,13 +101,12 @@ class MountItems extends IPCContainer {
|
||||
let allowAction = true;
|
||||
if (mount) {
|
||||
let result = this.sendSyncRequest(Constants.IPC_Check_Daemon_Version, {
|
||||
Directory: this.props.directory,
|
||||
StorageType: storageType,
|
||||
Version: this.props.version
|
||||
}).data;
|
||||
if (result.Success) {
|
||||
if (result.Valid) {
|
||||
if (this.props.platform !== 'win32') {
|
||||
if (this.props.Platform !== 'win32') {
|
||||
result = this.sendSyncRequest(Constants.IPC_Check_Mount_Location, {
|
||||
Location: location,
|
||||
});
|
||||
@@ -140,7 +138,6 @@ class MountItems extends IPCContainer {
|
||||
}, () => {
|
||||
if (mount) {
|
||||
this.sendRequest(Constants.IPC_Mount_Drive, {
|
||||
Directory: this.props.directory,
|
||||
Location: location,
|
||||
NoConsoleSupported: this.props.noConsoleSupported,
|
||||
StorageType: storageType,
|
||||
@@ -148,7 +145,6 @@ class MountItems extends IPCContainer {
|
||||
});
|
||||
} else {
|
||||
this.sendRequest(Constants.IPC_Unmount_Drive, {
|
||||
Directory: this.props.directory,
|
||||
Location: location,
|
||||
StorageType: storageType,
|
||||
Version: this.props.version,
|
||||
@@ -179,7 +175,7 @@ class MountItems extends IPCContainer {
|
||||
const providerLower = provider.toLowerCase();
|
||||
let location = data.Locations[provider];
|
||||
if (location.length === 0) {
|
||||
location = (this.props.platform === 'win32') ?
|
||||
location = (this.props.Platform === 'win32') ?
|
||||
this.props[providerLower].MountLocation || data.DriveLetters[provider][0] :
|
||||
this.props[providerLower].MountLocation;
|
||||
}
|
||||
@@ -256,8 +252,9 @@ class MountItems extends IPCContainer {
|
||||
};
|
||||
|
||||
performAutoMount = ()=> {
|
||||
if (this.props.processAutoMount) {
|
||||
this.props.autoMountProcessed();
|
||||
if (!this.props.AutoMountProcessed) {
|
||||
this.props.setAutoMountProcessed(true);
|
||||
|
||||
const processAutoMount = (provider) => {
|
||||
const providerLower = provider.toLowerCase();
|
||||
if (this.props[providerLower].AutoMount &&
|
||||
@@ -313,12 +310,11 @@ class MountItems extends IPCContainer {
|
||||
browseClicked={this.handleBrowseLocation}
|
||||
changed={(e) => this.handleMountLocationChanged(provider, e.target.value)}
|
||||
clicked={this.handleMountUnMount}
|
||||
configClicked={()=>this.props.configClicked(provider)}
|
||||
configClicked={()=>this.props.displayConfiguration(provider)}
|
||||
items={this.state[provider].DriveLetters}
|
||||
key={'mi_' + items.length}
|
||||
location={this.props[providerLower].MountLocation}
|
||||
mounted={this.state[provider].Mounted}
|
||||
platform={this.props.platform}
|
||||
title={provider} />
|
||||
));
|
||||
if (items.length !== this.state.length) {
|
||||
@@ -335,10 +331,19 @@ class MountItems extends IPCContainer {
|
||||
}
|
||||
}
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
setMountsBusy: busy => dispatch(setBusy(busy))
|
||||
AutoMountProcessed: state.mounts.AutoMountProcessed,
|
||||
Platform: state.common.Platform,
|
||||
}
|
||||
};
|
||||
|
||||
export default connect(null, mapDispatchToProps)(MountItems);
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
displayConfiguration: storageType => dispatch(displayConfiguration(storageType)),
|
||||
setAutoMountProcessed: processed => dispatch(setAutoMountProcessed(processed)),
|
||||
setMountsBusy: busy => dispatch(setBusy(busy)),
|
||||
}
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(MountItems);
|
||||
@@ -8,6 +8,20 @@ const spawn = require('child_process').spawn;
|
||||
const Constants = require('./constants');
|
||||
const RandomString = require('randomstring');
|
||||
|
||||
const _getDataDirectory = () => {
|
||||
return _resolvePath(Constants.DATA_LOCATIONS[os.platform()]);
|
||||
};
|
||||
|
||||
const _resolvePath = str => {
|
||||
if (os.platform() === 'win32') {
|
||||
return str.replace(/%([^%]+)%/g, (_, n) => {
|
||||
return process.env[n];
|
||||
});
|
||||
} else {
|
||||
return str.replace('~', os.homedir());
|
||||
}
|
||||
};
|
||||
|
||||
const tryParse = (j, def) => {
|
||||
try {
|
||||
return JSON.parse(j);
|
||||
@@ -16,7 +30,7 @@ const tryParse = (j, def) => {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.checkDaemonVersion = (directory, version, storageType) => {
|
||||
module.exports.checkDaemonVersion = (version, storageType) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const processOptions = {
|
||||
detached: true,
|
||||
@@ -24,7 +38,7 @@ module.exports.checkDaemonVersion = (directory, version, storageType) => {
|
||||
windowsHide: true,
|
||||
};
|
||||
|
||||
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const args = [];
|
||||
args.push('-cv');
|
||||
if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
|
||||
@@ -67,7 +81,7 @@ module.exports.createSignatureFiles = (signature, publicKey) => {
|
||||
};
|
||||
};
|
||||
|
||||
module.exports.detectRepertoryMounts = (directory, version) => {
|
||||
module.exports.detectRepertoryMounts = version => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const processOptions = {
|
||||
detached: true,
|
||||
@@ -75,7 +89,7 @@ module.exports.detectRepertoryMounts = (directory, version) => {
|
||||
windowsHide: true,
|
||||
};
|
||||
|
||||
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const args = [];
|
||||
args.push('-status');
|
||||
|
||||
@@ -240,7 +254,7 @@ module.exports.executeScript = script => {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.executeMount = (directory, version, storageType, location, noConsoleSupported, exitCallback) => {
|
||||
module.exports.executeMount = (version, storageType, location, noConsoleSupported, exitCallback) => {
|
||||
return new Promise((resolve) => {
|
||||
const processOptions = {
|
||||
detached: false,
|
||||
@@ -248,7 +262,7 @@ module.exports.executeMount = (directory, version, storageType, location, noCons
|
||||
stdio: 'ignore',
|
||||
};
|
||||
|
||||
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const args = [];
|
||||
if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
|
||||
args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]);
|
||||
@@ -285,7 +299,7 @@ module.exports.executeMount = (directory, version, storageType, location, noCons
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getConfig = (directory, version, storageType) => {
|
||||
module.exports.getConfig = (version, storageType) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const processOptions = {
|
||||
detached: true,
|
||||
@@ -293,7 +307,7 @@ module.exports.getConfig = (directory, version, storageType) => {
|
||||
windowsHide: true,
|
||||
};
|
||||
|
||||
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const args = [];
|
||||
args.push('-dc');
|
||||
if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
|
||||
@@ -331,7 +345,7 @@ module.exports.getConfig = (directory, version, storageType) => {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getConfigTemplate = (directory, version, storageType) => {
|
||||
module.exports.getConfigTemplate = (version, storageType) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const processOptions = {
|
||||
detached: true,
|
||||
@@ -339,7 +353,7 @@ module.exports.getConfigTemplate = (directory, version, storageType) => {
|
||||
windowsHide: true,
|
||||
};
|
||||
|
||||
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const args = [];
|
||||
args.push('-gt');
|
||||
if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
|
||||
@@ -364,6 +378,8 @@ module.exports.getConfigTemplate = (directory, version, storageType) => {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getDataDirectory = _getDataDirectory;
|
||||
|
||||
module.exports.getMissingDependencies = dependencies => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!dependencies) {
|
||||
@@ -482,17 +498,9 @@ module.exports.removeDirectoryRecursively = (p) => {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.resolvePath = str => {
|
||||
if (os.platform() === 'win32') {
|
||||
return str.replace(/%([^%]+)%/g, (_, n) => {
|
||||
return process.env[n];
|
||||
});
|
||||
} else {
|
||||
return str.replace('~', os.homedir());
|
||||
}
|
||||
};
|
||||
module.exports.resolvePath = _resolvePath;
|
||||
|
||||
module.exports.setConfigValue = (name, value, directory, storageType, version) => {
|
||||
module.exports.setConfigValue = (name, value, storageType, version) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const processOptions = {
|
||||
detached: true,
|
||||
@@ -500,7 +508,7 @@ module.exports.setConfigValue = (name, value, directory, storageType, version) =
|
||||
windowsHide: true,
|
||||
};
|
||||
|
||||
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const args = [];
|
||||
args.push('-set');
|
||||
args.push(name);
|
||||
@@ -523,7 +531,7 @@ module.exports.setConfigValue = (name, value, directory, storageType, version) =
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.stopMountProcess = (directory, version, storageType) => {
|
||||
module.exports.stopMountProcess = (version, storageType) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const processOptions = {
|
||||
detached: os.platform() === 'darwin',
|
||||
@@ -531,7 +539,7 @@ module.exports.stopMountProcess = (directory, version, storageType) => {
|
||||
windowsHide: true,
|
||||
};
|
||||
|
||||
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const args = ['-unmount'];
|
||||
if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
|
||||
args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]);
|
||||
@@ -555,14 +563,14 @@ module.exports.stopMountProcess = (directory, version, storageType) => {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.stopMountProcessSync = (directory, version, storageType) => {
|
||||
module.exports.stopMountProcessSync = (version, storageType) => {
|
||||
const processOptions = {
|
||||
detached: true,
|
||||
shell: os.platform() !== 'darwin',
|
||||
windowsHide: true,
|
||||
};
|
||||
|
||||
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const args = ['-unmount'];
|
||||
if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
|
||||
args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]);
|
||||
|
||||
12
src/index.js
12
src/index.js
@@ -3,27 +3,27 @@ import ReactDOM from 'react-dom';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
import createAppStore from './redux/store/createAppStore';
|
||||
import * as serviceWorker from './serviceWorker';
|
||||
import packageJson from '../package.json';
|
||||
import {Provider} from 'react-redux';
|
||||
import * as serviceWorker from './serviceWorker';
|
||||
|
||||
const Constants = require('./constants');
|
||||
|
||||
const store = createAppStore({});
|
||||
|
||||
if (!process.versions.hasOwnProperty('electron')) {
|
||||
const ipcRenderer = ((window && window.require) ? window.require('electron').ipcRenderer : null);
|
||||
if (ipcRenderer) {
|
||||
ipcRenderer.on(Constants.IPC_Get_Platform_Reply, (event, arg) => {
|
||||
if (arg.OSPlatform === 'linux') {
|
||||
if (arg.Platform === 'linux') {
|
||||
const root = document.documentElement;
|
||||
root.style.setProperty('--default_font_size', '15px');
|
||||
}
|
||||
|
||||
const store = createAppStore(arg.Platform, arg.AppPlatform);
|
||||
ReactDOM.render((
|
||||
<Provider store={store}>
|
||||
<App platform={arg.Platform} version={packageJson.version}/>
|
||||
</Provider>), document.getElementById('root'));
|
||||
<App version={packageJson.version}/>
|
||||
</Provider>
|
||||
), document.getElementById('root'));
|
||||
serviceWorker.unregister();
|
||||
});
|
||||
ipcRenderer.send(Constants.IPC_Get_Platform);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import {createAction} from "redux-starter-kit";
|
||||
import {createAction} from 'redux-starter-kit';
|
||||
|
||||
export const displayConfiguration = createAction('mounts/displayConfiguration');
|
||||
export const setAutoMountProcessed = createAction('mounts/setAutoMountProcessed');
|
||||
export const setBusy = createAction('mounts/setBusy');
|
||||
@@ -1,9 +1,17 @@
|
||||
import {createReducer} from 'redux-starter-kit';
|
||||
import {setBusy} from '../actions/mount_actions';
|
||||
import {displayConfiguration, setAutoMountProcessed, setBusy} from '../actions/mount_actions';
|
||||
|
||||
export const mountReducer = createReducer({
|
||||
AutoMountProcessed: false,
|
||||
DisplayConfiguration: null,
|
||||
MountsBusy: false,
|
||||
}, {
|
||||
[displayConfiguration]: (state, action) => {
|
||||
return {...state, DisplayConfiguration: action.payload};
|
||||
},
|
||||
[setAutoMountProcessed]: (state, action) => {
|
||||
return {...state, AutoMountProcessed: action.payload};
|
||||
},
|
||||
[setBusy]: (state, action) => {
|
||||
return {...state, MountsBusy: action.payload};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
import { configureStore, getDefaultMiddleware } from 'redux-starter-kit';
|
||||
import {configureStore, createReducer, getDefaultMiddleware} from 'redux-starter-kit';
|
||||
import {mountReducer} from '../reducers/mount_reducer';
|
||||
|
||||
export default function createAppStore(preloadedState) {
|
||||
export default function createAppStore(platform, appPlatform) {
|
||||
const createCommonReducer = () => {
|
||||
return createReducer({
|
||||
AppPlatform: appPlatform,
|
||||
Platform: platform,
|
||||
}, {});
|
||||
};
|
||||
|
||||
const reducer = {
|
||||
common: createCommonReducer(platform, appPlatform),
|
||||
mounts: mountReducer,
|
||||
};
|
||||
|
||||
@@ -11,7 +19,6 @@ export default function createAppStore(preloadedState) {
|
||||
return configureStore({
|
||||
reducer,
|
||||
middleware,
|
||||
devTools: process.env.NODE_ENV !== 'production',
|
||||
preloadedState
|
||||
devTools: process.env.NODE_ENV !== 'production'
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user