Skip to content

Commit 77ebaa0

Browse files
committed
MTP: Show loading progress when opening folders
- `list_directory_with_progress()` on `MtpConnectionManager` uses mtp-rs's new `list_objects_stream()` to get the handle count upfront, then fetches metadata per handle with progress callbacks every 20 items - `MtpVolume` overrides the `Volume` trait's `list_directory_with_progress()` to wire this through - Extracted `convert_object_infos()` and `finalize_listing()` to share post-processing between the two listing code paths - No frontend changes needed — the existing streaming listing pipeline already displays "Loaded N files..." when progress callbacks fire
1 parent 17efe8b commit 77ebaa0

3 files changed

Lines changed: 330 additions & 22 deletions

File tree

apps/desktop/src-tauri/src/file_system/volume/mtp.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ impl Volume for MtpVolume {
112112
mtp_path
113113
);
114114

115-
// Get the tokio runtime handle - we're inside spawn_blocking,
116-
// so block_on is safe here
117115
let handle = tokio::runtime::Handle::current();
118116

119117
let start = std::time::Instant::now();
@@ -139,6 +137,48 @@ impl Volume for MtpVolume {
139137
result.map_err(map_mtp_error)
140138
}
141139

140+
fn list_directory_with_progress(
141+
&self,
142+
path: &Path,
143+
on_progress: &dyn Fn(usize),
144+
) -> Result<Vec<FileEntry>, VolumeError> {
145+
let mtp_path = self.to_mtp_path(path);
146+
let device_id = self.device_id.clone();
147+
let storage_id = self.storage_id;
148+
149+
debug!(
150+
"MtpVolume::list_directory_with_progress: device={}, storage={}, input_path={}, mtp_path={}",
151+
device_id,
152+
storage_id,
153+
path.display(),
154+
mtp_path
155+
);
156+
157+
let handle = tokio::runtime::Handle::current();
158+
159+
let start = std::time::Instant::now();
160+
let result = handle.block_on(async move {
161+
connection_manager()
162+
.list_directory_with_progress(&device_id, storage_id, &mtp_path, on_progress)
163+
.await
164+
});
165+
166+
match &result {
167+
Ok(entries) => debug!(
168+
"MtpVolume::list_directory_with_progress: completed in {:?}, {} entries",
169+
start.elapsed(),
170+
entries.len()
171+
),
172+
Err(e) => debug!(
173+
"MtpVolume::list_directory_with_progress: failed in {:?}, error={:?}",
174+
start.elapsed(),
175+
e
176+
),
177+
}
178+
179+
result.map_err(map_mtp_error)
180+
}
181+
142182
fn get_metadata(&self, path: &Path) -> Result<FileEntry, VolumeError> {
143183
// MTP doesn't have a direct "get metadata" API - we need to list the parent
144184
// and find the entry. For now, return NotSupported.

apps/desktop/src-tauri/src/indexing/store.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,14 @@ impl IndexStore {
828828
Ok(())
829829
})();
830830
match result {
831-
Ok(()) => { conn.execute_batch("RELEASE insert_entries")?; Ok(()) }
832-
Err(e) => { let _ = conn.execute_batch("ROLLBACK TO insert_entries"); Err(e) }
831+
Ok(()) => {
832+
conn.execute_batch("RELEASE insert_entries")?;
833+
Ok(())
834+
}
835+
Err(e) => {
836+
let _ = conn.execute_batch("ROLLBACK TO insert_entries");
837+
Err(e)
838+
}
833839
}
834840
}
835841

@@ -899,8 +905,14 @@ impl IndexStore {
899905
Ok(())
900906
})();
901907
match result {
902-
Ok(()) => { conn.execute_batch("RELEASE upsert_stats")?; Ok(()) }
903-
Err(e) => { let _ = conn.execute_batch("ROLLBACK TO upsert_stats"); Err(e) }
908+
Ok(()) => {
909+
conn.execute_batch("RELEASE upsert_stats")?;
910+
Ok(())
911+
}
912+
Err(e) => {
913+
let _ = conn.execute_batch("ROLLBACK TO upsert_stats");
914+
Err(e)
915+
}
904916
}
905917
}
906918

0 commit comments

Comments
 (0)