Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

iCloud Drive folder: thumbnails from Apple, nothing downloaded to draw them

Yashwanth Kamireddi475e5fe247c9
diff --git a/Cargo.lock b/Cargo.lock
index b3f09a4..9145fa2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2743,6 +2743,16 @@ dependencies = [
"web_atoms",
]
+[[package]]
+name = "md-5"
+version = "0.10.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf"
+dependencies = [
+ "cfg-if",
+ "digest",
+]
+
[[package]]
name = "memchr"
version = "2.8.3"
@@ -3710,6 +3720,7 @@ dependencies = [
"fast_image_resize",
"image",
"libheif-rs",
+ "png 0.17.16",
]
[[package]]
@@ -3742,8 +3753,11 @@ name = "quince-vfs"
version = "0.1.0"
dependencies = [
"fuser",
+ "image",
"libc",
+ "md-5",
"quince-core",
+ "quince-media",
"tempfile",
"tokio",
]
diff --git a/crates/quince-media/Cargo.toml b/crates/quince-media/Cargo.toml
index 368c613..224e816 100644
--- a/crates/quince-media/Cargo.toml
+++ b/crates/quince-media/Cargo.toml
@@ -10,3 +10,4 @@ fast_image_resize = "6.1.0"
# attack surface for no gain.
image = { version = "0.25", default-features = false, features = ["png", "jpeg"] }
libheif-rs = "3.0.0"
+png = "0.17"
diff --git a/crates/quince-media/src/lib.rs b/crates/quince-media/src/lib.rs
index 0370c2a..e8f2e70 100644
--- a/crates/quince-media/src/lib.rs
+++ b/crates/quince-media/src/lib.rs
@@ -279,6 +279,91 @@ pub const UPRIGHT_MATRIX: [u8; 36] = [
0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0, 0, 0,
];
+/// The `file://` URI of a path, escaped exactly as GLib escapes it (g_filename_to_uri, its
+/// UNSAFE_PATH table in gconvert.c): the freedesktop thumbnail cache names each thumbnail by
+/// the MD5 of this string, so one character escaped differently and no file manager finds it.
+#[must_use]
+pub fn file_uri(path: &std::path::Path) -> String {
+ use std::os::unix::ffi::OsStrExt;
+ // GLib's table, ASCII 32 to 127; a character is kept when its byte has 0x08 set.
+ const ACCEPTABLE: [u8; 96] = [
+ 0x00, 0x3F, 0x20, 0x20, 0x28, 0x00, 0x2C, 0x3F, 0x3F, 0x3F, 0x3F, 0x2A, 0x28, 0x3F, 0x3F,
+ 0x1C, //
+ 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x38, 0x20, 0x20, 0x2C, 0x20,
+ 0x20, //
+ 0x38, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
+ 0x3F, //
+ 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x20, 0x20, 0x20, 0x20,
+ 0x3F, //
+ 0x20, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
+ 0x3F, //
+ 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x20, 0x20, 0x20, 0x3F,
+ 0x20,
+ ];
+ let mut out = String::from("file://");
+ for &b in path.as_os_str().as_bytes() {
+ let kept = (32..128).contains(&b) && ACCEPTABLE[usize::from(b - 32)] & 0x08 != 0;
+ if kept {
+ out.push(char::from(b));
+ } else {
+ out.push_str(&format!("%{b:02X}"));
+ }
+ }
+ out
+}
+
+/// A thumbnail as the freedesktop thumbnail cache keeps one: a PNG no larger than `px` on its
+/// longer side (never enlarged), carrying the file's URI and modification time, which a file
+/// manager checks before trusting it.
+///
+/// # Errors
+/// When the picture cannot be read or the PNG cannot be made.
+pub fn freedesktop_thumbnail(
+ picture: &[u8],
+ px: u32,
+ uri: &str,
+ mtime: i64,
+) -> Result<Vec<u8>, String> {
+ let image = image::load_from_memory(picture).map_err(|e| e.to_string())?;
+ let image = if image.width().max(image.height()) > px {
+ image.resize(px, px, image::imageops::FilterType::Lanczos3)
+ } else {
+ image
+ };
+ let rgba = image.to_rgba8();
+ let mut out = Vec::new();
+ {
+ let mut encoder = png::Encoder::new(&mut out, rgba.width(), rgba.height());
+ encoder.set_color(png::ColorType::Rgba);
+ encoder.set_depth(png::BitDepth::Eight);
+ encoder
+ .add_text_chunk("Thumb::URI".into(), uri.into())
+ .map_err(|e| e.to_string())?;
+ encoder
+ .add_text_chunk("Thumb::MTime".into(), mtime.to_string())
+ .map_err(|e| e.to_string())?;
+ encoder
+ .add_text_chunk("Software".into(), "Quince".into())
+ .map_err(|e| e.to_string())?;
+ let mut writer = encoder.write_header().map_err(|e| e.to_string())?;
+ writer.write_image_data(&rgba).map_err(|e| e.to_string())?;
+ }
+ Ok(out)
+}
+
+/// The `Thumb::MTime` a freedesktop thumbnail carries, if it is one.
+#[must_use]
+pub fn thumbnail_mtime(png_bytes: &[u8]) -> Option<i64> {
+ let decoder = png::Decoder::new(std::io::Cursor::new(png_bytes));
+ let reader = decoder.read_info().ok()?;
+ reader
+ .info()
+ .uncompressed_latin1_text
+ .iter()
+ .find(|t| t.keyword == "Thumb::MTime")
+ .and_then(|t| t.text.trim().parse().ok())
+}
+
/// Whether bytes are a HEIF file (HEIC and its kin): an `ftyp` box naming a HEIF brand.
#[must_use]
pub fn is_heif(bytes: &[u8]) -> bool {
diff --git a/crates/quince-media/tests/video_matrix.rs b/crates/quince-media/tests/video_matrix.rs
index c54474b..6082433 100644
--- a/crates/quince-media/tests/video_matrix.rs
+++ b/crates/quince-media/tests/video_matrix.rs
@@ -34,3 +34,31 @@ fn the_matrix_is_found_where_it_is() {
let b = i32::from_be_bytes(bytes[at as usize + 4..at as usize + 8].try_into().unwrap());
assert_eq!((a, b), (0, 0x10000), "its first two words are a and b");
}
+
+/// The thumbnail cache's own rules: a path's URI escaped as GLib escapes it, and a PNG that
+/// carries that URI and the file's time.
+#[test]
+fn freedesktop_thumbnails() {
+ assert_eq!(
+ quince_media::file_uri(Path::new("/home/a b/Résumé (v2)+x;y#z.txt")),
+ "file:///home/a%20b/R%C3%A9sum%C3%A9%20(v2)+x%3By%23z.txt"
+ );
+ let mut picture = image::RgbImage::new(400, 200);
+ for (x, _, p) in picture.enumerate_pixels_mut() {
+ *p = image::Rgb([(x % 255) as u8, 80, 200]);
+ }
+ let mut jpeg = std::io::Cursor::new(Vec::new());
+ picture
+ .write_to(&mut jpeg, image::ImageFormat::Jpeg)
+ .unwrap();
+ let png =
+ quince_media::freedesktop_thumbnail(jpeg.get_ref(), 128, "file:///x.jpg", 1_700_000_100)
+ .unwrap();
+ let back = image::load_from_memory(&png).unwrap();
+ assert_eq!(
+ (back.width(), back.height()),
+ (128, 64),
+ "no larger than 128 on its longer side"
+ );
+ assert_eq!(quince_media::thumbnail_mtime(&png), Some(1_700_000_100));
+}
diff --git a/crates/quince-vfs/Cargo.toml b/crates/quince-vfs/Cargo.toml
index 0064fea..871077c 100644
--- a/crates/quince-vfs/Cargo.toml
+++ b/crates/quince-vfs/Cargo.toml
@@ -9,11 +9,14 @@ license.workspace = true
quince-core = { path = "../quince-core" }
tokio = { workspace = true, features = ["sync", "rt", "time"] }
libc = "0.2"
+quince-media = { path = "../quince-media" }
+md-5 = "0.10"
[target.'cfg(target_os = "linux")'.dependencies]
fuser = { version = "0.18", default-features = false }
[dev-dependencies]
+image = { version = "0.25", default-features = false, features = ["jpeg", "png"] }
tempfile = "3"
libc = "0.2"
tokio = { workspace = true, features = ["sync", "rt", "macros", "rt-multi-thread"] }
diff --git a/crates/quince-vfs/src/fuse.rs b/crates/quince-vfs/src/fuse.rs
index a0f9e35..c3db673 100644
--- a/crates/quince-vfs/src/fuse.rs
+++ b/crates/quince-vfs/src/fuse.rs
@@ -33,6 +33,10 @@ pub struct DriveFs {
uid: u32,
gid: u32,
mounted: std::time::SystemTime,
+ /// Where the folder is mounted and the thumbnail cache's root, when thumbnails are wanted.
+ thumbs: Option<(std::path::PathBuf, std::path::PathBuf)>,
+ /// Folders whose thumbnails were written, by their items' versions: written once.
+ filled: Mutex<std::collections::HashSet<String>>,
}
impl DriveFs {
@@ -51,12 +55,64 @@ impl DriveFs {
cache,
inodes: Mutex::new(Inodes::new()),
mounted: std::time::SystemTime::now(),
+ thumbs: None,
+ filled: Mutex::new(std::collections::HashSet::new()),
rt,
uid,
gid,
}
}
+ /// Apple's pictures of each folder listed put in the thumbnail cache (the crate's
+ /// write_thumbnails), for a folder mounted at `mount`.
+ #[must_use]
+ pub fn with_thumbnails(mut self, mount: std::path::PathBuf, cache: std::path::PathBuf) -> Self {
+ self.thumbs = Some((mount, cache));
+ self
+ }
+
+ /// In the background, once per folder version: the folder's thumbnails written.
+ fn fill_thumbnails(&self, folder: &DriveItem, files: &[(String, u64, DriveItem)]) {
+ let Some((mount, cache)) = self.thumbs.clone() else {
+ return;
+ };
+ let mut paths = Vec::new();
+ let mut fingerprint = folder.drivewsid.clone();
+ {
+ let inodes = self
+ .inodes
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner);
+ for (_, ino, item) in files.iter().filter(|(_, _, i)| !i.is_container()) {
+ if let Some(p) = inodes.path(*ino) {
+ paths.push((p.to_string(), item.clone()));
+ fingerprint.push_str(item.etag.as_deref().unwrap_or(""));
+ }
+ }
+ }
+ if paths.is_empty()
+ || !self
+ .filled
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .insert(fingerprint)
+ {
+ return;
+ }
+ let (remote, id) = (Arc::clone(&self.remote), folder.drivewsid.clone());
+ self.rt.spawn(async move {
+ let Ok(pictures) = remote.thumbnails(&id).await else {
+ return;
+ };
+ if !pictures.is_empty() {
+ let _ = tokio::task::spawn_blocking(move || {
+ crate::write_thumbnails(&mount, &cache, &paths, &pictures)
+ })
+ .await;
+ }
+ });
+ }
+
fn item(&self, ino: INodeNo) -> Option<DriveItem> {
self.inodes
.lock()
@@ -132,7 +188,11 @@ impl DriveFs {
.unwrap_or_else(std::sync::PoisonError::into_inner);
Ok(named(&items)
.into_iter()
- .map(|(name, it)| (name, inodes.ino(&it), it))
+ .map(|(name, it)| {
+ let child = inodes.ino(&it);
+ inodes.place(child, ino.0, &name);
+ (name, child, it)
+ })
.collect())
}
}
@@ -167,6 +227,11 @@ impl Filesystem for DriveFs {
Ok(c) => c,
Err(e) => return reply.error(e),
};
+ if offset == 0 {
+ if let Some(folder) = self.item(ino) {
+ self.fill_thumbnails(&folder, &children);
+ }
+ }
let parent = self
.item(ino)
.and_then(|i| i.parent_id)
diff --git a/crates/quince-vfs/src/lib.rs b/crates/quince-vfs/src/lib.rs
index 8573611..6ed19fa 100644
--- a/crates/quince-vfs/src/lib.rs
+++ b/crates/quince-vfs/src/lib.rs
@@ -25,6 +25,11 @@ pub trait Remote: Send + Sync + 'static {
fn list(&self, folder: &str) -> Fut<Vec<DriveItem>>;
/// `len` bytes of a file from `offset` (fewer only at its end).
fn read(&self, item: &DriveItem, offset: u64, len: u64) -> Fut<Vec<u8>>;
+ /// Apple's own pictures of a folder's files, by item id: for a file manager's thumbnails,
+ /// so it never downloads a file to draw one. None by default.
+ fn thumbnails(&self, _folder: &str) -> Fut<HashMap<String, Vec<u8>>> {
+ Box::pin(async { Ok(HashMap::new()) })
+ }
}
/// What the library already knows, read without the network.
@@ -42,6 +47,8 @@ pub const ROOT: &str = "FOLDER::com.apple.CloudDocs::root";
pub struct Inodes {
by_ino: HashMap<u64, DriveItem>,
by_id: HashMap<String, u64>,
+ /// Where each item is in the folder, as the file manager names it ("Work/Deck.key").
+ paths: HashMap<u64, String>,
next: u64,
}
@@ -84,6 +91,25 @@ impl Inodes {
ino
}
+ /// Where an item is, from the folder's top, as last listed.
+ #[must_use]
+ pub fn path(&self, ino: u64) -> Option<&str> {
+ if ino == 1 {
+ return Some("");
+ }
+ self.paths.get(&ino).map(String::as_str)
+ }
+
+ /// Record where an item is: its folder's path and its name in it.
+ pub fn place(&mut self, ino: u64, parent: u64, name: &str) {
+ let at = match self.path(parent) {
+ Some("") => name.to_string(),
+ Some(p) => format!("{p}/{name}"),
+ None => return,
+ };
+ self.paths.insert(ino, at);
+ }
+
/// The inode an item already has, by Apple's id.
#[must_use]
pub fn ino_of(&self, id: &str) -> Option<u64> {
@@ -335,6 +361,50 @@ pub fn is_thumbnailer(comm: &str, cmdline: &str) -> bool {
named || (comm == "kioworker" && cmdline.contains("thumbnail"))
}
+/// Apple's pictures of a folder's files written into the freedesktop thumbnail cache, where
+/// GNOME Files, Dolphin and every other file manager look before reading a file to draw it:
+/// thumbnails appear at once, and nothing is downloaded for them. Each is named by the MD5 of
+/// its file's URI and carries the file's time, which the file manager checks; one already
+/// there for the same version is left alone. `mount` is where the folder is mounted, `cache`
+/// the thumbnail cache's root (~/.cache/thumbnails).
+pub fn write_thumbnails(
+ mount: &Path,
+ cache: &Path,
+ files: &[(String, DriveItem)],
+ pictures: &HashMap<String, Vec<u8>>,
+) {
+ use md5::Digest;
+ use std::os::unix::fs::PermissionsExt;
+ for (path, item) in files {
+ let Some(picture) = pictures.get(&item.drivewsid) else {
+ continue;
+ };
+ let uri = quince_media::file_uri(&mount.join(path));
+ let mtime = item.modified_at.unwrap_or(0);
+ let name = format!("{:x}.png", md5::Md5::digest(uri.as_bytes()));
+ for (dir, px) in [("normal", 128), ("large", 256), ("x-large", 512)] {
+ let at = cache.join(dir).join(&name);
+ if std::fs::read(&at)
+ .ok()
+ .and_then(|b| quince_media::thumbnail_mtime(&b))
+ == Some(mtime)
+ {
+ continue;
+ }
+ let Ok(png) = quince_media::freedesktop_thumbnail(picture, px, &uri, mtime) else {
+ continue;
+ };
+ let _ = std::fs::create_dir_all(cache.join(dir));
+ // As the specification asks: private to its owner, and never seen half-written.
+ let part = at.with_extension("png.part");
+ if std::fs::write(&part, &png).is_ok() {
+ let _ = std::fs::set_permissions(&part, std::fs::Permissions::from_mode(0o600));
+ let _ = std::fs::rename(&part, &at);
+ }
+ }
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/crates/quince-vfs/tests/mount.rs b/crates/quince-vfs/tests/mount.rs
index 559d80a..4f95e6c 100644
--- a/crates/quince-vfs/tests/mount.rs
+++ b/crates/quince-vfs/tests/mount.rs
@@ -35,6 +35,23 @@ impl Remote for Apple {
let out = self.folders.get(folder).cloned().unwrap_or_default();
Box::pin(async move { Ok(out) })
}
+ fn thumbnails(&self, folder: &str) -> Fut<HashMap<String, Vec<u8>>> {
+ // Apple's picture of the film, for the root folder.
+ let out = if folder == ROOT {
+ let mut picture = image::RgbImage::new(300, 200);
+ for (x, y, p) in picture.enumerate_pixels_mut() {
+ *p = image::Rgb([(x % 255) as u8, (y % 255) as u8, 90]);
+ }
+ let mut jpeg = std::io::Cursor::new(Vec::new());
+ picture
+ .write_to(&mut jpeg, image::ImageFormat::Jpeg)
+ .unwrap();
+ HashMap::from([("FILE::z::film".to_string(), jpeg.into_inner())])
+ } else {
+ HashMap::new()
+ };
+ Box::pin(async move { Ok(out) })
+ }
fn read(&self, item: &DriveItem, offset: u64, len: u64) -> Fut<Vec<u8>> {
self.reads.lock().unwrap().push((offset, len));
let data = &self.files[&item.drivewsid];
@@ -101,12 +118,14 @@ fn a_mounted_drive_reads_like_a_folder() {
let rt = tokio::runtime::Runtime::new().unwrap();
let cache_dir = tempfile::tempdir().unwrap();
let at = tempfile::tempdir().unwrap();
+ let thumbs = tempfile::tempdir().unwrap();
let fs = fuse::DriveFs::new(
apple.clone(),
library,
Arc::new(Cache::new(cache_dir.path()).unwrap()),
rt.handle().clone(),
- );
+ )
+ .with_thumbnails(at.path().to_path_buf(), thumbs.path().join("thumbnails"));
let session = fuse::mount(fs, at.path()).expect("mounted");
let mut names: Vec<String> = std::fs::read_dir(at.path())
@@ -175,6 +194,39 @@ fn a_mounted_drive_reads_like_a_folder() {
assert_eq!(err.raw_os_error(), Some(libc::EROFS), "{err}");
assert_eq!(std::fs::read(at.path().join("Note.txt")).unwrap(), note);
+ // Apple's picture of the film is in the thumbnail cache, named and stamped so that GLib —
+ // what GNOME Files asks — finds it valid for the mounted file, with nothing downloaded for it.
+ let film_path = at.path().join("Film.mov");
+ let reads_before = apple.reads.lock().unwrap().len();
+ let mut valid = String::new();
+ for _ in 0..30 {
+ std::thread::sleep(std::time::Duration::from_millis(100));
+ if let Ok(out) = std::process::Command::new("gio")
+ .args(["info", "-a", "thumbnail::path,thumbnail::is-valid"])
+ .arg(&film_path)
+ .env("XDG_CACHE_HOME", thumbs.path())
+ .output()
+ {
+ valid = String::from_utf8_lossy(&out.stdout).into_owned();
+ if valid.contains("thumbnail::is-valid: TRUE") {
+ break;
+ }
+ } else {
+ valid = "no gio here".into();
+ break;
+ }
+ }
+ assert!(
+ valid.contains("thumbnail::is-valid: TRUE") || valid == "no gio here",
+ "GLib finds the thumbnail valid: {valid}"
+ );
+ eprintln!("gio says: {}", valid.trim().replace('\n', " | "));
+ assert_eq!(
+ apple.reads.lock().unwrap().len(),
+ reads_before,
+ "nothing downloaded to draw it"
+ );
+
drop(session);
assert_eq!(
std::fs::read_dir(at.path()).unwrap().count(),
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 1d68f5e..924e191 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -3084,17 +3084,37 @@ async fn drive_duplicate(
async fn drive_thumbnails(
folder_id: String,
app: tauri::AppHandle,
- auth: State<'_, Auth>,
- data: State<'_, Data>,
) -> UiResult<std::collections::HashMap<String, String>> {
use base64::Engine;
+ Ok(folder_thumbnails(&app, &folder_id)
+ .await?
+ .into_iter()
+ .map(|(id, bytes)| {
+ let url = data_url(
+ &bytes,
+ &base64::engine::general_purpose::STANDARD.encode(&bytes),
+ );
+ (id, url)
+ })
+ .collect())
+}
+
+/// Apple's pictures of a folder's files, by item id: for the window's grid and for the iCloud
+/// Drive folder's thumbnails (mount.rs), from one cache. Kept on disk beside the library,
+/// named by item and version, so a folder opened again has its pictures at once and only a
+/// changed file is fetched anew.
+pub(crate) async fn folder_thumbnails(
+ app: &tauri::AppHandle,
+ folder_id: &str,
+) -> Result<std::collections::HashMap<String, Vec<u8>>, String> {
let files = {
+ let data = app.state::<Data>();
let library = data.0.lock().await;
library
- .drive_children(&folder_id)
+ .drive_children(folder_id)
.map_err(|e| e.to_string())?
};
- let cache = state_dir(&app).join("thumbnails");
+ let cache = state_dir(app).join("thumbnails");
std::fs::create_dir_all(&cache).ok();
let key = |f: &quince_core::drive::DriveItem| {
let safe = |s: &str| {
@@ -3114,19 +3134,14 @@ async fn drive_thumbnails(
match std::fs::read(key(f)) {
Ok(bytes) if bytes.is_empty() => {} // known to have none
Ok(bytes) => {
- out.insert(
- f.drivewsid.clone(),
- data_url(
- &bytes,
- &base64::engine::general_purpose::STANDARD.encode(&bytes),
- ),
- );
+ out.insert(f.drivewsid.clone(), bytes);
}
Err(_) => missing.push(f.clone()),
}
}
if !missing.is_empty() {
let (http, docws, params) = {
+ let auth = app.state::<Auth>();
let client = auth.client.lock().await;
(
client.http().clone(),
@@ -3148,13 +3163,7 @@ async fn drive_thumbnails(
// An empty file records "Apple has no picture for this version", so it is not asked again.
std::fs::write(key(f), bytes.as_deref().unwrap_or(&[])).ok();
if let Some(bytes) = bytes {
- out.insert(
- f.drivewsid.clone(),
- data_url(
- &bytes,
- &base64::engine::general_purpose::STANDARD.encode(&bytes),
- ),
- );
+ out.insert(f.drivewsid.clone(), bytes);
}
}
}
diff --git a/src-tauri/src/mount.rs b/src-tauri/src/mount.rs
index b5367e0..02590b2 100644
--- a/src-tauri/src/mount.rs
+++ b/src-tauri/src/mount.rs
@@ -59,6 +59,11 @@ impl Remote for AppRemote {
})
}
+ fn thumbnails(&self, folder: &str) -> Fut<HashMap<String, Vec<u8>>> {
+ let (app, folder) = (self.app.clone(), folder.to_string());
+ Box::pin(async move { crate::folder_thumbnails(&app, &folder).await })
+ }
+
fn read(&self, item: &DriveItem, offset: u64, len: u64) -> Fut<Vec<u8>> {
let (app, links, item) = (self.app.clone(), Arc::clone(&self.links), item.clone());
Box::pin(async move {
@@ -188,7 +193,17 @@ fn start(app: &AppHandle, at: &std::path::Path) -> Result<(), String> {
});
let store = Arc::new(AppStore(app.clone()));
let rt = tauri::async_runtime::handle().inner().clone();
- let fs = quince_vfs::fuse::DriveFs::new(remote, store, cache, rt);
+ // Apple's pictures go where every file manager looks for thumbnails, so none of them
+ // downloads a file to draw one.
+ let thumbs = std::env::var_os("XDG_CACHE_HOME")
+ .map(PathBuf::from)
+ .filter(|p| p.is_absolute())
+ .or_else(|| app.path().home_dir().ok().map(|h| h.join(".cache")))
+ .map(|c| c.join("thumbnails"));
+ let mut fs = quince_vfs::fuse::DriveFs::new(remote, store, cache, rt);
+ if let Some(thumbs) = thumbs {
+ fs = fs.with_thumbnails(at.to_path_buf(), thumbs);
+ }
let session = quince_vfs::fuse::mount(fs, at)
.map_err(|e| format!("The folder could not be mounted: {e}"))?;
*SESSION