Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.
Rust apple-notesapple-reminderscloudkitcrdtdesktop-appicloudicloud-calendaricloud-driveicloud-notesicloud-photosiphonelinuxlinux-desktoplocal-firstoffline-firstprivacyrusttauritauri-appwindows
Drive: Paste uploads files copied in the file manager again
Yashwanth Kamireddi483440c89a80
diff --git a/src-tauri/src/clipboard.rs b/src-tauri/src/clipboard.rsindex 5579e7c..bf14872 100644--- a/src-tauri/src/clipboard.rs+++ b/src-tauri/src/clipboard.rs@@ -33,11 +33,11 @@ async fn read(app: &tauri::AppHandle) -> Result<Clipboard, String> {app.run_on_main_thread(move || {let clipboard = gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD);clipboard.request_uris(move |clipboard, uris| {- let files: Vec<String> = uris- .iter()- .filter_map(|uri| glib::filename_from_uri(uri).ok())- .map(|(path, _)| path.to_string_lossy().into_owned())- .collect();+ let files = handed_over(+ uris.iter()+ .filter_map(|uri| glib::filename_from_uri(uri).ok())+ .map(|(path, _)| path),+ );if files.is_empty() {clipboard.request_text(move |_, text| {let _ = tx.send(Clipboard {@@ -54,3 +54,32 @@ async fn read(app: &tauri::AppHandle) -> Result<Clipboard, String> {rx.await.map_err(|_| "The clipboard couldn’t be read.".to_string())}++/// Files copied in the file manager were handed over by the person, as a drop is: granted for+/// reading (grants.rs), so Drive's Paste can upload them. Answered as the window names them.+#[cfg_attr(not(target_os = "linux"), allow(dead_code))]+fn handed_over(paths: impl Iterator<Item = std::path::PathBuf>) -> Vec<String> {+ paths+ .map(|path| {+ crate::grants::grant_read(&path);+ path.to_string_lossy().into_owned()+ })+ .collect()+}++#[cfg(test)]+mod tests {+ /// Files on the clipboard can be uploaded by Paste: what clipboard_read hands the window+ /// is granted for reading, and nothing else is.+ #[test]+ fn files_on_the_clipboard_may_be_pasted_and_no_others() {+ let dir = tempfile::tempdir().unwrap();+ let (copied, other) = (dir.path().join("copied.jpg"), dir.path().join("other.jpg"));+ std::fs::write(&copied, b"x").unwrap();+ std::fs::write(&other, b"x").unwrap();+ let named = super::handed_over(std::iter::once(copied.clone()));+ assert_eq!(named, vec![copied.to_string_lossy().into_owned()]);+ assert!(crate::grants::take_read(&named[0]).is_ok());+ assert!(crate::grants::take_read(&other.to_string_lossy()).is_err());+ }+}