2024-04-22 13:14:25 -06:00
|
|
|
use cosmic::{iced::subscription, widget, Command};
|
2024-04-22 09:54:00 -06:00
|
|
|
use std::{collections::BTreeMap, path::PathBuf, sync::Arc};
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "gvfs")]
|
|
|
|
|
mod gvfs;
|
|
|
|
|
|
2024-04-22 13:14:25 -06:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
|
pub enum MounterItem {
|
|
|
|
|
#[cfg(feature = "gvfs")]
|
|
|
|
|
Gvfs(gvfs::Item),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl MounterItem {
|
|
|
|
|
pub fn name(&self) -> String {
|
|
|
|
|
match self {
|
|
|
|
|
#[cfg(feature = "gvfs")]
|
|
|
|
|
Self::Gvfs(item) => item.name(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn is_mounted(&self) -> bool {
|
|
|
|
|
match self {
|
|
|
|
|
#[cfg(feature = "gvfs")]
|
|
|
|
|
Self::Gvfs(item) => item.is_mounted(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn icon(&self) -> Option<widget::icon::Handle> {
|
|
|
|
|
match self {
|
|
|
|
|
#[cfg(feature = "gvfs")]
|
|
|
|
|
Self::Gvfs(item) => item.icon(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn path(&self) -> Option<PathBuf> {
|
|
|
|
|
match self {
|
|
|
|
|
#[cfg(feature = "gvfs")]
|
|
|
|
|
Self::Gvfs(item) => item.path(),
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-22 09:54:00 -06:00
|
|
|
}
|
|
|
|
|
|
2024-04-22 13:14:25 -06:00
|
|
|
pub type MounterItems = Vec<MounterItem>;
|
2024-04-22 09:54:00 -06:00
|
|
|
|
|
|
|
|
pub trait Mounter {
|
2024-04-22 13:14:25 -06:00
|
|
|
//TODO: send result
|
|
|
|
|
fn mount(&self, item: MounterItem) -> Command<()>;
|
|
|
|
|
fn subscription(&self) -> subscription::Subscription<MounterItems>;
|
2024-04-22 09:54:00 -06:00
|
|
|
}
|
|
|
|
|
|
2024-04-22 13:14:25 -06:00
|
|
|
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
|
|
|
|
pub struct MounterKey(pub &'static str);
|
2024-04-22 09:54:00 -06:00
|
|
|
pub type MounterMap = BTreeMap<MounterKey, Box<dyn Mounter>>;
|
|
|
|
|
pub type Mounters = Arc<MounterMap>;
|
|
|
|
|
|
|
|
|
|
pub fn mounters() -> Mounters {
|
|
|
|
|
let mut mounters = MounterMap::new();
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "gvfs")]
|
|
|
|
|
{
|
2024-04-22 13:14:25 -06:00
|
|
|
mounters.insert(MounterKey("gvfs"), Box::new(gvfs::Gvfs::new()));
|
2024-04-22 09:54:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Mounters::new(mounters)
|
|
|
|
|
}
|