Move workspace file work off the main thread and delete to the trash
Run the blocking workspace commands on the blocking thread pool. Tauri runs a synchronous command on the main thread, so a long search or copy froze every window. Command names, arguments, and results do not change. Send each workspace-event only to the windows that have its root open. The frontend listens with its window label as the target. Do not send access events, because the frontend ignores them. Drop watchers after the state lock is released, because a macOS watcher waits for its thread when it stops. Fix these defects. Each fix has a Rust test: - A rename that changes only the letter case works on case-insensitive volumes. - New files publish with a move that never replaces a file: MoveFileExW on Windows, renameat2 or renamex_np on Linux and macOS, then a hard link, then create_new. exFAT, FAT32, and many network mounts now work. The Windows save recovery uses the same move. - On macOS and Linux, existing names with a colon stay usable. New names reject the characters that Windows does not allow, on every platform. - workspace_read_data_url checks the size before it reads the file. - workspace_write_bytes uses the atomic writer. Its only caller writes new names, so it gets no conflict check. - Delete and rename act on a link itself, not on its target. Delete now moves items to the system trash. One file moves without a confirmation. A folder or several items need one. Shift+Delete and "Delete permanently" keep the permanent delete with its confirmation. Windows drives without a Recycle Bin give an error instead of a silent permanent delete. The smoke test for tree actions now checks this behavior. The user guide describes it and the new-name rule.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import { open as openDialog } from "@tauri-apps/plugin-dialog";
|
||||
import type { TreeEntry, WorkspaceEvent, WorkspaceInfo } from "./types";
|
||||
import { tr } from "../i18n/index.ts";
|
||||
@@ -64,8 +65,9 @@ export function workspaceRename(from: string, to: string, expectedRoot?: string)
|
||||
return invoke("workspace_rename", { from, to, expectedRoot });
|
||||
}
|
||||
|
||||
export function workspaceDelete(rel: string): Promise<void> {
|
||||
return invoke("workspace_delete", { rel });
|
||||
/** Move an item to the system trash, or delete it permanently with `permanent`. */
|
||||
export function workspaceDelete(rel: string, permanent = false): Promise<void> {
|
||||
return invoke("workspace_delete", { rel, permanent });
|
||||
}
|
||||
|
||||
export function workspaceReadDataUrl(rel: string): Promise<string> {
|
||||
@@ -107,10 +109,15 @@ export function workspaceSearch(query: string): Promise<SearchHit[]> {
|
||||
return invoke("workspace_search", { query });
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen to file changes in the workspace of this window. The host sends each change only to
|
||||
* the windows that have its workspace open (src-tauri/src/workspace.rs `emit_watch_event`).
|
||||
* The target must be this window: a listener without a target receives the events of every window.
|
||||
*/
|
||||
export function onWorkspaceEvent(
|
||||
handler: (event: WorkspaceEvent) => void,
|
||||
): Promise<UnlistenFn> {
|
||||
return listen<WorkspaceEvent>("workspace-event", (event) => {
|
||||
handler(event.payload);
|
||||
});
|
||||
}, { target: getCurrentWindow().label });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user