diff --git a/components/apps/FileExplorer/SearchBar.tsx b/components/apps/FileExplorer/SearchBar.tsx index 428ad22a..87ebcdd4 100644 --- a/components/apps/FileExplorer/SearchBar.tsx +++ b/components/apps/FileExplorer/SearchBar.tsx @@ -1,7 +1,6 @@ import type { FSModule } from "browserfs/dist/node/core/FS"; import { Search } from "components/apps/FileExplorer/NavigationIcons"; import StyledSearch from "components/apps/FileExplorer/StyledSearch"; -import { TEXT_EDITORS } from "components/system/Files/FileEntry/extensions"; import { getInfoWithExtension } from "components/system/Files/FileEntry/functions"; import type { FileInfo } from "components/system/Files/FileEntry/useFileInfo"; import { useFileSystem } from "contexts/fileSystem"; @@ -14,6 +13,7 @@ import { ICON_CACHE, ICON_CACHE_EXTENSION, SHORTCUT_EXTENSION, + TEXT_EDITORS, YT_ICON_CACHE, } from "utils/constants"; import { diff --git a/components/system/Files/FileEntry/constants.ts b/components/system/Files/FileEntry/constants.ts new file mode 100644 index 00000000..1d8ccf68 --- /dev/null +++ b/components/system/Files/FileEntry/constants.ts @@ -0,0 +1,70 @@ +export const EXTRACTABLE_EXTENSIONS = new Set([ + ".001", + ".7z", + ".ace", + ".apk", + ".appx", + ".arj", + ".bz2", + ".bzip2", + ".cab", + ".chm", + ".chw", + ".cpio", + ".deb", + ".dll", + ".dmg", + ".doc", + ".docx", + ".epub", + ".esd", + ".exe", + ".flv", + ".gz", + ".gzip", + ".hfs", + ".hxs", + ".img", + ".ipa", + ".jar", + ".lha", + ".lit", + ".lzh", + ".lzma", + ".mbr", + ".msi", + ".ntfs", + ".ods", + ".odt", + ".ova", + ".pages", + ".pkg", + ".ppt", + ".qcow", + ".qcow2", + ".r00", + ".rar", + ".rpm", + ".squashfs", + ".swf", + ".swm", + ".sys", + ".tar", + ".taz", + ".tgz", + ".txz", + ".udf", + ".vdi", + ".vhd", + ".vhdx", + ".vmdk", + ".wim", + ".xar", + ".xip", + ".xls", + ".xlsx", + ".xpi", + ".xz", + ".z", + ".zipx", +]); diff --git a/components/system/Files/FileEntry/extensions.ts b/components/system/Files/FileEntry/extensions.ts index b676cea8..edb0e7f4 100644 --- a/components/system/Files/FileEntry/extensions.ts +++ b/components/system/Files/FileEntry/extensions.ts @@ -1,5 +1,5 @@ import { emulatorCores } from "components/apps/Emulator/config"; -import { EDITABLE_IMAGE_FILE_EXTENSIONS } from "utils/constants"; +import { EDITABLE_IMAGE_FILE_EXTENSIONS, TEXT_EDITORS } from "utils/constants"; type Extension = { command?: string; @@ -8,8 +8,6 @@ type Extension = { type?: string; }; -export const TEXT_EDITORS = ["MonacoEditor", "Vim"]; - const types = { Application: { icon: "executable", diff --git a/components/system/Files/FileEntry/useFileContextMenu.ts b/components/system/Files/FileEntry/useFileContextMenu.ts index 201b7a14..6a45d1d0 100644 --- a/components/system/Files/FileEntry/useFileContextMenu.ts +++ b/components/system/Files/FileEntry/useFileContextMenu.ts @@ -1,6 +1,4 @@ -import extensions, { - TEXT_EDITORS, -} from "components/system/Files/FileEntry/extensions"; +import extensions from "components/system/Files/FileEntry/extensions"; import { getProcessByFileExtension } from "components/system/Files/FileEntry/functions"; import useFile from "components/system/Files/FileEntry/useFile"; import type { FocusEntryFunctions } from "components/system/Files/FileManager/useFocusableEntries"; @@ -23,7 +21,6 @@ import { CURSOR_FILE_EXTENSIONS, DESKTOP_PATH, EDITABLE_IMAGE_FILE_EXTENSIONS, - EXTRACTABLE_EXTENSIONS, IMAGE_FILE_EXTENSIONS, MENU_SEPERATOR, MOUNTABLE_EXTENSIONS, @@ -32,6 +29,7 @@ import { ROOT_SHORTCUT, SHORTCUT_EXTENSION, SPREADSHEET_FORMATS, + TEXT_EDITORS, UNSUPPORTED_BACKGROUND_EXTENSIONS, VIDEO_FILE_EXTENSIONS, } from "utils/constants"; @@ -94,7 +92,7 @@ const useFileContextMenu = ( const { contextMenu } = useMenu(); const { onContextMenuCapture, ...contextMenuHandlers } = useMemo( () => - contextMenu?.(() => { + contextMenu?.(async () => { const urlExtension = getExtension(url); const { process: extensionProcesses = [] } = urlExtension in extensions ? extensions[urlExtension] : {}; @@ -410,6 +408,10 @@ const useFileContextMenu = ( } } + const { EXTRACTABLE_EXTENSIONS } = await import( + "components/system/Files/FileEntry/constants" + ); + menuItems.unshift( { action: () => archiveFiles(absoluteEntries()), diff --git a/components/system/Files/FileManager/icons.ts b/components/system/Files/FileManager/icons.ts new file mode 100644 index 00000000..d10a66c6 --- /dev/null +++ b/components/system/Files/FileManager/icons.ts @@ -0,0 +1,2 @@ +export const UNKNOWN_ICON = + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAB0ElEQVR42u2ZVWLbQBiEp/K6DOpb+LF4ip47oCuULpAYH3uAlcbMNOZpm0lsizWz+/3CgEc9aiuFHz9/YYVIcjAAkODcYYDoTyPQHZse7m0E49tLkid/8rz4BuD7RgFIYpW+fvmMXStJEvz+/RuvXr1KG41mVhT5RiECRMUYsUuF0Nv18+fPcXp6ktbrjSzPhRBCDxxUpVKpG+Ls7DSt1eprhwjYWwAdJQD9EGftELV2iCiHCAQMAvT04sVznJ+fpdVqNcuj1hOBJj0wCvECFxcXaeWhIuEUYFADAGZCXF5dpg/3DxmA99YIZVmGRXr58lVqi1CMER8+fOh+pkUS5XIZd7d3ylEIViI5M7wCITqa1wOAtDVPKD1A45andC1ES/N6DZCuzKsIWZr3RoikMK4jZGleD2BsntDOA74tT0gIOZrXEfJmXiti24KleBi1M09SThBIU/P6mZiW5qEXMW3NUzuMGrc8NYRssSE0hFyZVxFyLVgdIcOW51oIWZqHfj9ga15+rOLb8lIRg47m9RoQ/R+eeb0GaGleR8i15XWEqL5VFIIJ87V5u70nvrm+AUF0/8nx4ZlxgOj+9KeTk+Oz8/rrYnIYBAoWeNSj9qwWS/T9vUU9j2EAAAAASUVORK5CYII="; diff --git a/components/system/Files/FileManager/useDraggableEntries.ts b/components/system/Files/FileManager/useDraggableEntries.ts index d436aa7b..c171a619 100644 --- a/components/system/Files/FileManager/useDraggableEntries.ts +++ b/components/system/Files/FileManager/useDraggableEntries.ts @@ -4,7 +4,7 @@ import { useSession } from "contexts/session"; import { join } from "path"; import { useCallback, useEffect, useRef, useState } from "react"; import type { Position } from "react-rnd"; -import { MILLISECONDS_IN_SECOND, UNKNOWN_ICON } from "utils/constants"; +import { MILLISECONDS_IN_SECOND } from "utils/constants"; import { getHtmlToImage, haltEvent, @@ -187,6 +187,10 @@ const useDraggableEntries = ( let newDragImage: string | undefined; try { + const { UNKNOWN_ICON } = await import( + "components/system/Files/FileManager/icons" + ); + newDragImage = await htmlToImage?.toPng(fileManagerRef.current, { filter: (element) => { return ( diff --git a/contexts/menu/useMenuContextState.ts b/contexts/menu/useMenuContextState.ts index 46430dc2..1cab08e0 100644 --- a/contexts/menu/useMenuContextState.ts +++ b/contexts/menu/useMenuContextState.ts @@ -43,7 +43,7 @@ export type ContextMenuCapture = { type MenuContextState = { contextMenu: ( - getItems: (event?: CaptureTriggerEvent) => MenuItem[] + getItems: (event?: CaptureTriggerEvent) => MenuItem[] | Promise ) => ContextMenuCapture; menu: MenuState; setMenu: React.Dispatch>; @@ -55,13 +55,15 @@ const useMenuContextState = (): MenuContextState => { const touchEvent = useRef(); const contextMenu = useCallback( ( - getItems: (event?: CaptureTriggerEvent) => MenuItem[] + getItems: ( + event?: CaptureTriggerEvent + ) => MenuItem[] | Promise ): ContextMenuCapture => { - const onContextMenuCapture = ( + const onContextMenuCapture = async ( event?: CaptureTriggerEvent, domRect?: DOMRect, options?: MenuOptions - ): void => { + ): Promise => { const { staticX, staticY } = options || {}; let x = 0; let y = 0; @@ -78,7 +80,7 @@ const useMenuContextState = (): MenuContextState => { y = inputY + height; } - const items = getItems(event); + const items = await getItems(event); setMenu({ items: items.length > 0 ? items : undefined, diff --git a/utils/constants.ts b/utils/constants.ts index b513e433..df7336d6 100644 --- a/utils/constants.ts +++ b/utils/constants.ts @@ -8,13 +8,6 @@ export const BASE_2D_CONTEXT_OPTIONS: CanvasRenderingContext2DSettings = { desynchronized: true, }; -export const IPFS_GATEWAY_URLS = [ - "https://.ipfs.cf-ipfs.com/", - "https://.ipfs.dweb.link/", - "https://cloudflare-ipfs.com/ipfs//", - "https://gateway.ipfs.io/ipfs//", -]; - export const IFRAME_CONFIG = { referrerPolicy: "no-referrer" as React.HTMLAttributeReferrerPolicy, sandbox: @@ -125,6 +118,8 @@ export const UNSUPPORTED_BACKGROUND_EXTENSIONS = new Set([ ".svg", ]); +export const TEXT_EDITORS = ["MonacoEditor", "Vim"]; + export const CURSOR_FILE_EXTENSIONS = new Set([".ani", ".cur"]); export const EDITABLE_IMAGE_FILE_EXTENSIONS = new Set([ @@ -153,77 +148,6 @@ export const MILLISECONDS_IN_MINUTE = 60000; export const MILLISECONDS_IN_DAY = 86400000; -export const EXTRACTABLE_EXTENSIONS = new Set([ - ".001", - ".7z", - ".ace", - ".apk", - ".appx", - ".arj", - ".bz2", - ".bzip2", - ".cab", - ".chm", - ".chw", - ".cpio", - ".deb", - ".dll", - ".dmg", - ".doc", - ".docx", - ".epub", - ".esd", - ".exe", - ".flv", - ".gz", - ".gzip", - ".hfs", - ".hxs", - ".img", - ".ipa", - ".jar", - ".lha", - ".lit", - ".lzh", - ".lzma", - ".mbr", - ".msi", - ".ntfs", - ".ods", - ".odt", - ".ova", - ".pages", - ".pkg", - ".ppt", - ".qcow", - ".qcow2", - ".r00", - ".rar", - ".rpm", - ".squashfs", - ".swf", - ".swm", - ".sys", - ".tar", - ".taz", - ".tgz", - ".txz", - ".udf", - ".vdi", - ".vhd", - ".vhdx", - ".vmdk", - ".wim", - ".xar", - ".xip", - ".xls", - ".xlsx", - ".xpi", - ".xz", - ".z", - ".zipx", -]); - export const MOUNTABLE_EXTENSIONS = new Set([".iso", ".jsdos", ".wsz", ".zip"]); export const SPREADSHEET_FORMATS = [ @@ -347,9 +271,6 @@ export const MOUNTED_FOLDER_ICON = `${ICON_PATH}/mounted.webp`; export const NEW_FOLDER_ICON = `${ICON_PATH}/new_folder.webp`; -export const UNKNOWN_ICON = - "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAB0ElEQVR42u2ZVWLbQBiEp/K6DOpb+LF4ip47oCuULpAYH3uAlcbMNOZpm0lsizWz+/3CgEc9aiuFHz9/YYVIcjAAkODcYYDoTyPQHZse7m0E49tLkid/8rz4BuD7RgFIYpW+fvmMXStJEvz+/RuvXr1KG41mVhT5RiECRMUYsUuF0Nv18+fPcXp6ktbrjSzPhRBCDxxUpVKpG+Ls7DSt1eprhwjYWwAdJQD9EGftELV2iCiHCAQMAvT04sVznJ+fpdVqNcuj1hOBJj0wCvECFxcXaeWhIuEUYFADAGZCXF5dpg/3DxmA99YIZVmGRXr58lVqi1CMER8+fOh+pkUS5XIZd7d3ylEIViI5M7wCITqa1wOAtDVPKD1A45andC1ES/N6DZCuzKsIWZr3RoikMK4jZGleD2BsntDOA74tT0gIOZrXEfJmXiti24KleBi1M09SThBIU/P6mZiW5qEXMW3NUzuMGrc8NYRssSE0hFyZVxFyLVgdIcOW51oIWZqHfj9ga15+rOLb8lIRg47m9RoQ/R+eeb0GaGleR8i15XWEqL5VFIIJ87V5u70nvrm+AUF0/8nx4ZlxgOj+9KeTk+Oz8/rrYnIYBAoWeNSj9qwWS/T9vUU9j2EAAAAASUVORK5CYII="; - export const SMALLEST_JXL_FILE = "data:image/jxl;base64,/woIAAAMABKIAgC4AF3lEgAAFSqjjBu8nOv58kOHxbSN6wxttW1hSaLIODZJJ3BIEkkaoCUzGM6qJAE="; diff --git a/utils/ipfs.ts b/utils/ipfs.ts index 06137d2a..8ee7c797 100644 --- a/utils/ipfs.ts +++ b/utils/ipfs.ts @@ -1,12 +1,18 @@ import { HIGH_PRIORITY_REQUEST, - IPFS_GATEWAY_URLS, MILLISECONDS_IN_SECOND, ONE_TIME_PASSIVE_EVENT, } from "utils/constants"; let IPFS_GATEWAY_URL = ""; +export const IPFS_GATEWAY_URLS = [ + "https://.ipfs.cf-ipfs.com/", + "https://.ipfs.dweb.link/", + "https://cloudflare-ipfs.com/ipfs//", + "https://gateway.ipfs.io/ipfs//", +]; + const isIpfsGatewayAvailable = (gatewayUrl: string): Promise => new Promise((resolve) => { const timeoutId = window.setTimeout( @@ -34,7 +40,7 @@ const isIpfsGatewayAvailable = (gatewayUrl: string): Promise => img.src = `${gatewayUrl.replace( "", - // https://github.com/ipfs/public-gateway-checker/blob/master/src/constants.ts + // https://github.com/ipfs/public-gateway-checker/blob/master/src/constants.ts (IMG_HASH) "bafybeibwzifw52ttrkqlikfzext5akxu7lz4xiwjgwzmqcpdzmp3n5vnbe" )}?now=${Date.now()}&filename=1x1.png#x-ipfs-companion-no-redirect`; });