This commit is contained in:
Ashley Wulber 2025-07-15 10:55:21 -04:00 committed by Jeremy Soller
parent 08367c9ea6
commit a7a519b14c
3 changed files with 9 additions and 36 deletions

View file

@ -3,13 +3,7 @@ use cosmic::{
widget, Task,
};
use gio::{glib, prelude::*};
use std::{
any::TypeId,
cell::Cell,
future::pending,
path::{Path, PathBuf},
sync::Arc,
};
use std::{any::TypeId, cell::Cell, future::pending, path::PathBuf, sync::Arc};
use tokio::sync::{mpsc, Mutex};
use super::{Mounter, MounterAuth, MounterItem, MounterItems, MounterMessage};
@ -205,7 +199,6 @@ enum Cmd {
NetworkScan(
String,
IconSizes,
Option<PathBuf>,
mpsc::Sender<Result<Vec<tab::Item>, String>>,
),
Unmount(MounterItem),
@ -404,7 +397,7 @@ impl Gvfs {
}
);
}
Cmd::NetworkScan(uri, sizes, path, items_tx) => {
Cmd::NetworkScan(uri, sizes, items_tx) => {
let file = gio::File::for_uri(&uri);
let needs_mount = match file.find_enclosing_mount(gio::Cancellable::NONE) {
Ok(_) => false,
@ -527,20 +520,10 @@ impl Mounter for Gvfs {
)
}
fn network_scan(
&self,
uri: &str,
sizes: IconSizes,
path: Option<&Path>,
) -> Option<Result<Vec<tab::Item>, String>> {
fn network_scan(&self, uri: &str, sizes: IconSizes) -> Option<Result<Vec<tab::Item>, String>> {
let (items_tx, mut items_rx) = mpsc::channel(1);
self.command_tx
.send(Cmd::NetworkScan(
uri.to_string(),
sizes,
path.map(|p| p.to_owned()),
items_tx,
))
.send(Cmd::NetworkScan(uri.to_string(), sizes, items_tx))
.unwrap();
items_rx.blocking_recv()
}

View file

@ -1,11 +1,6 @@
use cosmic::{iced::Subscription, widget, Task};
use once_cell::sync::Lazy;
use std::{
collections::BTreeMap,
fmt,
path::{Path, PathBuf},
sync::Arc,
};
use std::{collections::BTreeMap, fmt, path::PathBuf, sync::Arc};
use tokio::sync::mpsc;
use crate::{config::IconSizes, tab};
@ -108,12 +103,7 @@ pub trait Mounter: Send + Sync {
//TODO: send result
fn mount(&self, item: MounterItem) -> Task<()>;
fn network_drive(&self, uri: String) -> Task<()>;
fn network_scan(
&self,
uri: &str,
sizes: IconSizes,
path: Option<&Path>,
) -> Option<Result<Vec<tab::Item>, String>>;
fn network_scan(&self, uri: &str, sizes: IconSizes) -> Option<Result<Vec<tab::Item>, String>>;
fn unmount(&self, item: MounterItem) -> Task<()>;
fn subscription(&self) -> Subscription<MounterMessage>;
}

View file

@ -1205,9 +1205,9 @@ pub fn scan_recents(sizes: IconSizes) -> Vec<Item> {
recents.into_iter().take(50).map(|(item, _)| item).collect()
}
pub fn scan_network(uri: &str, sizes: IconSizes, path: Option<&Path>) -> Vec<Item> {
pub fn scan_network(uri: &str, sizes: IconSizes) -> Vec<Item> {
for (_key, mounter) in MOUNTERS.iter() {
match mounter.network_scan(uri, sizes, path) {
match mounter.network_scan(uri, sizes) {
Some(Ok(items)) => return items,
Some(Err(err)) => {
log::warn!("failed to scan {:?}: {}", uri, err);
@ -1445,7 +1445,7 @@ impl Location {
}
Self::Trash => scan_trash(sizes),
Self::Recents => scan_recents(sizes),
Self::Network(uri, _, path) => scan_network(uri, sizes, path.as_deref()),
Self::Network(uri, _, _) => scan_network(uri, sizes),
};
let parent_item_opt = match self.path_opt() {
Some(path) => match item_from_path(path, sizes) {