mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-26 21:41:48 +02:00
feat(fs/watch): migrate to notify-debouncer-full (#885)
* Add support for notify-debouncer-full * Add fs watch to demo * Remove notify-debouncer-mini * Rename RawEvent to WatchEvent * Add full type definition for EventKind * Remove `track file ids` option from fs watcher * Update plugins/fs/guest-js/index.ts
This commit is contained in:
@@ -1098,8 +1098,8 @@ interface DebouncedWatchOptions extends WatchOptions {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
type RawEvent = {
|
||||
type: RawEventKind;
|
||||
type WatchEvent = {
|
||||
type: WatchEventKind;
|
||||
paths: string[];
|
||||
attrs: unknown;
|
||||
};
|
||||
@@ -1107,28 +1107,60 @@ type RawEvent = {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
type RawEventKind =
|
||||
| "any "
|
||||
| {
|
||||
access?: unknown;
|
||||
}
|
||||
| {
|
||||
create?: unknown;
|
||||
}
|
||||
| {
|
||||
modify?: unknown;
|
||||
}
|
||||
| {
|
||||
remove?: unknown;
|
||||
}
|
||||
type WatchEventKind =
|
||||
| "any"
|
||||
| { access: WatchEventKindAccess }
|
||||
| { create: WatchEventKindCreate }
|
||||
| { modify: WatchEventKindModify }
|
||||
| { remove: WatchEventKindRemove }
|
||||
| "other";
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
type DebouncedEvent =
|
||||
| { kind: "Any"; path: string }[]
|
||||
| { kind: "AnyContinuous"; path: string }[];
|
||||
type WatchEventKindAccess =
|
||||
| { kind: "any" }
|
||||
| { kind: "close"; mode: "any" | "execute" | "read" | "write" | "other" }
|
||||
| { kind: "open"; mode: "any" | "execute" | "read" | "write" | "other" }
|
||||
| { kind: "other" };
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
type WatchEventKindCreate =
|
||||
| { kind: "any" }
|
||||
| { kind: "file" }
|
||||
| { kind: "folder" }
|
||||
| { kind: "other" };
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
type WatchEventKindModify =
|
||||
| { kind: "any" }
|
||||
| { kind: "data"; mode: "any" | "size" | "content" | "other" }
|
||||
| {
|
||||
kind: "metadata";
|
||||
mode:
|
||||
| "any"
|
||||
| "access-time"
|
||||
| "write-time"
|
||||
| "permissions"
|
||||
| "ownership"
|
||||
| "extended"
|
||||
| "other";
|
||||
}
|
||||
| { kind: "name"; mode: "any" | "to" | "from" | "both" | "other" }
|
||||
| { kind: "other" };
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
type WatchEventKindRemove =
|
||||
| { kind: "any" }
|
||||
| { kind: "file" }
|
||||
| { kind: "folder" }
|
||||
| { kind: "other" };
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
@@ -1146,7 +1178,7 @@ async function unwatch(rid: number): Promise<void> {
|
||||
*/
|
||||
async function watch(
|
||||
paths: string | string[] | URL | URL[],
|
||||
cb: (event: DebouncedEvent) => void,
|
||||
cb: (event: WatchEvent) => void,
|
||||
options?: DebouncedWatchOptions,
|
||||
): Promise<UnwatchFn> {
|
||||
const opts = {
|
||||
@@ -1163,7 +1195,7 @@ async function watch(
|
||||
}
|
||||
}
|
||||
|
||||
const onEvent = new Channel<DebouncedEvent>();
|
||||
const onEvent = new Channel<WatchEvent>();
|
||||
onEvent.onmessage = cb;
|
||||
|
||||
const rid: number = await invoke("plugin:fs|watch", {
|
||||
@@ -1184,7 +1216,7 @@ async function watch(
|
||||
*/
|
||||
async function watchImmediate(
|
||||
paths: string | string[] | URL | URL[],
|
||||
cb: (event: RawEvent) => void,
|
||||
cb: (event: WatchEvent) => void,
|
||||
options?: WatchOptions,
|
||||
): Promise<UnwatchFn> {
|
||||
const opts = {
|
||||
@@ -1201,7 +1233,7 @@ async function watchImmediate(
|
||||
}
|
||||
}
|
||||
|
||||
const onEvent = new Channel<RawEvent>();
|
||||
const onEvent = new Channel<WatchEvent>();
|
||||
onEvent.onmessage = cb;
|
||||
|
||||
const rid: number = await invoke("plugin:fs|watch", {
|
||||
@@ -1232,8 +1264,12 @@ export type {
|
||||
FileInfo,
|
||||
WatchOptions,
|
||||
DebouncedWatchOptions,
|
||||
DebouncedEvent,
|
||||
RawEvent,
|
||||
WatchEvent,
|
||||
WatchEventKind,
|
||||
WatchEventKindAccess,
|
||||
WatchEventKindCreate,
|
||||
WatchEventKindModify,
|
||||
WatchEventKindRemove,
|
||||
UnwatchFn,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user