Skip to content
Permalink
Browse files

Merge fe9edf2 into 184fdc8

  • Loading branch information...
daniloprates committed Sep 11, 2019
2 parents 184fdc8 + fe9edf2 commit 912862c7811aa2c11893248ac129d7470f9e6b5e
@@ -18,6 +18,7 @@ Changelog

### Fixes

- Implemented disk space check error handling ([PR 1562](https://github.com/input-output-hk/daedalus/pull/1562))
- Fixed UI issues across different app themes ([PR 1547](https://github.com/input-output-hk/daedalus/pull/1547))
- Fixed minor UI issues on the "Delegation center" screen and "Delegation setup" wizard ([PR 1545](https://github.com/input-output-hk/daedalus/pull/1545))
- Fixed "White" theme styles ([PR 1532](https://github.com/input-output-hk/daedalus/pull/1532))
@@ -9,8 +9,8 @@ const { isTest, isProduction, isBlankScreenFixActive } = environment;
// Make sure Daedalus is started with required configuration
const { LAUNCHER_CONFIG } = process.env;
const isStartedByLauncher = !!LAUNCHER_CONFIG;
const isWindows = process.platform === 'win32';
if (!isStartedByLauncher) {
const isWindows = process.platform === 'win32';
const dialogTitle = 'Daedalus improperly started!';
let dialogMessage;
if (isProduction) {
@@ -93,6 +93,7 @@ export const pubLogsFolderPath = path.join(appLogsFolderPath, 'pub');
export const appFolderPath = launcherConfig.workingDir;
export const { nodeDbPath } = launcherConfig;
export const stateDirectoryPath = launcherConfig.statePath;
export const stateDrive = isWindows ? stateDirectoryPath.slice(0, 2) : '/';
export const ALLOWED_LOGS = [
'Daedalus.json',
'System-info.json',
@@ -3,7 +3,6 @@ import { BrowserWindow } from 'electron';
import checkDiskSpace from 'check-disk-space';
import prettysize from 'prettysize';
import { getDiskSpaceStatusChannel } from '../ipc/get-disk-space-status';
import { environment } from '../environment';
import { Logger } from './logging';
import {
DISK_SPACE_REQUIRED,
@@ -12,71 +11,89 @@ import {
DISK_SPACE_CHECK_MEDIUM_INTERVAL,
DISK_SPACE_CHECK_SHORT_INTERVAL,
DISK_SPACE_RECOMMENDED_PERCENTAGE,
stateDrive,
} from '../config';

export const handleDiskSpace = (
mainWindow: BrowserWindow,
onCheckDiskSpace?: Function
) => {
const path = environment.isWindows ? 'C:' : '/';
let diskSpaceCheckInterval;
let diskSpaceCheckIntervalLength = DISK_SPACE_CHECK_LONG_INTERVAL; // Default check interval
let isNotEnoughDiskSpace = false; // Default check state

const handleCheckDiskSpace = async (forceDiskSpaceRequired?: number) => {
const diskSpaceRequired = forceDiskSpaceRequired || DISK_SPACE_REQUIRED;
const {
free: diskSpaceAvailable,
size: diskTotalSpace,
} = await checkDiskSpace(path);
const diskSpaceMissing = Math.max(
diskSpaceRequired - diskSpaceAvailable,
0
);
const diskSpaceRecommended =
(diskTotalSpace * DISK_SPACE_RECOMMENDED_PERCENTAGE) / 100;
const diskSpaceRequiredMargin =
diskSpaceRequired -
(diskSpaceRequired * DISK_SPACE_REQUIRED_MARGIN_PERCENTAGE) / 100;
try {
const {
free: diskSpaceAvailable,
size: diskTotalSpace,
} = await checkDiskSpace(stateDrive);
const diskSpaceMissing = Math.max(
diskSpaceRequired - diskSpaceAvailable,
0
);
const diskSpaceRecommended =
(diskTotalSpace * DISK_SPACE_RECOMMENDED_PERCENTAGE) / 100;
const diskSpaceRequiredMargin =
diskSpaceRequired -
(diskSpaceRequired * DISK_SPACE_REQUIRED_MARGIN_PERCENTAGE) / 100;

if (diskSpaceAvailable <= diskSpaceRequiredMargin) {
if (!isNotEnoughDiskSpace) {
// State change: transitioning from enough to not-enough disk space
setDiskSpaceIntervalChecking(DISK_SPACE_CHECK_SHORT_INTERVAL);
isNotEnoughDiskSpace = true;
if (diskSpaceAvailable <= diskSpaceRequiredMargin) {
if (!isNotEnoughDiskSpace) {
// State change: transitioning from enough to not-enough disk space
setDiskSpaceIntervalChecking(DISK_SPACE_CHECK_SHORT_INTERVAL);
isNotEnoughDiskSpace = true;
}
} else if (diskSpaceAvailable >= diskSpaceRequired) {
const newDiskSpaceCheckIntervalLength =
diskSpaceAvailable >= diskSpaceRequired * 2
? DISK_SPACE_CHECK_LONG_INTERVAL
: DISK_SPACE_CHECK_MEDIUM_INTERVAL;
if (isNotEnoughDiskSpace) {
// State change: transitioning from not-enough to enough disk space
setDiskSpaceIntervalChecking(newDiskSpaceCheckIntervalLength);
isNotEnoughDiskSpace = false;
} else if (
newDiskSpaceCheckIntervalLength !== diskSpaceCheckIntervalLength
) {
// Interval change: transitioning from medium to long interval (or vice versa)
// This is a special case in which we adjust the disk space check polling interval:
// - more than 2x of available space than required: LONG interval
// - less than 2x of available space than required: MEDIUM interval
setDiskSpaceIntervalChecking(newDiskSpaceCheckIntervalLength);
}
}
} else if (diskSpaceAvailable >= diskSpaceRequired) {
const newDiskSpaceCheckIntervalLength =
diskSpaceAvailable >= diskSpaceRequired * 2
? DISK_SPACE_CHECK_LONG_INTERVAL
: DISK_SPACE_CHECK_MEDIUM_INTERVAL;
if (isNotEnoughDiskSpace) {
// State change: transitioning from not-enough to enough disk space
setDiskSpaceIntervalChecking(newDiskSpaceCheckIntervalLength);
isNotEnoughDiskSpace = false;
} else if (
newDiskSpaceCheckIntervalLength !== diskSpaceCheckIntervalLength
) {
// Interval change: transitioning from medium to long interval (or vice versa)
// This is a special case in which we adjust the disk space check polling interval:
// - more than 2x of available space than required: LONG interval
// - less than 2x of available space than required: MEDIUM interval
setDiskSpaceIntervalChecking(newDiskSpaceCheckIntervalLength);

const response = {
isNotEnoughDiskSpace,
diskSpaceRequired: prettysize(diskSpaceRequired),
diskSpaceMissing: prettysize(diskSpaceMissing),
diskSpaceRecommended: prettysize(diskSpaceRecommended),
diskSpaceAvailable: prettysize(diskSpaceAvailable),
};
if (isNotEnoughDiskSpace)
Logger.info('Not enough disk space', { response });
if (typeof onCheckDiskSpace === 'function') onCheckDiskSpace(response);
getDiskSpaceStatusChannel.send(response, mainWindow.webContents);
return response;
} catch (error) {
// Remove diskSpaceCheckInterval if set
if (diskSpaceCheckInterval) {
clearInterval(diskSpaceCheckInterval);
// Reset to default check interval
diskSpaceCheckIntervalLength = DISK_SPACE_CHECK_LONG_INTERVAL;
}
const response = {
isNotEnoughDiskSpace: false,
diskSpaceRequired: '',
diskSpaceMissing: '',
diskSpaceRecommended: '',
diskSpaceAvailable: '',
};
getDiskSpaceStatusChannel.send(response, mainWindow.webContents);
return response;
}

const response = {
isNotEnoughDiskSpace,
diskSpaceRequired: prettysize(diskSpaceRequired),
diskSpaceMissing: prettysize(diskSpaceMissing),
diskSpaceRecommended: prettysize(diskSpaceRecommended),
diskSpaceAvailable: prettysize(diskSpaceAvailable),
};
if (isNotEnoughDiskSpace)
Logger.info('Not enough disk space', { response });
if (typeof onCheckDiskSpace === 'function') onCheckDiskSpace(response);
getDiskSpaceStatusChannel.send(response, mainWindow.webContents);
return response;
};

const setDiskSpaceIntervalChecking = interval => {
@@ -59,6 +59,16 @@ const messages = defineMessages({
defaultMessage: '!!!Available disk space',
description: 'Available disk space',
},
unknownDiskSpace: {
id: 'daedalus.diagnostics.dialog.unknownDiskSpace',
defaultMessage: '!!!Unknown',
description: 'Unknown amount of disk space',
},
unknownDiskSpaceSupportUrl: {
id: 'daedalus.diagnostics.dialog.unknownDiskSpaceSupportUrl',
defaultMessage: '!!!https://iohk.zendesk.com/hc',
description: '"Support" link URL while disk space is unknown',
},
coreInfo: {
id: 'daedalus.diagnostics.dialog.coreInfo',
defaultMessage: '!!!CORE INFO',
@@ -568,6 +578,10 @@ export default class DaedalusDiagnostics extends Component<Props, State> {
styles[`locale-${currentLocale}`],
]);

const unknownDiskSpaceSupportUrl = intl.formatMessage(
messages.unknownDiskSpaceSupportUrl
);

return (
<div className={styles.component}>
<DialogCloseButton
@@ -605,7 +619,22 @@ export default class DaedalusDiagnostics extends Component<Props, State> {
</tr>
<tr>
<th>{intl.formatMessage(messages.availableDiskSpace)}:</th>
<td>{availableDiskSpace}</td>
<td>
{availableDiskSpace || (
<button
className={styles.unknownDiskSpaceBtn}
onClick={() =>
onOpenExternalLink(unknownDiskSpaceSupportUrl)
}
>
{intl.formatMessage(messages.unknownDiskSpace)}
<SVGInline
svg={externalLinkIcon}
className={styles.externalLinkIcon}
/>
</button>
)}
</td>
</tr>
</tbody>
<tbody>
@@ -291,7 +291,8 @@
padding-top: 0;
}

&.realTimeStatusBtn {
&.realTimeStatusBtn,
&.unknownDiskSpaceBtn {
@include link(--theme-network-window-white-color);
background: transparent !important;
border-bottom: none;
@@ -94,6 +94,8 @@
"daedalus.diagnostics.dialog.system.info": "SYSTEM INFO",
"daedalus.diagnostics.dialog.systemTimeCorrect": "System Time Correct",
"daedalus.diagnostics.dialog.systemTimeIgnored": "System Time Ignored",
"daedalus.diagnostics.dialog.unknownDiskSpace": "!!!Unknown",
"daedalus.diagnostics.dialog.unknownDiskSpaceSupportUrl": "!!!https://iohk.zendesk.com/hc",
"environment.apiName.cardano": "!!!Cardano",
"environment.currency.ada": "!!!Ada",
"global.assuranceLevel.normal": "!!!Normal",

0 comments on commit 912862c

Please sign in to comment.
You can’t perform that action at this time.