Implement unmount button
This commit is contained in:
parent
8c3af501ca
commit
37a6f37f7f
5 changed files with 77 additions and 29 deletions
32
Cargo.lock
generated
32
Cargo.lock
generated
|
|
@ -1065,7 +1065,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-config"
|
name = "cosmic-config"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e"
|
source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atomicwrites",
|
"atomicwrites",
|
||||||
"cosmic-config-derive",
|
"cosmic-config-derive",
|
||||||
|
|
@ -1082,7 +1082,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-config-derive"
|
name = "cosmic-config-derive"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e"
|
source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
|
|
@ -1152,7 +1152,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-theme"
|
name = "cosmic-theme"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e"
|
source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"almost",
|
"almost",
|
||||||
"cosmic-config",
|
"cosmic-config",
|
||||||
|
|
@ -2624,7 +2624,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced"
|
name = "iced"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e"
|
source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dnd",
|
"dnd",
|
||||||
"iced_accessibility",
|
"iced_accessibility",
|
||||||
|
|
@ -2642,7 +2642,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_accessibility"
|
name = "iced_accessibility"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e"
|
source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"accesskit",
|
"accesskit",
|
||||||
"accesskit_winit",
|
"accesskit_winit",
|
||||||
|
|
@ -2651,7 +2651,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_core"
|
name = "iced_core"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e"
|
source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.5.0",
|
"bitflags 2.5.0",
|
||||||
"dnd",
|
"dnd",
|
||||||
|
|
@ -2671,7 +2671,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_futures"
|
name = "iced_futures"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e"
|
source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
|
|
@ -2684,7 +2684,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_graphics"
|
name = "iced_graphics"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e"
|
source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.5.0",
|
"bitflags 2.5.0",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
|
@ -2708,7 +2708,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_renderer"
|
name = "iced_renderer"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e"
|
source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_graphics",
|
"iced_graphics",
|
||||||
"iced_tiny_skia",
|
"iced_tiny_skia",
|
||||||
|
|
@ -2720,7 +2720,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_runtime"
|
name = "iced_runtime"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e"
|
source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dnd",
|
"dnd",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
|
|
@ -2732,7 +2732,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_style"
|
name = "iced_style"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e"
|
source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_core",
|
"iced_core",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
|
@ -2742,7 +2742,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_tiny_skia"
|
name = "iced_tiny_skia"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e"
|
source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"cosmic-text",
|
"cosmic-text",
|
||||||
|
|
@ -2759,7 +2759,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_wgpu"
|
name = "iced_wgpu"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e"
|
source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.5.0",
|
"bitflags 2.5.0",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
|
@ -2778,7 +2778,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_widget"
|
name = "iced_widget"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e"
|
source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dnd",
|
"dnd",
|
||||||
"iced_renderer",
|
"iced_renderer",
|
||||||
|
|
@ -2794,7 +2794,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_winit"
|
name = "iced_winit"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e"
|
source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dnd",
|
"dnd",
|
||||||
"iced_graphics",
|
"iced_graphics",
|
||||||
|
|
@ -3120,7 +3120,7 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libcosmic"
|
name = "libcosmic"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#1adeadacf60c7f7381ec270710fcdab706d4175e"
|
source = "git+https://github.com/pop-os/libcosmic.git?branch=nav-bar-close-icon#62c139f7f8154d5ac6ded6d53ada853c0aece0d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"apply",
|
"apply",
|
||||||
"ashpd 0.7.0",
|
"ashpd 0.7.0",
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ slotmap = "1.0.7"
|
||||||
|
|
||||||
[dependencies.libcosmic]
|
[dependencies.libcosmic]
|
||||||
git = "https://github.com/pop-os/libcosmic.git"
|
git = "https://github.com/pop-os/libcosmic.git"
|
||||||
|
branch = "nav-bar-close-icon"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["multi-window", "tokio", "winit"]
|
features = ["multi-window", "tokio", "winit"]
|
||||||
|
|
||||||
|
|
@ -77,10 +78,6 @@ test-log = "0.2"
|
||||||
# libcosmic = { path = "../libcosmic" }
|
# libcosmic = { path = "../libcosmic" }
|
||||||
# cosmic-config = { path = "../libcosmic/cosmic-config" }
|
# cosmic-config = { path = "../libcosmic/cosmic-config" }
|
||||||
# cosmic-theme = { path = "../libcosmic/cosmic-theme" }
|
# cosmic-theme = { path = "../libcosmic/cosmic-theme" }
|
||||||
# libcosmic = { git = "https://github.com/pop-os/libcosmic//", branch = "dnd" }
|
|
||||||
# cosmic-config = { git = "https://github.com/pop-os/libcosmic//", branch = "dnd" }
|
|
||||||
# cosmic-theme = { git = "https://github.com/pop-os/libcosmic//", branch = "dnd" }
|
|
||||||
|
|
||||||
# [patch.'https://github.com/pop-os/smithay-clipboard']
|
# [patch.'https://github.com/pop-os/smithay-clipboard']
|
||||||
# smithay-clipboard = { git = "https://github.com/pop-os/smithay-clipboard//", rev = "2f2430b" }
|
|
||||||
# smithay-clipboard = { path = "../smithay-clipboard" }
|
# smithay-clipboard = { path = "../smithay-clipboard" }
|
||||||
|
|
|
||||||
28
src/app.rs
28
src/app.rs
|
|
@ -182,6 +182,7 @@ pub enum Message {
|
||||||
Modifiers(Modifiers),
|
Modifiers(Modifiers),
|
||||||
MoveToTrash(Option<Entity>),
|
MoveToTrash(Option<Entity>),
|
||||||
MounterItems(MounterKey, MounterItems),
|
MounterItems(MounterKey, MounterItems),
|
||||||
|
NavBarClose(Entity),
|
||||||
NavBarContext(Entity),
|
NavBarContext(Entity),
|
||||||
NavMenuAction(NavMenuAction),
|
NavMenuAction(NavMenuAction),
|
||||||
NewItem(Option<Entity>, bool),
|
NewItem(Option<Entity>, bool),
|
||||||
|
|
@ -734,7 +735,13 @@ impl Application for App {
|
||||||
cosmic::app::Message::App(Message::DndDropNav(entity, data, action))
|
cosmic::app::Message::App(Message::DndDropNav(entity, data, action))
|
||||||
})
|
})
|
||||||
.on_context(|entity| cosmic::app::Message::App(Message::NavBarContext(entity)))
|
.on_context(|entity| cosmic::app::Message::App(Message::NavBarContext(entity)))
|
||||||
|
.on_close(|entity| cosmic::app::Message::App(Message::NavBarClose(entity)))
|
||||||
.context_menu(self.nav_context_menu(self.nav_bar_context_id))
|
.context_menu(self.nav_context_menu(self.nav_bar_context_id))
|
||||||
|
.close_icon(
|
||||||
|
widget::icon::from_name("media-eject-symbolic")
|
||||||
|
.size(16)
|
||||||
|
.icon(),
|
||||||
|
)
|
||||||
.into_container();
|
.into_container();
|
||||||
|
|
||||||
if !self.core().is_condensed() {
|
if !self.core().is_condensed() {
|
||||||
|
|
@ -1065,15 +1072,7 @@ impl Application for App {
|
||||||
let mut entity = self
|
let mut entity = self
|
||||||
.nav_model
|
.nav_model
|
||||||
.insert()
|
.insert()
|
||||||
.text(format!(
|
.text(item.name())
|
||||||
"{} ({})",
|
|
||||||
item.name(),
|
|
||||||
if item.is_mounted() {
|
|
||||||
"mounted"
|
|
||||||
} else {
|
|
||||||
"not mounted"
|
|
||||||
}
|
|
||||||
))
|
|
||||||
.data(MounterData(key, item.clone()));
|
.data(MounterData(key, item.clone()));
|
||||||
if let Some(path) = item.path() {
|
if let Some(path) = item.path() {
|
||||||
entity = entity.data(Location::Path(path.clone()));
|
entity = entity.data(Location::Path(path.clone()));
|
||||||
|
|
@ -1081,6 +1080,9 @@ impl Application for App {
|
||||||
if let Some(icon) = item.icon() {
|
if let Some(icon) = item.icon() {
|
||||||
entity = entity.icon(widget::icon::icon(icon).size(16));
|
entity = entity.icon(widget::icon::icon(icon).size(16));
|
||||||
}
|
}
|
||||||
|
if item.is_mounted() {
|
||||||
|
entity = entity.closable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::NewItem(entity_opt, dir) => {
|
Message::NewItem(entity_opt, dir) => {
|
||||||
|
|
@ -1650,6 +1652,14 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Message::NavBarClose(entity) => {
|
||||||
|
if let Some(data) = self.nav_model.data::<MounterData>(entity) {
|
||||||
|
if let Some(mounter) = self.mounters.get(&data.0) {
|
||||||
|
return mounter.unmount(data.1.clone()).map(|_| message::none());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Tracks which nav bar item to show a context menu for.
|
// Tracks which nav bar item to show a context menu for.
|
||||||
Message::NavBarContext(entity) => {
|
Message::NavBarContext(entity) => {
|
||||||
self.nav_bar_context_id = entity;
|
self.nav_bar_context_id = entity;
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ fn gio_icon_to_path(icon: &gio::Icon, size: u16) -> Option<PathBuf> {
|
||||||
enum Cmd {
|
enum Cmd {
|
||||||
Rescan,
|
Rescan,
|
||||||
Mount(MounterItem),
|
Mount(MounterItem),
|
||||||
|
Unmount(MounterItem),
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Event {
|
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> {
|
fn subscription(&self) -> subscription::Subscription<MounterItems> {
|
||||||
let command_tx = self.command_tx.clone();
|
let command_tx = self.command_tx.clone();
|
||||||
let event_rx = self.event_rx.clone();
|
let event_rx = self.event_rx.clone();
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ pub type MounterItems = Vec<MounterItem>;
|
||||||
pub trait Mounter {
|
pub trait Mounter {
|
||||||
//TODO: send result
|
//TODO: send result
|
||||||
fn mount(&self, item: MounterItem) -> Command<()>;
|
fn mount(&self, item: MounterItem) -> Command<()>;
|
||||||
|
fn unmount(&self, item: MounterItem) -> Command<()>;
|
||||||
fn subscription(&self) -> subscription::Subscription<MounterItems>;
|
fn subscription(&self) -> subscription::Subscription<MounterItems>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue