Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src-tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ pub fn run() {
commands::canonicalize_path,
commands::read_file_as_data_url,
commands::save_file_content,
commands::sweep_temp_files,
commands::export_pdf_windows,
commands::print_pdf,
commands::is_win11,
Expand Down
26 changes: 25 additions & 1 deletion src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use crate::fs_safety::{
atomic_write, canonical_identity, encode_text, ensure_path_within_root, read_to_string_lossy,
resolve_image_directory, safe_path_component,
resolve_image_directory, safe_path_component, sweep_document_temps,
};
use crate::markdown::{build_markdown_preview, convert_markdown, heading_anchors, HeadingAnchor};
use crate::window_runtime::{self, WatcherState};
Expand Down Expand Up @@ -226,6 +226,30 @@ pub async fn save_file_content(
.unwrap_or_else(|e| Err(e.to_string()))
}

/// Clear temp files earlier runs left beside the documents this window knows
/// about — the recent-file list, and whatever the session restored.
///
/// A save already sweeps the document it is writing, and that is the sweep
/// that matters while someone is working. It cannot reach a document nobody
/// opens again, whose leftovers would otherwise stay in the user's folder for
/// good, so startup asks for the documents Markpad remembers (#722).
///
/// Every window calls this and only the first pays for it: the sweep is once
/// per document per run, and Markpad's windows share a process.
///
/// Async and off the main thread: this is a `read_dir` per document on folders
/// that may live on a network volume, and nothing waits for the result.
#[tauri::command]
pub async fn sweep_temp_files(paths: Vec<String>) -> Result<(), String> {
tauri::async_runtime::spawn_blocking(move || {
for path in paths {
sweep_document_temps(Path::new(&path));
}
})
.await
.map_err(|e| e.to_string())
}

/// Resolve `path` to the identity the filesystem gives it — see
/// `canonical_identity` for what that folds and why the filesystem, rather
/// than a platform guess, is the thing being asked.
Expand Down
Loading
Loading