diff --git a/components/apps/JSDOS/useDosCI.ts b/components/apps/JSDOS/useDosCI.ts index 6bcc6a0a..88fe8623 100644 --- a/components/apps/JSDOS/useDosCI.ts +++ b/components/apps/JSDOS/useDosCI.ts @@ -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]); diff --git a/components/apps/V86/useV86.ts b/components/apps/V86/useV86.ts index 034f39f4..b99fafca 100644 --- a/components/apps/V86/useV86.ts +++ b/components/apps/V86/useV86.ts @@ -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 => { 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]);