Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/files/browser/webFileSystemAccess.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
/**
7
* Typings for the https://wicg.github.io/file-system-access
8
*
9
* Use `supported(window)` to find out if the browser supports this kind of API.
10
*/
11
export namespace WebFileSystemAccess {
12
13
export function supported(obj: any & Window): boolean {
14
if (typeof obj?.showDirectoryPicker === 'function') {
15
return true;
16
}
17
18
return false;
19
}
20
21
export function isFileSystemHandle(handle: unknown): handle is FileSystemHandle {
22
const candidate = handle as FileSystemHandle | undefined;
23
if (!candidate) {
24
return false;
25
}
26
27
return typeof candidate.kind === 'string' && typeof candidate.queryPermission === 'function' && typeof candidate.requestPermission === 'function';
28
}
29
30
export function isFileSystemFileHandle(handle: FileSystemHandle): handle is FileSystemFileHandle {
31
return handle.kind === 'file';
32
}
33
34
export function isFileSystemDirectoryHandle(handle: FileSystemHandle): handle is FileSystemDirectoryHandle {
35
return handle.kind === 'directory';
36
}
37
}
38
39
export namespace WebFileSystemObserver {
40
41
export function supported(obj: any & Window): boolean {
42
return typeof obj?.FileSystemObserver === 'function';
43
}
44
}
45
46
export interface FileSystemObserver {
47
new(callback: (records: FileSystemObserverRecord[], observer: FileSystemObserver) => void): FileSystemObserver;
48
49
observe(handle: FileSystemHandle): Promise<void>;
50
observe(handle: FileSystemDirectoryHandle, options?: { recursive: boolean }): Promise<void>;
51
52
unobserve(handle: FileSystemHandle): void;
53
disconnect(): void;
54
}
55
56
export interface FileSystemObserverRecord {
57
58
/**
59
* The handle passed to the `FileSystemObserver.observe()` function
60
*/
61
readonly root: FileSystemHandle;
62
63
/**
64
* The handle affected by the file system change
65
*/
66
readonly changedHandle: FileSystemHandle;
67
68
/**
69
* The path of the `changedHandle` relative to the `root`
70
*/
71
readonly relativePathComponents: string[];
72
73
/**
74
* "appeared": The file or directory was created or got moved into the root.
75
* "disappeared": The file or directory was deleted or got moved out of the root.
76
* "modified": The file or directory was modified.
77
* "moved": The file or directory was moved within the root.
78
* "unknown": This indicates that zero or more events were missed. Developers should poll the watched directory in response to this.
79
* "errored": The observation is no longer valid. In this case, you may want to stop observing the file system.
80
*/
81
readonly type: 'appeared' | 'disappeared' | 'modified' | 'moved' | 'unknown' | 'errored';
82
83
/**
84
* The former location of a moved handle. Available only when the type is "moved".
85
*/
86
readonly relativePathMovedFrom?: string[];
87
}
88
89