Refactoring
This commit is contained in:
@@ -1,20 +1,15 @@
|
||||
import React from 'react';
|
||||
import {Component} from 'react';
|
||||
import Box from '../../components/UI/Box/Box';
|
||||
import Button from '../../components/UI/Button/Button';
|
||||
import CSSModules from 'react-css-modules';
|
||||
import styles from './MountItems.css';
|
||||
import Modal from '../../components/UI/Modal/Modal';
|
||||
import MountItem from '../../components/MountItem/MountItem';
|
||||
import IPCContainer from '../IPCContainer/IPCContainer';
|
||||
|
||||
const Constants = require('../../constants');
|
||||
|
||||
let ipcRenderer = null;
|
||||
if (!process.versions.hasOwnProperty('electron')) {
|
||||
ipcRenderer = ((window && window.require) ? window.require('electron').ipcRenderer : null);
|
||||
}
|
||||
|
||||
class MountItems extends Component {
|
||||
class MountItems extends IPCContainer {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
@@ -26,13 +21,11 @@ class MountItems extends Component {
|
||||
};
|
||||
}
|
||||
|
||||
if (ipcRenderer) {
|
||||
ipcRenderer.on(Constants.IPC_Detect_Mounts_Reply, this.onDetectMountsReply);
|
||||
ipcRenderer.on(Constants.IPC_Mount_Drive_Reply, this.onMountDriveReply);
|
||||
ipcRenderer.on(Constants.IPC_Unmount_Drive_Reply, this.onUnmountDriveReply);
|
||||
this.setRequestHandler(Constants.IPC_Detect_Mounts_Reply, this.onDetectMountsReply);
|
||||
this.setRequestHandler(Constants.IPC_Mount_Drive_Reply, this.onMountDriveReply);
|
||||
this.setRequestHandler(Constants.IPC_Unmount_Drive_Reply, this.onUnmountDriveReply);
|
||||
|
||||
this.detectMounts();
|
||||
}
|
||||
this.detectMounts();
|
||||
}
|
||||
|
||||
retryIntervals = {};
|
||||
@@ -58,24 +51,20 @@ class MountItems extends Component {
|
||||
}
|
||||
};
|
||||
|
||||
componentWillUnmount = () => {
|
||||
componentWillUnmount() {
|
||||
for (const storageType in this.state.RetryItems) {
|
||||
if (this.state.RetryItems.hasOwnProperty(storageType)) {
|
||||
this.cancelRetryMount(storageType);
|
||||
}
|
||||
}
|
||||
|
||||
if (ipcRenderer) {
|
||||
ipcRenderer.removeListener(Constants.IPC_Detect_Mounts_Reply, this.onDetectMountsReply);
|
||||
ipcRenderer.removeListener(Constants.IPC_Mount_Drive_Reply, this.onMountDriveReply);
|
||||
ipcRenderer.removeListener(Constants.IPC_Unmount_Drive_Reply, this.onUnmountDriveReply);
|
||||
}
|
||||
super.componentWillUnmount();
|
||||
};
|
||||
|
||||
detectMounts = ()=> {
|
||||
if (!this.state.DisplayRetry) {
|
||||
this.props.mountsBusy(true);
|
||||
ipcRenderer.send(Constants.IPC_Detect_Mounts, {
|
||||
this.sendRequest(Constants.IPC_Detect_Mounts, {
|
||||
Directory: this.props.directory,
|
||||
Version: this.props.version,
|
||||
});
|
||||
@@ -83,7 +72,7 @@ class MountItems extends Component {
|
||||
};
|
||||
|
||||
handleBrowseLocation = (storageType, location) => {
|
||||
location = ipcRenderer.sendSync(Constants.IPC_Browse_Directory, {
|
||||
location = this.sendSyncRequest(Constants.IPC_Browse_Directory, {
|
||||
Title: storageType + ' Mount Location',
|
||||
Location: location,
|
||||
});
|
||||
@@ -103,10 +92,10 @@ class MountItems extends Component {
|
||||
handleMountUnMount = (storageType, mount, location) => {
|
||||
if (!location || (location.trim().length === 0)) {
|
||||
this.props.errorHandler('Mount location is not set');
|
||||
} else if (ipcRenderer) {
|
||||
} else {
|
||||
let allowAction = true;
|
||||
if (mount && (this.props.platform !== 'win32')) {
|
||||
const result = ipcRenderer.sendSync(Constants.IPC_Check_Mount_Location, {
|
||||
const result = this.sendSyncRequest(Constants.IPC_Check_Mount_Location, {
|
||||
Location: location,
|
||||
});
|
||||
if (!result.Success) {
|
||||
@@ -127,7 +116,7 @@ class MountItems extends Component {
|
||||
[storageType]: storageState,
|
||||
}, () => {
|
||||
if (mount) {
|
||||
ipcRenderer.send(Constants.IPC_Mount_Drive, {
|
||||
this.sendRequest(Constants.IPC_Mount_Drive, {
|
||||
Directory: this.props.directory,
|
||||
Location: location,
|
||||
NoConsoleSupported: this.props.noConsoleSupported,
|
||||
@@ -135,7 +124,7 @@ class MountItems extends Component {
|
||||
Version: this.props.version,
|
||||
});
|
||||
} else {
|
||||
ipcRenderer.send(Constants.IPC_Unmount_Drive, {
|
||||
this.sendRequest(Constants.IPC_Unmount_Drive, {
|
||||
Directory: this.props.directory,
|
||||
Location: location,
|
||||
StorageType: storageType,
|
||||
|
||||
Reference in New Issue
Block a user