mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-14 10:34:06 +02:00
# Summary - Adds desktop file tracking: local paths are preserved and save buttons now work as expcted (doing Save/Save As as appropriate) - Adds logic to track whether files are 'dirty' (they've been modified by some tool, and not saved to disk yet). - Improves file state UX (dirty vs saved) and close warnings - Web behaviour should be unaffected by these changes ## Indicators Files now have indicators in desktop mode to tell you their state. ### File up-to-date with disk <img width="318" height="393" alt="image" src="https://github.com/user-attachments/assets/06325f9a-afd7-4c2f-8a5b-6d11e3093115" /> ### File modified by a tool but not saved to disk yet <img width="357" height="385" alt="image" src="https://github.com/user-attachments/assets/1a7716d9-c6f7-4d13-be0d-c1de6493954b" /> ### File not tracked on disk <img width="312" height="379" alt="image" src="https://github.com/user-attachments/assets/9cffe300-bd9a-4e19-97c7-9b98bebefacc" /> # Limitations - It's a bit weird that we still have files stored in indexeddb in the app, which are still loadable. We might want to change this behaviour in the future - Viewer's Save doesn't persist to disk. I've left that out here because it'd need a lot of testing to make sure the logic's right with making sure you can leave the Viewer with applying the changes to the PDF _without_ saving to disk - There's no current way to do Save As on a file that has already been persisted to disk - it's only ever Save. Similarly, there's no way to duplicate a file. --------- Co-authored-by: James Brunton <[email protected]> Co-authored-by: James Brunton <[email protected]>
45 lines
1.6 KiB
Rust
45 lines
1.6 KiB
Rust
use crate::utils::add_log;
|
|
use std::sync::Mutex;
|
|
|
|
// Store the opened file paths globally (supports multiple files)
|
|
static OPENED_FILES: Mutex<Vec<String>> = Mutex::new(Vec::new());
|
|
|
|
// Add an opened file path
|
|
pub fn add_opened_file(file_path: String) {
|
|
let mut opened_files = OPENED_FILES.lock().unwrap();
|
|
opened_files.push(file_path.clone());
|
|
add_log(format!("📂 File stored for later retrieval: {}", file_path));
|
|
}
|
|
|
|
// Command to get opened file paths (if app was launched with files)
|
|
#[tauri::command]
|
|
pub async fn get_opened_files() -> Result<Vec<String>, String> {
|
|
// Get all files from the OPENED_FILES store
|
|
// Command line args are processed in setup() callback and added to this store
|
|
// Additional files from second instances or events are also added here
|
|
let opened_files = OPENED_FILES.lock().unwrap();
|
|
let all_files = opened_files.clone();
|
|
|
|
add_log(format!("📂 Returning {} opened file(s)", all_files.len()));
|
|
Ok(all_files)
|
|
}
|
|
|
|
// Command to clear the opened files (after processing)
|
|
#[tauri::command]
|
|
pub async fn clear_opened_files() -> Result<(), String> {
|
|
let mut opened_files = OPENED_FILES.lock().unwrap();
|
|
opened_files.clear();
|
|
add_log("📂 Cleared opened files".to_string());
|
|
Ok(())
|
|
}
|
|
|
|
// Command to atomically get and clear opened file paths
|
|
#[tauri::command]
|
|
pub async fn pop_opened_files() -> Result<Vec<String>, String> {
|
|
let mut opened_files = OPENED_FILES.lock().unwrap();
|
|
let all_files = opened_files.clone();
|
|
opened_files.clear();
|
|
add_log(format!("📂 Returning and clearing {} opened file(s)", all_files.len()));
|
|
Ok(all_files)
|
|
}
|