Path: blob/main/src/vs/platform/files/browser/webFileSystemAccess.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45/**6* Typings for the https://wicg.github.io/file-system-access7*8* Use `supported(window)` to find out if the browser supports this kind of API.9*/10export namespace WebFileSystemAccess {1112export function supported(obj: any & Window): boolean {13if (typeof obj?.showDirectoryPicker === 'function') {14return true;15}1617return false;18}1920export function isFileSystemHandle(handle: unknown): handle is FileSystemHandle {21const candidate = handle as FileSystemHandle | undefined;22if (!candidate) {23return false;24}2526return typeof candidate.kind === 'string' && typeof candidate.queryPermission === 'function' && typeof candidate.requestPermission === 'function';27}2829export function isFileSystemFileHandle(handle: FileSystemHandle): handle is FileSystemFileHandle {30return handle.kind === 'file';31}3233export function isFileSystemDirectoryHandle(handle: FileSystemHandle): handle is FileSystemDirectoryHandle {34return handle.kind === 'directory';35}36}3738export namespace WebFileSystemObserver {3940export function supported(obj: any & Window): boolean {41return typeof obj?.FileSystemObserver === 'function';42}43}4445export interface FileSystemObserver {46new(callback: (records: FileSystemObserverRecord[], observer: FileSystemObserver) => void): FileSystemObserver;4748observe(handle: FileSystemHandle): Promise<void>;49observe(handle: FileSystemDirectoryHandle, options?: { recursive: boolean }): Promise<void>;5051unobserve(handle: FileSystemHandle): void;52disconnect(): void;53}5455export interface FileSystemObserverRecord {5657/**58* The handle passed to the `FileSystemObserver.observe()` function59*/60readonly root: FileSystemHandle;6162/**63* The handle affected by the file system change64*/65readonly changedHandle: FileSystemHandle;6667/**68* The path of the `changedHandle` relative to the `root`69*/70readonly relativePathComponents: string[];7172/**73* "appeared": The file or directory was created or got moved into the root.74* "disappeared": The file or directory was deleted or got moved out of the root.75* "modified": The file or directory was modified.76* "moved": The file or directory was moved within the root.77* "unknown": This indicates that zero or more events were missed. Developers should poll the watched directory in response to this.78* "errored": The observation is no longer valid. In this case, you may want to stop observing the file system.79*/80readonly type: 'appeared' | 'disappeared' | 'modified' | 'moved' | 'unknown' | 'errored';8182/**83* The former location of a moved handle. Available only when the type is "moved".84*/85readonly relativePathMovedFrom?: string[];86}878889