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 std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Block {
|
||||
|
@ -36,10 +30,10 @@ pub async fn collect_drives_from_udisk() -> udisks2::Result<Vec<Drive>> {
|
|||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|(object_path, _)| {
|
||||
let Ok(obj) = client.object(object_path.clone()) else {
|
||||
return None;
|
||||
};
|
||||
Some((object_path, obj))
|
||||
client
|
||||
.object(object_path.clone())
|
||||
.ok()
|
||||
.map(|obj| (object_path, obj))
|
||||
});
|
||||
|
||||
for (path, i) in objects {
|
||||
|
@ -106,7 +100,7 @@ pub async fn collect_all() -> udisks2::Result<Vec<Drive>> {
|
|||
for i in mounts {
|
||||
let block = drives
|
||||
.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));
|
||||
if let Some(block) = block {
|
||||
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<()> {
|
||||
let mut drives: Vec<Drive> = Vec::new();
|
||||
let client = udisks2::Client::new().await?;
|
||||
|
||||
client
|
||||
|
@ -143,13 +136,10 @@ pub async fn mount(block: &Block) -> udisks2::Result<()> {
|
|||
.mount(HashMap::new())
|
||||
.await?;
|
||||
|
||||
// client.part
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn unmount(block: &Block) -> udisks2::Result<()> {
|
||||
let mut drives: Vec<Drive> = Vec::new();
|
||||
let client = udisks2::Client::new().await?;
|
||||
|
||||
client
|
||||
|
@ -158,7 +148,6 @@ pub async fn unmount(block: &Block) -> udisks2::Result<()> {
|
|||
.await?
|
||||
.unmount(HashMap::new())
|
||||
.await?;
|
||||
// client.part
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
23
src/main.rs
23
src/main.rs
|
@ -1,21 +1,13 @@
|
|||
mod drives;
|
||||
mod mountpoints;
|
||||
|
||||
use std::{
|
||||
ffi::{OsStr, OsString},
|
||||
io::stderr,
|
||||
os::unix::ffi::{OsStrExt, OsStringExt},
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
use std::{io::stderr, sync::Arc, time::Duration};
|
||||
|
||||
use crossterm::{
|
||||
event::{Event, EventStream, KeyCode, KeyEventKind},
|
||||
execute,
|
||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||
};
|
||||
use drives::Drive;
|
||||
use mountpoints::MountPoint;
|
||||
use ratatui::{
|
||||
layout::{Alignment, Constraint, Layout},
|
||||
prelude::CrosstermBackend,
|
||||
|
@ -29,12 +21,6 @@ use ratatui::{
|
|||
use tokio::sync::Mutex;
|
||||
use tokio_stream::StreamExt;
|
||||
|
||||
enum Command {
|
||||
None,
|
||||
Mount(String),
|
||||
Umount(String),
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> udisks2::Result<()> {
|
||||
enable_raw_mode().unwrap();
|
||||
|
@ -134,9 +120,10 @@ fn draw(
|
|||
i.dev.clone(),
|
||||
i.label.clone(),
|
||||
i.mount.clone().unwrap_or_default(),
|
||||
match i.mounted {
|
||||
true => "M".to_owned(),
|
||||
false => "O".to_owned(),
|
||||
if i.mounted {
|
||||
"M".to_owned()
|
||||
} else {
|
||||
"O".to_owned()
|
||||
},
|
||||
])
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue