mirror of
https://github.com/coastalwhite/lemurs
synced 2024-11-23 02:23:07 +00:00
Refactor initrcs.rs to handle errors
This commit is contained in:
parent
ed62ac24b9
commit
563f16aa3f
1 changed files with 25 additions and 9 deletions
|
@ -1,21 +1,37 @@
|
|||
use crate::ui::WindowManager;
|
||||
|
||||
use std::fs;
|
||||
|
||||
use log::warn;
|
||||
|
||||
const INITRCS_FOLDER_PATH: &str = "/etc/lemurs/wms";
|
||||
|
||||
pub fn get_window_managers() -> Vec<WindowManager> {
|
||||
let wms = match fs::read_dir(INITRCS_FOLDER_PATH) {
|
||||
let found_paths = match fs::read_dir(INITRCS_FOLDER_PATH) {
|
||||
Ok(paths) => paths,
|
||||
Err(_) => return Vec::new(),
|
||||
};
|
||||
|
||||
wms
|
||||
.map(|entry| {
|
||||
let entry = entry.unwrap();
|
||||
WindowManager::new(
|
||||
entry.file_name().into_string().unwrap(), // TODO: Remove unwrap
|
||||
entry.path(),
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
// NOTE: Maybe we can do something smart with `with_capacity` here.
|
||||
let mut wms = Vec::new();
|
||||
|
||||
// TODO: Maybe this can be done better.
|
||||
for path in found_paths {
|
||||
if let Ok(path) = path {
|
||||
let file_name = path.file_name().into_string();
|
||||
|
||||
if let Ok(file_name) = file_name {
|
||||
wms.push(WindowManager::new(
|
||||
file_name,
|
||||
path.path(),
|
||||
));
|
||||
} else {
|
||||
warn!("Unable to convert OSString to String");
|
||||
}
|
||||
} else {
|
||||
warn!("Ignored errorinous path: '{}'", path.unwrap_err());
|
||||
}
|
||||
}
|
||||
|
||||
wms
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue