<commit_before>// @flow
import { BrowserWindow } from 'electron';
import checkDiskSpace from 'check-disk-space';
import { DISK_SPACE_STATUS_CHANNEL } from '../../common/ipc/check-disk-space';
import environment from '../../common/environment';

const DISK_SPACE_REQUIRED = 2000000000; // 2Gb
const DISK_SPACE_REQUIRED_MARGIN =
  DISK_SPACE_REQUIRED - (DISK_SPACE_REQUIRED * 10 / 100); // 2Gb - 10%
const DISK_SPACE_CHECK_LONG_INTERVAL = 600000; // 10 minutes
const DISK_SPACE_CHECK_SHORT_INTERVAL = 10000; // 10 seconds

const path = environment.isWindows() ? 'c:' : '/';
let diskSpaceCheckInterval;
let notEnoughSpace = false;

const handleCheckDiskSpace = async () => {

  const { free: diskSpaceAvailable } = await checkDiskSpace(path);
  const diskSpaceMissing = DISK_SPACE_REQUIRED - diskSpaceAvailable;

  if (diskSpaceAvailable <= DISK_SPACE_REQUIRED_MARGIN) {
    if (!notEnoughSpace) {
      setDiskSpaceIntervalChecking(DISK_SPACE_CHECK_SHORT_INTERVAL);
    }
    notEnoughSpace = true;
  } else if (diskSpaceAvailable >= DISK_SPACE_REQUIRED) {
    if (notEnoughSpace) {
      setDiskSpaceIntervalChecking(DISK_SPACE_CHECK_LONG_INTERVAL);
    }
    notEnoughSpace = false;
  }

  return {
    diskSpaceAvailable,
    diskSpaceRequired: DISK_SPACE_REQUIRED,
    notEnoughSpace,
    diskSpaceMissing,
  };
};

const setDiskSpaceIntervalChecking = (interval) => {
  clearInterval(diskSpaceCheckInterval);
  diskSpaceCheckInterval =
    setInterval(() => handleCheckDiskSpace(), interval);
};
setDiskSpaceIntervalChecking(DISK_SPACE_CHECK_LONG_INTERVAL);

export const onNoDiskSpaceError = async (mainWindow: BrowserWindow) => {
  const response = await handleCheckDiskSpace();
  mainWindow.webContents.send(DISK_SPACE_STATUS_CHANNEL, response);
};<commit_msg>[DDW-256] Trigger checking on Daedalus start<commit_after>// @flow
import { BrowserWindow } from 'electron';
import checkDiskSpace from 'check-disk-space';
import { DISK_SPACE_STATUS_CHANNEL } from '../../common/ipc/check-disk-space';
import environment from '../../common/environment';

const DISK_SPACE_REQUIRED = 2000000000; // 2Gb
const DISK_SPACE_REQUIRED_MARGIN =
  DISK_SPACE_REQUIRED - (DISK_SPACE_REQUIRED * 10 / 100); // 2Gb - 10%
const DISK_SPACE_CHECK_LONG_INTERVAL = 600000; // 10 minutes
const DISK_SPACE_CHECK_SHORT_INTERVAL = 10000; // 10 seconds

const path = environment.isWindows() ? 'c:' : '/';
let diskSpaceCheckInterval;
let notEnoughSpace = false;

const handleCheckDiskSpace = async () => {

  const { free: diskSpaceAvailable } = await checkDiskSpace(path);
  const diskSpaceMissing = DISK_SPACE_REQUIRED - diskSpaceAvailable;

  if (diskSpaceAvailable <= DISK_SPACE_REQUIRED_MARGIN) {
    if (!notEnoughSpace) {
      setDiskSpaceIntervalChecking(DISK_SPACE_CHECK_SHORT_INTERVAL);
    }
    notEnoughSpace = true;
  } else if (diskSpaceAvailable >= DISK_SPACE_REQUIRED) {
    if (notEnoughSpace) {
      setDiskSpaceIntervalChecking(DISK_SPACE_CHECK_LONG_INTERVAL);
    }
    notEnoughSpace = false;
  }

  return {
    diskSpaceAvailable,
    diskSpaceRequired: DISK_SPACE_REQUIRED,
    notEnoughSpace,
    diskSpaceMissing,
  };
};

const setDiskSpaceIntervalChecking = (interval) => {
  clearInterval(diskSpaceCheckInterval);
  diskSpaceCheckInterval =
    setInterval(() => handleCheckDiskSpace(), interval);
};
setDiskSpaceIntervalChecking(DISK_SPACE_CHECK_LONG_INTERVAL);
handleCheckDiskSpace();

export const onNoDiskSpaceError = async (mainWindow: BrowserWindow) => {
  const response = await handleCheckDiskSpace();
  mainWindow.webContents.send(DISK_SPACE_STATUS_CHANNEL, response);
};
{'fraction_non_alphanumeric': 0.10259269584611096, 'fraction_numerical': 0.019793699470309453, 'mean_word_length': 5.2076124567474045, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2960522', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1150, 'n_words': 216}