Save on idle callback update documents folder

This commit is contained in:
Dustin Brett
2022-07-16 22:48:56 -07:00
parent fbc3e3f616
commit 58a26fdb63
2 changed files with 20 additions and 6 deletions

View File

@@ -8,7 +8,7 @@ import { useFileSystem } from "contexts/fileSystem";
import { useProcesses } from "contexts/process";
import type { CommandInterface } from "emulators";
import type { DosInstance } from "emulators-ui/dist/types/js-dos";
import { basename, extname, join } from "path";
import { basename, dirname, extname, join } from "path";
import { useCallback, useEffect, useState } from "react";
import { SAVE_PATH } from "utils/constants";
import { bufferToUrl, cleanUpBufferUrl } from "utils/functions";
@@ -53,7 +53,10 @@ const useDosCI = (
async (bundleUrl: string, closeInstance = false) => {
const saveName = `${basename(bundleUrl)}${saveExtension}`;
if (!(await exists(SAVE_PATH))) await mkdirRecursive(SAVE_PATH);
if (!(await exists(SAVE_PATH))) {
await mkdirRecursive(SAVE_PATH);
updateFolder(dirname(SAVE_PATH));
}
if (
typeof dosCI[bundleUrl] !== "undefined" &&
@@ -124,7 +127,11 @@ const useDosCI = (
}
return () => {
if (url && closing) setTimeout(() => closeBundle(url, closing), 1000);
if (url && closing) {
window.requestIdleCallback(() => closeBundle(url, closing), {
timeout: 1000,
});
}
};
}, [closeBundle, closing, dosCI, dosInstance, loadBundle, process, url]);

View File

@@ -17,7 +17,7 @@ import useTitle from "components/system/Window/useTitle";
import { useFileSystem } from "contexts/fileSystem";
import { fs9pV4ToV3 } from "contexts/fileSystem/functions";
import { useProcesses } from "contexts/process";
import { basename, extname, join } from "path";
import { basename, dirname, extname, join } from "path";
import { useCallback, useEffect, useRef, useState } from "react";
import { SAVE_PATH } from "utils/constants";
import { bufferToUrl, cleanUpBufferUrl, loadFiles } from "utils/functions";
@@ -53,7 +53,10 @@ const useV86 = (
async (diskImageUrl: string): Promise<void> => {
const saveName = `${basename(diskImageUrl)}${saveExtension}`;
if (!(await exists(SAVE_PATH))) await mkdirRecursive(SAVE_PATH);
if (!(await exists(SAVE_PATH))) {
await mkdirRecursive(SAVE_PATH);
updateFolder(dirname(SAVE_PATH));
}
if (
await writeFile(
@@ -164,7 +167,11 @@ const useV86 = (
return () => {
if (url && closing && !shutdown.current) {
shutdown.current = true;
if (emulator[url]) setTimeout(() => closeDiskImage(url), 1000);
if (emulator[url]) {
window.requestIdleCallback(() => closeDiskImage(url), {
timeout: 1000,
});
}
}
};
}, [closeDiskImage, closing, emulator, loadDiskImage, loading, process, url]);