mirror of
https://github.com/SL-RU/mmtui.git
synced 2025-03-04 00:14:45 +01:00
linter fixes
This commit is contained in:
parent
3fa98701d5
commit
8616b07809
2 changed files with 11 additions and 35 deletions
|
@ -1,11 +1,5 @@
|
||||||
use std::{
|
|
||||||
collections::HashMap,
|
|
||||||
ffi::{OsStr, OsString},
|
|
||||||
os::unix::ffi::{OsStrExt, OsStringExt},
|
|
||||||
sync::{Arc, Mutex},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::mountpoints;
|
use crate::mountpoints;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Block {
|
pub struct Block {
|
||||||
|
@ -36,10 +30,10 @@ pub async fn collect_drives_from_udisk() -> udisks2::Result<Vec<Drive>> {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
.filter_map(|(object_path, _)| {
|
.filter_map(|(object_path, _)| {
|
||||||
let Ok(obj) = client.object(object_path.clone()) else {
|
client
|
||||||
return None;
|
.object(object_path.clone())
|
||||||
};
|
.ok()
|
||||||
Some((object_path, obj))
|
.map(|obj| (object_path, obj))
|
||||||
});
|
});
|
||||||
|
|
||||||
for (path, i) in objects {
|
for (path, i) in objects {
|
||||||
|
@ -106,7 +100,7 @@ pub async fn collect_all() -> udisks2::Result<Vec<Drive>> {
|
||||||
for i in mounts {
|
for i in mounts {
|
||||||
let block = drives
|
let block = drives
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.find(|d| d.blocks.iter().find(|b| b.dev == i.dev).is_some())
|
.find(|d| d.blocks.iter().any(|b| b.dev == i.dev))
|
||||||
.and_then(|d| d.blocks.iter_mut().find(|b| b.dev == i.dev));
|
.and_then(|d| d.blocks.iter_mut().find(|b| b.dev == i.dev));
|
||||||
if let Some(block) = block {
|
if let Some(block) = block {
|
||||||
block.mount = i.path;
|
block.mount = i.path;
|
||||||
|
@ -133,7 +127,6 @@ pub async fn collect_all() -> udisks2::Result<Vec<Drive>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn mount(block: &Block) -> udisks2::Result<()> {
|
pub async fn mount(block: &Block) -> udisks2::Result<()> {
|
||||||
let mut drives: Vec<Drive> = Vec::new();
|
|
||||||
let client = udisks2::Client::new().await?;
|
let client = udisks2::Client::new().await?;
|
||||||
|
|
||||||
client
|
client
|
||||||
|
@ -143,13 +136,10 @@ pub async fn mount(block: &Block) -> udisks2::Result<()> {
|
||||||
.mount(HashMap::new())
|
.mount(HashMap::new())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// client.part
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn unmount(block: &Block) -> udisks2::Result<()> {
|
pub async fn unmount(block: &Block) -> udisks2::Result<()> {
|
||||||
let mut drives: Vec<Drive> = Vec::new();
|
|
||||||
let client = udisks2::Client::new().await?;
|
let client = udisks2::Client::new().await?;
|
||||||
|
|
||||||
client
|
client
|
||||||
|
@ -158,7 +148,6 @@ pub async fn unmount(block: &Block) -> udisks2::Result<()> {
|
||||||
.await?
|
.await?
|
||||||
.unmount(HashMap::new())
|
.unmount(HashMap::new())
|
||||||
.await?;
|
.await?;
|
||||||
// client.part
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
23
src/main.rs
23
src/main.rs
|
@ -1,21 +1,13 @@
|
||||||
mod drives;
|
mod drives;
|
||||||
mod mountpoints;
|
mod mountpoints;
|
||||||
|
|
||||||
use std::{
|
use std::{io::stderr, sync::Arc, time::Duration};
|
||||||
ffi::{OsStr, OsString},
|
|
||||||
io::stderr,
|
|
||||||
os::unix::ffi::{OsStrExt, OsStringExt},
|
|
||||||
sync::Arc,
|
|
||||||
time::Duration,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
event::{Event, EventStream, KeyCode, KeyEventKind},
|
event::{Event, EventStream, KeyCode, KeyEventKind},
|
||||||
execute,
|
execute,
|
||||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||||
};
|
};
|
||||||
use drives::Drive;
|
|
||||||
use mountpoints::MountPoint;
|
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::{Alignment, Constraint, Layout},
|
layout::{Alignment, Constraint, Layout},
|
||||||
prelude::CrosstermBackend,
|
prelude::CrosstermBackend,
|
||||||
|
@ -29,12 +21,6 @@ use ratatui::{
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use tokio_stream::StreamExt;
|
use tokio_stream::StreamExt;
|
||||||
|
|
||||||
enum Command {
|
|
||||||
None,
|
|
||||||
Mount(String),
|
|
||||||
Umount(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> udisks2::Result<()> {
|
async fn main() -> udisks2::Result<()> {
|
||||||
enable_raw_mode().unwrap();
|
enable_raw_mode().unwrap();
|
||||||
|
@ -134,9 +120,10 @@ fn draw(
|
||||||
i.dev.clone(),
|
i.dev.clone(),
|
||||||
i.label.clone(),
|
i.label.clone(),
|
||||||
i.mount.clone().unwrap_or_default(),
|
i.mount.clone().unwrap_or_default(),
|
||||||
match i.mounted {
|
if i.mounted {
|
||||||
true => "M".to_owned(),
|
"M".to_owned()
|
||||||
false => "O".to_owned(),
|
} else {
|
||||||
|
"O".to_owned()
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue