cosmic-files/src/mounter/mod.rs

66 lines
1.5 KiB
Rust
Raw Normal View History

2024-04-22 13:14:25 -06:00
use cosmic::{iced::subscription, widget, Command};
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 13:14:25 -06:00
pub type MounterItems = Vec<MounterItem>;
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 13:14:25 -06:00
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct MounterKey(pub &'static str);
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()));
}
Mounters::new(mounters)
}