summaryrefslogtreecommitdiffstats
path: root/src/removable_devices.rs
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-10-26 17:13:33 +0200
committerqkzk <qu3nt1n@gmail.com>2023-10-26 17:13:33 +0200
commit37a36500a368d8e150534f09fde4efe557f858c7 (patch)
treeba336e5d0fc485b47f46030a07a52957dea3ef63 /src/removable_devices.rs
parent7d46af336f214d1acc03afd8b7a13dfb1f655fa1 (diff)
removable not working, wrong command passed to gio, everything else looks good
Diffstat (limited to 'src/removable_devices.rs')
-rw-r--r--src/removable_devices.rs48
1 files changed, 43 insertions, 5 deletions
diff --git a/src/removable_devices.rs b/src/removable_devices.rs
index a67e8a9..6f793f8 100644
--- a/src/removable_devices.rs
+++ b/src/removable_devices.rs
@@ -1,5 +1,4 @@
use anyhow::{anyhow, Result};
-use log::info;
use crate::{constant_strings_paths::GIO, impl_selectable_content};
@@ -36,6 +35,14 @@ impl RemovableDevices {
Some(Self { content, index: 0 })
}
}
+
+ pub fn current(&mut self) -> Option<&mut Removable> {
+ if self.content.is_empty() {
+ None
+ } else {
+ Some(&mut self.content[self.index])
+ }
+ }
}
#[derive(Debug, Clone, Default)]
@@ -47,19 +54,50 @@ pub struct Removable {
impl Removable {
fn from_gio(line: String) -> Result<Self> {
- let line = line.replace("activation_root=", "");
- let device_name = line.replace("mtp:://", "");
+ let line = line.replace("activation_root=mtp://", "");
+ let device_name = line;
let uid = users::get_current_uid();
- let path = format!("/run/user/{uid}/gvfs/{line}");
+ let path = format!("/run/user/{uid}/gvfs/mtp:host={device_name}");
let pb_path = std::path::Path::new(&path);
let is_mounted = pb_path.exists() && pb_path.read_dir()?.next().is_some();
- log::info!("gio {line} - is_mounted {is_mounted}");
+ log::info!("gio {device_name} - is_mounted {is_mounted}");
Ok(Self {
device_name,
path,
is_mounted,
})
}
+
+ pub fn mount(&mut self) -> Result<()> {
+ if self.is_mounted {
+ return Err(anyhow!("Already mounted {name}", name = self.device_name));
+ }
+ self.is_mounted = std::process::Command::new(GIO)
+ .args(vec![
+ "mount",
+ &format!("mtp://{name}", name = self.device_name),
+ ])
+ .spawn()?
+ .wait()?
+ .success();
+ Ok(())
+ }
+
+ pub fn umount(&mut self) -> Result<()> {
+ if !self.is_mounted {
+ return Err(anyhow!("Not mounted {name}", name = self.device_name));
+ }
+ self.is_mounted = std::process::Command::new(GIO)
+ .args(vec![
+ "mount",
+ &format!("mtp://{name}", name = self.device_name),
+ "-u",
+ ])
+ .spawn()?
+ .wait()?
+ .success();
+ Ok(())
+ }
}
impl_selectable_content!(Removable, RemovableDevices);