Implement unmount button

This commit is contained in:
Jeremy Soller 2024-04-24 13:59:55 -06:00
parent 8c3af501ca
commit 37a6f37f7f
No known key found for this signature in database
GPG key ID: D02FD439211AF56F
5 changed files with 77 additions and 29 deletions

View file

@ -24,6 +24,7 @@ fn gio_icon_to_path(icon: &gio::Icon, size: u16) -> Option<PathBuf> {
enum Cmd {
Rescan,
Mount(MounterItem),
Unmount(MounterItem),
}
enum Event {
@ -189,6 +190,34 @@ impl Gvfs {
);
}
}
Cmd::Unmount(mounter_item) => {
let MounterItem::Gvfs(item) = mounter_item else { continue };
let ItemKind::Mount = item.kind else { continue };
for (i, mount) in monitor.mounts().into_iter().enumerate() {
if i != item.index {
continue;
}
let name = MountExt::name(&mount);
if item.name != name {
log::warn!("trying to unmount mount {} failed: name is {:?} when {:?} was expected", i, name, item.name);
continue;
}
//TODO: do eject instead of unmount?
log::info!("unmount {}", name);
MountExt::unmount_with_operation(
&mount,
gio::MountUnmountFlags::NONE,
//TODO: gio::MountOperation needed for network shares with auth
gio::MountOperation::NONE,
gio::Cancellable::NONE,
move |result| {
log::info!("unmount {}: result {:?}", name, result);
},
);
}
}
}
}
});
@ -213,6 +242,17 @@ impl Mounter for Gvfs {
)
}
fn unmount(&self, item: MounterItem) -> Command<()> {
let command_tx = self.command_tx.clone();
Command::perform(
async move {
command_tx.send(Cmd::Unmount(item)).unwrap();
()
},
|x| x,
)
}
fn subscription(&self) -> subscription::Subscription<MounterItems> {
let command_tx = self.command_tx.clone();
let event_rx = self.event_rx.clone();

View file

@ -51,6 +51,7 @@ pub type MounterItems = Vec<MounterItem>;
pub trait Mounter {
//TODO: send result
fn mount(&self, item: MounterItem) -> Command<()>;
fn unmount(&self, item: MounterItem) -> Command<()>;
fn subscription(&self) -> subscription::Subscription<MounterItems>;
}