Implement unmount button
This commit is contained in:
parent
8c3af501ca
commit
37a6f37f7f
5 changed files with 77 additions and 29 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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>;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue