📦📎-fixes, typo fixes

This commit is contained in:
Aleksander
2025-09-20 12:17:17 +02:00
parent cfb733de09
commit b9e5541971
41 changed files with 494 additions and 498 deletions

View File

@@ -11,7 +11,7 @@ use wgui::{
use crate::{
backend::{common::OverlaySelector, overlay::OverlayID, task::TaskType, wayvr::WayVRAction},
config::{save_layout, AStrSetExt},
config::{AStrSetExt, save_layout},
state::AppState,
};
@@ -21,14 +21,14 @@ pub(super) fn setup_custom_button<S>(
attribs: &CustomAttribsInfoOwned,
listeners: &mut EventListenerCollection<AppState, S>,
listener_handles: &mut ListenerHandleVec,
app: &AppState,
_app: &AppState,
) {
const EVENTS: [(&str, EventListenerKind); 2] = [
("press", EventListenerKind::MousePress),
("release", EventListenerKind::MouseRelease),
];
for (name, kind) in EVENTS.iter() {
for (name, kind) in &EVENTS {
let Some(action) = attribs.get_value(name) else {
continue;
};
@@ -47,14 +47,14 @@ pub(super) fn setup_custom_button<S>(
}),
"::OverlayToggle" => {
let Some(selector) = args.next() else {
log::warn!("Missing argument for {}", command);
log::warn!("Missing argument for {command}");
continue;
};
let selector = selector
.parse::<usize>()
.map(|id| OverlaySelector::Id(OverlayID { 0: id }))
.unwrap_or_else(|_| OverlaySelector::Name(selector.into()));
let selector = selector.parse::<usize>().map_or_else(
|_| OverlaySelector::Name(selector.into()),
|id| OverlaySelector::Id(OverlayID(id)),
);
Box::new(move |_common, _data, app, _| {
app.tasks.enqueue(TaskType::Overlay(
@@ -90,7 +90,11 @@ pub(super) fn setup_custom_button<S>(
}
"::WatchHide" => todo!(),
"::WatchSwapHand" => todo!(),
// TODO
#[allow(clippy::match_same_arms)]
"::EditToggle" => return,
// TODO
#[allow(clippy::match_same_arms)]
"::OscSend" => return,
// shell
_ => todo!(),
@@ -110,18 +114,20 @@ struct ShellButtonState {
carry_over: RefCell<Option<String>>,
}
// TODO
#[allow(clippy::missing_const_for_fn)]
fn shell_on_action(
state: &ShellButtonState,
common: &mut event::CallbackDataCommon,
data: &mut event::CallbackData,
_state: &ShellButtonState,
_common: &mut event::CallbackDataCommon,
_data: &mut event::CallbackData,
) {
let mut mut_state = state.mut_state.borrow_mut();
//let mut mut_state = state.mut_state.borrow_mut();
}
fn shell_on_tick(
state: &ShellButtonState,
common: &mut event::CallbackDataCommon,
data: &mut event::CallbackData,
_common: &mut event::CallbackDataCommon,
_data: &mut event::CallbackData,
) {
let mut mut_state = state.mut_state.borrow_mut();
@@ -129,8 +135,8 @@ fn shell_on_tick(
match child.try_wait() {
// not exited yet
Ok(None) => {
if let Some(text) = mut_state.reader.as_mut().and_then(|r| {
read_label_from_pipe("child process", r, &mut *state.carry_over.borrow_mut())
if let Some(_text) = mut_state.reader.as_mut().and_then(|r| {
read_label_from_pipe("child process", r, &mut state.carry_over.borrow_mut())
}) {
//TODO update label
}
@@ -138,8 +144,8 @@ fn shell_on_tick(
}
// exited successfully
Ok(Some(code)) if code.success() => {
if let Some(text) = mut_state.reader.as_mut().and_then(|r| {
read_label_from_pipe("child process", r, &mut *state.carry_over.borrow_mut())
if let Some(_text) = mut_state.reader.as_mut().and_then(|r| {
read_label_from_pipe("child process", r, &mut state.carry_over.borrow_mut())
}) {
//TODO update label
}
@@ -148,7 +154,7 @@ fn shell_on_tick(
// exited with failure
Ok(Some(code)) => {
mut_state.child = None;
log::warn!("Label process exited with code {}", code);
log::warn!("Label process exited with code {code}");
}
// lost
Err(_) => {

View File

@@ -11,7 +11,7 @@ static ENV_VAR_REGEX: LazyLock<Regex> = LazyLock::new(|| {
pub(super) fn expand_env_vars(template: &str) -> String {
ENV_VAR_REGEX
.replace_all(template, |caps: &regex::Captures| {
let var_name = caps.get(1).or(caps.get(2)).unwrap().as_str();
let var_name = caps.get(1).or_else(|| caps.get(2)).unwrap().as_str();
std::env::var(var_name)
.inspect_err(|e| log::warn!("Unable to substitute env var {var_name}: {e:?}"))
.unwrap_or_default()
@@ -45,9 +45,5 @@ where
carry_over.replace(cur);
if prev.len() > 0 {
Some(prev)
} else {
None
}
if prev.is_empty() { None } else { Some(prev) }
}

View File

@@ -15,7 +15,7 @@ use wgui::{
event::{self, EventCallback, EventListenerCollection, ListenerHandleVec},
i18n::Translation,
layout::Layout,
parser::{parse_color_hex, CustomAttribsInfoOwned},
parser::{CustomAttribsInfoOwned, parse_color_hex},
widget::label::WidgetLabel,
};
@@ -23,6 +23,7 @@ use crate::state::AppState;
use super::helper::{expand_env_vars, read_label_from_pipe};
#[allow(clippy::too_many_lines)]
pub(super) fn setup_custom_label<S>(
layout: &mut Layout,
attribs: &CustomAttribsInfoOwned,
@@ -85,15 +86,15 @@ pub(super) fn setup_custom_label<S>(
let state = BatteryLabelState {
low_color: attribs
.get_value("low_color")
.and_then(|s| parse_color_hex(s))
.and_then(parse_color_hex)
.unwrap_or(BAT_LOW),
normal_color: attribs
.get_value("normal_color")
.and_then(|s| parse_color_hex(s))
.and_then(parse_color_hex)
.unwrap_or(BAT_NORMAL),
charging_color: attribs
.get_value("charging_color")
.and_then(|s| parse_color_hex(s))
.and_then(parse_color_hex)
.unwrap_or(BAT_CHARGING),
low_threshold: attribs
.get_value("low_threshold")
@@ -122,10 +123,7 @@ pub(super) fn setup_custom_label<S>(
tz_name.split('/').next_back().map(|x| x.replace('_', " "))
});
let pretty_tz = match maybe_pretty_tz.as_ref() {
Some(x) => x.as_str(),
None => "Local",
};
let pretty_tz = maybe_pretty_tz.as_ref().map_or("Local", |x| x.as_str());
let mut i18n = layout.state.globals.i18n();
layout
@@ -133,7 +131,7 @@ pub(super) fn setup_custom_label<S>(
.widgets
.get_as::<WidgetLabel>(attribs.widget_id)
.unwrap()
.set_text_simple(&mut *i18n, Translation::from_raw_text(&pretty_tz));
.set_text_simple(&mut i18n, Translation::from_raw_text(pretty_tz));
// does not need to be dynamic
return;
@@ -202,6 +200,7 @@ struct ShellLabelState {
carry_over: RefCell<Option<String>>,
}
#[allow(clippy::redundant_else)]
fn shell_on_tick(
state: &ShellLabelState,
common: &mut event::CallbackDataCommon,
@@ -214,7 +213,7 @@ fn shell_on_tick(
// not exited yet
Ok(None) => {
if let Some(text) = mut_state.reader.as_mut().and_then(|r| {
read_label_from_pipe("child process", r, &mut *state.carry_over.borrow_mut())
read_label_from_pipe("child process", r, &mut state.carry_over.borrow_mut())
}) {
let label = data.obj.get_as_mut::<WidgetLabel>().unwrap();
label.set_text(common, Translation::from_raw_text(&text));
@@ -225,7 +224,7 @@ fn shell_on_tick(
// exited successfully
Ok(Some(code)) if code.success() => {
if let Some(text) = mut_state.reader.as_mut().and_then(|r| {
read_label_from_pipe("child process", r, &mut *state.carry_over.borrow_mut())
read_label_from_pipe("child process", r, &mut state.carry_over.borrow_mut())
}) {
let label = data.obj.get_as_mut::<WidgetLabel>().unwrap();
label.set_text(common, Translation::from_raw_text(&text));
@@ -237,7 +236,7 @@ fn shell_on_tick(
Ok(Some(code)) => {
mut_state.child = None;
mut_state.next_try = Instant::now() + Duration::from_secs(15);
log::warn!("Label process exited with code {}", code);
log::warn!("Label process exited with code {code}");
return;
}
// lost
@@ -248,10 +247,8 @@ fn shell_on_tick(
return;
}
}
} else {
if mut_state.next_try > Instant::now() {
return;
}
} else if mut_state.next_try > Instant::now() {
return;
}
match Command::new("sh")
@@ -266,7 +263,7 @@ fn shell_on_tick(
mut_state.reader = Some(io::BufReader::new(stdout));
}
Err(e) => {
log::warn!("Failed to run shell script '{}': {e:?}", &state.exec)
log::warn!("Failed to run shell script '{}': {e:?}", &state.exec);
}
}
}
@@ -300,7 +297,7 @@ impl FifoLabelState {
if let Err(e) = fs::remove_file(&self.path) {
anyhow::bail!("Unable to remove existing FIFO at {}: {e:?}", &self.path);
};
}
Ok(())
}
@@ -321,39 +318,38 @@ fn pipe_on_tick(
) {
let mut mut_state = state.mut_state.borrow_mut();
let reader = match mut_state.reader.as_mut() {
Some(f) => f,
None => {
if mut_state.next_try > Instant::now() {
return;
}
if let Err(e) = state.try_remove_fifo() {
mut_state.next_try = Instant::now() + Duration::from_secs(15);
log::warn!("Requested FIFO path is taken: {e:?}");
return;
}
if let Err(e) = create_fifo(&state.path, 0o777) {
mut_state.next_try = Instant::now() + Duration::from_secs(15);
log::warn!("Failed to create FIFO: {e:?}");
return;
}
mut_state.reader = fs::File::open(&state.path)
.inspect_err(|e| {
log::warn!("Failed to open FIFO: {e:?}");
mut_state.next_try = Instant::now() + Duration::from_secs(15);
})
.map(|f| io::BufReader::new(f))
.ok();
mut_state.reader.as_mut().unwrap()
let reader = if let Some(f) = mut_state.reader.as_mut() {
f
} else {
if mut_state.next_try > Instant::now() {
return;
}
if let Err(e) = state.try_remove_fifo() {
mut_state.next_try = Instant::now() + Duration::from_secs(15);
log::warn!("Requested FIFO path is taken: {e:?}");
return;
}
if let Err(e) = create_fifo(&state.path, 0o777) {
mut_state.next_try = Instant::now() + Duration::from_secs(15);
log::warn!("Failed to create FIFO: {e:?}");
return;
}
mut_state.reader = fs::File::open(&state.path)
.inspect_err(|e| {
log::warn!("Failed to open FIFO: {e:?}");
mut_state.next_try = Instant::now() + Duration::from_secs(15);
})
.map(io::BufReader::new)
.ok();
mut_state.reader.as_mut().unwrap()
};
if let Some(text) =
read_label_from_pipe(&state.path, reader, &mut *state.carry_over.borrow_mut())
read_label_from_pipe(&state.path, reader, &mut state.carry_over.borrow_mut())
{
let label = data.obj.get_as_mut::<WidgetLabel>().unwrap();
label.set_text(common, Translation::from_raw_text(&text));
@@ -385,21 +381,21 @@ fn battery_on_tick(
let label = data.obj.get_as_mut::<WidgetLabel>().unwrap();
if let Some(device) = device {
if let Some(soc) = device.soc {
let soc = (soc * 100.).min(99.) as u32;
let text = format!("{}{}", tags[device.role as usize], soc);
let color = if device.charging {
state.charging_color
} else if soc < state.low_threshold {
state.low_color
} else {
state.normal_color
};
label.set_color(common, color, false);
label.set_text(common, Translation::from_raw_text(&text));
return;
}
if let Some(device) = device
&& let Some(soc) = device.soc
{
let soc = (soc * 100.).min(99.) as u32;
let text = format!("{}{}", tags[device.role as usize], soc);
let color = if device.charging {
state.charging_color
} else if soc < state.low_threshold {
state.low_color
} else {
state.normal_color
};
label.set_color(common, color, false);
label.set_text(common, Translation::from_raw_text(&text));
return;
}
label.set_text(common, Translation::default());
}