Refactoring
This commit is contained in:
@@ -21,6 +21,16 @@ const Host = ({ allowDelete, editHost, host_list, host_data, onChange, onDelete
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getHostDisplay = () => {
|
||||||
|
return (
|
||||||
|
host_data.HostNameOrIp +
|
||||||
|
((host_data.Protocol === 'http' && host_data.ApiPort === 80) ||
|
||||||
|
(host_data.Protocol === 'https' && host_data.ApiPort === 443)
|
||||||
|
? ''
|
||||||
|
: ':' + host_data.ApiPort)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const premium = host_data.AuthURL && host_data.AuthUser;
|
const premium = host_data.AuthURL && host_data.AuthUser;
|
||||||
return (
|
return (
|
||||||
<div style={{ display: 'flex', flexDirection: 'row' }}>
|
<div style={{ display: 'flex', flexDirection: 'row' }}>
|
||||||
@@ -46,23 +56,10 @@ const Host = ({ allowDelete, editHost, host_list, host_data, onChange, onDelete
|
|||||||
) : null}
|
) : null}
|
||||||
{premium ? (
|
{premium ? (
|
||||||
<p>
|
<p>
|
||||||
<b>
|
<b>{'(premium) ' + getHostDisplay()}</b>
|
||||||
{'(premium) ' +
|
|
||||||
host_data.HostNameOrIp +
|
|
||||||
((host_data.Protocol === 'http' && host_data.ApiPort === 80) ||
|
|
||||||
(host_data.Protocol === 'https' && host_data.ApiPort === 443)
|
|
||||||
? ''
|
|
||||||
: ':' + host_data.ApiPort)}
|
|
||||||
</b>
|
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<p>
|
<p>{getHostDisplay()}</p>
|
||||||
{host_data.HostNameOrIp +
|
|
||||||
((host_data.Protocol === 'http' && host_data.ApiPort === 80) ||
|
|
||||||
(host_data.Protocol === 'https' && host_data.ApiPort === 443)
|
|
||||||
? ''
|
|
||||||
: ':' + host_data.ApiPort)}
|
|
||||||
</p>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -78,4 +75,3 @@ Host.propTypes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default connect(null, mapDispatchToProps)(Host);
|
export default connect(null, mapDispatchToProps)(Host);
|
||||||
// export default Host;
|
|
||||||
|
|||||||
@@ -67,11 +67,9 @@ class MountItems extends IPCContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
for (const provider in this.state.RetryItems) {
|
Object.keys(this.state.RetryItems).forEach((provider) => {
|
||||||
if (Object.prototype.hasOwnProperty.call(this.state.RetryItems, provider)) {
|
|
||||||
this.cancelRetryMount(provider);
|
this.cancelRetryMount(provider);
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
this.props.resetMountsState();
|
this.props.resetMountsState();
|
||||||
this.activeDetections = [];
|
this.activeDetections = [];
|
||||||
@@ -91,8 +89,7 @@ class MountItems extends IPCContainer {
|
|||||||
|
|
||||||
detectMounts = () => {
|
detectMounts = () => {
|
||||||
if (!this.state.DisplayRetry) {
|
if (!this.state.DisplayRetry) {
|
||||||
const providerList = this.getProviderList();
|
this.getProviderList().forEach((provider) => {
|
||||||
providerList.forEach((provider) => {
|
|
||||||
this.detectMount(provider);
|
this.detectMount(provider);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -121,7 +118,7 @@ class MountItems extends IPCContainer {
|
|||||||
() => {
|
() => {
|
||||||
this.sendRequest(Constants.IPC_Show_Window);
|
this.sendRequest(Constants.IPC_Show_Window);
|
||||||
this.retryIntervals[provider] = setInterval(() => {
|
this.retryIntervals[provider] = setInterval(() => {
|
||||||
let retryItems = {
|
const retryItems = {
|
||||||
...this.state.RetryItems,
|
...this.state.RetryItems,
|
||||||
};
|
};
|
||||||
const retrySeconds = retryItems[provider].RetrySeconds - 1;
|
const retrySeconds = retryItems[provider].RetrySeconds - 1;
|
||||||
@@ -174,6 +171,9 @@ class MountItems extends IPCContainer {
|
|||||||
S3: s3,
|
S3: s3,
|
||||||
Version: this.props.InstalledVersion,
|
Version: this.props.InstalledVersion,
|
||||||
}).data;
|
}).data;
|
||||||
|
const displayRetry = (msg) => {
|
||||||
|
this.displayRetryMount(provider, remote, s3, location, msg);
|
||||||
|
};
|
||||||
if (result.Success) {
|
if (result.Success) {
|
||||||
if (result.Valid) {
|
if (result.Valid) {
|
||||||
if (this.props.Platform !== 'win32') {
|
if (this.props.Platform !== 'win32') {
|
||||||
@@ -191,32 +191,16 @@ class MountItems extends IPCContainer {
|
|||||||
result.Code === new Uint32Array([-1])[0] ||
|
result.Code === new Uint32Array([-1])[0] ||
|
||||||
result.Code === new Uint8Array([-1])[0]
|
result.Code === new Uint8Array([-1])[0]
|
||||||
) {
|
) {
|
||||||
this.displayRetryMount(
|
displayRetry('Failed to connect to ' + provider + ' daemon');
|
||||||
provider,
|
|
||||||
remote,
|
|
||||||
s3,
|
|
||||||
location,
|
|
||||||
'Failed to connect to ' + provider + ' daemon'
|
|
||||||
);
|
|
||||||
} else if (
|
} else if (
|
||||||
result.Code === new Uint32Array([-3])[0] ||
|
result.Code === new Uint32Array([-3])[0] ||
|
||||||
result.Code === new Uint8Array([-3])[0]
|
result.Code === new Uint8Array([-3])[0]
|
||||||
) {
|
) {
|
||||||
this.displayRetryMount(
|
displayRetry(
|
||||||
provider,
|
|
||||||
remote,
|
|
||||||
s3,
|
|
||||||
location,
|
|
||||||
'Incompatible ' + provider + ' daemon. Please upgrade ' + provider + '.'
|
'Incompatible ' + provider + ' daemon. Please upgrade ' + provider + '.'
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.displayRetryMount(
|
displayRetry('Version check failed: ' + result.Error);
|
||||||
provider,
|
|
||||||
remote,
|
|
||||||
s3,
|
|
||||||
location,
|
|
||||||
'Version check failed: ' + result.Error
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -226,13 +210,7 @@ class MountItems extends IPCContainer {
|
|||||||
'Failed to launch repertory. Please install Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019.'
|
'Failed to launch repertory. Please install Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019.'
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.displayRetryMount(
|
displayRetry('Version check failed: ' + result.Error);
|
||||||
provider,
|
|
||||||
remote,
|
|
||||||
s3,
|
|
||||||
location,
|
|
||||||
'Version check failed: ' + result.Error
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -241,23 +219,13 @@ class MountItems extends IPCContainer {
|
|||||||
this.addMountsBusy(provider);
|
this.addMountsBusy(provider);
|
||||||
this.props.setAllowMount(provider, false);
|
this.props.setAllowMount(provider, false);
|
||||||
|
|
||||||
if (mount) {
|
this.sendRequest(mount ? Constants.IPC_Mount_Drive : Constants.IPC_Unmount_Drive, {
|
||||||
this.sendRequest(Constants.IPC_Mount_Drive, {
|
|
||||||
Location: location,
|
Location: location,
|
||||||
Provider: provider,
|
Provider: provider,
|
||||||
Remote: remote,
|
Remote: remote,
|
||||||
S3: s3,
|
S3: s3,
|
||||||
Version: this.props.InstalledVersion,
|
Version: this.props.InstalledVersion,
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
this.sendRequest(Constants.IPC_Unmount_Drive, {
|
|
||||||
Location: location,
|
|
||||||
Provider: provider,
|
|
||||||
Remote: remote,
|
|
||||||
S3: s3,
|
|
||||||
Version: this.props.InstalledVersion,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -285,11 +253,9 @@ class MountItems extends IPCContainer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
hasActiveMount = () => {
|
hasActiveMount = () => {
|
||||||
for (const provider of Object.keys(this.props.MountState)) {
|
return !!Object.keys(this.props.MountState).find((provider) => {
|
||||||
if (this.props.MountState[provider].Mounted) return true;
|
return this.props.MountState[provider].Mounted;
|
||||||
}
|
});
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
onDetectMountReply = (_, arg) => {
|
onDetectMountReply = (_, arg) => {
|
||||||
@@ -384,10 +350,9 @@ class MountItems extends IPCContainer {
|
|||||||
render() {
|
render() {
|
||||||
let retryDisplay;
|
let retryDisplay;
|
||||||
if (this.state.DisplayRetry) {
|
if (this.state.DisplayRetry) {
|
||||||
let retryList = [];
|
const retryList = [];
|
||||||
let retryCount = 0;
|
let retryCount = 0;
|
||||||
for (const provider in this.state.RetryItems) {
|
Object.keys(this.state.RetryItems).forEach((provider) => {
|
||||||
if (Object.prototype.hasOwnProperty.call(this.state.RetryItems, provider)) {
|
|
||||||
if (this.state.RetryItems[provider].RetryMessage) {
|
if (this.state.RetryItems[provider].RetryMessage) {
|
||||||
retryList.push(
|
retryList.push(
|
||||||
<p key={'rl_' + retryList.length}>{this.state.RetryItems[provider].RetryMessage}</p>
|
<p key={'rl_' + retryList.length}>{this.state.RetryItems[provider].RetryMessage}</p>
|
||||||
@@ -402,14 +367,10 @@ class MountItems extends IPCContainer {
|
|||||||
);
|
);
|
||||||
if (++retryCount < Object.keys(this.state.RetryItems).length) {
|
if (++retryCount < Object.keys(this.state.RetryItems).length) {
|
||||||
retryList.push(
|
retryList.push(
|
||||||
<div
|
<div style={{ paddingTop: 'var(--default_spacing)' }} key={'rl_' + retryList.length} />
|
||||||
style={{ paddingTop: 'var(--default_spacing)' }}
|
|
||||||
key={'rl_' + retryList.length}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
retryDisplay = (
|
retryDisplay = (
|
||||||
<Modal>
|
<Modal>
|
||||||
@@ -428,7 +389,7 @@ class MountItems extends IPCContainer {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let footerItems = [];
|
const footerItems = [];
|
||||||
if (this.props.remoteSupported || this.props.s3Supported) {
|
if (this.props.remoteSupported || this.props.s3Supported) {
|
||||||
footerItems.push(
|
footerItems.push(
|
||||||
<AddMount
|
<AddMount
|
||||||
@@ -441,7 +402,7 @@ class MountItems extends IPCContainer {
|
|||||||
footerItems.push(<div key={'hi_' + footerItems.length} style={{ height: '27px' }} />);
|
footerItems.push(<div key={'hi_' + footerItems.length} style={{ height: '27px' }} />);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mountItems = [];
|
const mountItems = [];
|
||||||
const addMountItem = (provider, remote, s3) => {
|
const addMountItem = (provider, remote, s3) => {
|
||||||
if (mountItems.length > 0) {
|
if (mountItems.length > 0) {
|
||||||
mountItems.push(
|
mountItems.push(
|
||||||
@@ -466,20 +427,14 @@ class MountItems extends IPCContainer {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const provider of this.getProviderList(true)) {
|
this.getProviderList(true).forEach((provider) => addMountItem(provider));
|
||||||
addMountItem(provider);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.props.remoteSupported) {
|
if (this.props.remoteSupported) {
|
||||||
for (const provider of this.props.RemoteMounts) {
|
this.props.RemoteMounts.forEach((provider) => addMountItem(provider, true));
|
||||||
addMountItem(provider, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.props.s3Supported) {
|
if (this.props.s3Supported) {
|
||||||
for (const provider of this.props.S3Mounts) {
|
this.props.S3Mounts.forEach((provider) => addMountItem(provider, false, true));
|
||||||
addMountItem(provider, false, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user