Watch: Add "Toggle Dashboard" button by default, Toast: Show user-specific error messages in various places, WayVR: Modify example env vars

This commit is contained in:
Aleksander
2025-01-19 00:53:59 +01:00
parent bbed686a5e
commit 6c95607d44
12 changed files with 155 additions and 78 deletions

View File

@@ -19,14 +19,14 @@ use crate::{
config::{save_layout, save_settings, AStrSetExt},
hid::VirtualKey,
overlays::{
toast::{Toast, ToastTopic},
toast::{error_toast, Toast, ToastTopic},
watch::WATCH_NAME,
},
state::AppState,
};
#[cfg(feature = "wayvr")]
use crate::overlays::wayvr::WayVRAction;
#[cfg(not(feature = "wayvr"))]
use crate::overlays::toast::error_toast_str;
use super::{ExecArgs, ModularControl, ModularData};
@@ -119,6 +119,26 @@ pub enum WindowAction {
Destroy,
}
#[derive(Deserialize, Clone)]
pub enum WayVRDisplayClickAction {
ToggleVisibility,
Reset,
}
#[derive(Deserialize, Clone)]
#[allow(dead_code)] // in case if WayVR feature is disabled
pub enum WayVRAction {
AppClick {
catalog_name: Arc<str>,
app_name: Arc<str>,
},
DisplayClick {
display_name: Arc<str>,
action: WayVRDisplayClickAction,
},
ToggleDashboard,
}
#[derive(Deserialize, Clone)]
#[serde(tag = "type")]
pub enum ButtonAction {
@@ -137,8 +157,10 @@ pub enum ButtonAction {
target: OverlaySelector,
action: OverlayAction,
},
#[cfg(feature = "wayvr")]
WayVR(WayVRAction),
// Ignored if "wayvr" feature is not enabled
WayVR {
action: WayVRAction,
},
Window {
target: Arc<str>,
action: WindowAction,
@@ -332,9 +354,16 @@ fn handle_action(action: &ButtonAction, press: &mut PressData, app: &mut AppStat
ButtonAction::Watch { action } => run_watch(action, app),
ButtonAction::Overlay { target, action } => run_overlay(target, action, app),
ButtonAction::Window { target, action } => run_window(target, action, app),
#[cfg(feature = "wayvr")]
ButtonAction::WayVR(action) => {
app.tasks.enqueue(TaskType::WayVR(action.clone()));
ButtonAction::WayVR { action } => {
#[cfg(feature = "wayvr")]
{
app.tasks.enqueue(TaskType::WayVR(action.clone()));
}
#[cfg(not(feature = "wayvr"))]
{
let _ = &action;
error_toast_str(app, "WayVR feature is not enabled");
}
}
ButtonAction::VirtualKey { keycode, action } => app
.hid_provider
@@ -461,12 +490,12 @@ fn run_system(action: &SystemAction, app: &mut AppState) {
}
SystemAction::PersistConfig => {
if let Err(e) = save_settings(&app.session.config) {
log::error!("Failed to save config: {:?}", e);
error_toast(app, "Failed to save config", e);
}
}
SystemAction::PersistLayout => {
if let Err(e) = save_layout(&app.session.config) {
log::error!("Failed to save layout: {:?}", e);
error_toast(app, "Failed to save layout", e);
}
}
}
@@ -477,7 +506,7 @@ fn run_exec(args: &ExecArgs, toast: &Option<Arc<str>>, press: &mut PressData, ap
match proc.try_wait() {
Ok(Some(code)) => {
if !code.success() {
log::error!("Child process exited with code: {}", code);
error_toast(app, "Child process exited with code", code);
}
press.child = None;
}
@@ -487,7 +516,7 @@ fn run_exec(args: &ExecArgs, toast: &Option<Arc<str>>, press: &mut PressData, ap
}
Err(e) => {
press.child = None;
log::error!("Error checking child process: {:?}", e);
error_toast(app, "Error checking child process", e);
}
}
}
@@ -500,7 +529,7 @@ fn run_exec(args: &ExecArgs, toast: &Option<Arc<str>>, press: &mut PressData, ap
}
}
Err(e) => {
log::error!("Failed to spawn process {:?}: {:?}", args, e);
error_toast(app, &format!("Failed to spawn process {:?}", args), e);
}
};
}
@@ -651,7 +680,9 @@ fn run_overlay(overlay: &OverlaySelector, action: &OverlayAction, app: &mut AppS
if state_dirty {
match save_layout(&app.session.config) {
Ok(_) => log::debug!("Saved state"),
Err(e) => log::error!("Failed to save state: {:?}", e),
Err(e) => {
error_toast(app, "Failed to save state", e);
}
}
}
}),

View File

@@ -9,7 +9,11 @@ use std::{
time::Instant,
};
use crate::{gui::modular::FALLBACK_COLOR, state::AppState};
use crate::{
gui::modular::FALLBACK_COLOR,
overlays::toast::{error_toast, error_toast_str},
state::AppState,
};
use serde::Deserialize;
@@ -233,14 +237,21 @@ pub(super) fn label_update(control: &mut ModularControl, _: &mut (), app: &mut A
match proc.try_wait() {
Ok(Some(code)) => {
if !code.success() {
log::error!("Child process exited with code: {}", code);
error_toast(
app,
"LabelData::Exec: Child process exited with code",
code,
);
} else {
if let Some(mut stdout) = proc.stdout.take() {
let mut buf = String::new();
if stdout.read_to_string(&mut buf).is_ok() {
control.set_text(&buf);
} else {
log::error!("Failed to read stdout for child process");
error_toast_str(
app,
"LabelData::Exec: Failed to read stdout for child process",
);
return;
}
return;
@@ -256,7 +267,7 @@ pub(super) fn label_update(control: &mut ModularControl, _: &mut (), app: &mut A
}
Err(e) => {
*child = None;
log::error!("Error checking child process: {:?}", e);
error_toast(app, "Error checking child process", e);
return;
}
}
@@ -282,7 +293,7 @@ pub(super) fn label_update(control: &mut ModularControl, _: &mut (), app: &mut A
*child = Some(proc);
}
Err(e) => {
log::error!("Failed to spawn process {:?}: {:?}", args, e);
error_toast(app, &format!("Failed to spawn process {:?}", args), e);
}
};
}

View File

@@ -3,6 +3,9 @@ pub mod label;
use std::{fs::File, sync::Arc};
#[cfg(feature = "wayvr")]
use button::{WayVRAction, WayVRDisplayClickAction};
use glam::Vec4;
use serde::Deserialize;
use vulkano::{command_buffer::CommandBufferUsage, image::view::ImageView};
@@ -12,9 +15,6 @@ use crate::{
graphics::dds::WlxCommandBufferDds, state::AppState,
};
#[cfg(feature = "wayvr")]
use crate::overlays::wayvr::{WayVRAction, WayVRDisplayClickAction};
use self::{
button::{modular_button_init, ButtonAction, ButtonData, OverlayAction},
label::{modular_label_init, LabelContent, LabelData},
@@ -452,10 +452,12 @@ pub fn modular_canvas(
);
let data = ButtonData {
click_up: Some(vec![ButtonAction::WayVR(WayVRAction::AppClick {
catalog_name: catalog_name.clone(),
app_name: Arc::from(app.name.as_str()),
})]),
click_up: Some(vec![ButtonAction::WayVR {
action: WayVRAction::AppClick {
catalog_name: catalog_name.clone(),
app_name: Arc::from(app.name.as_str()),
},
}]),
..Default::default()
};
@@ -502,16 +504,18 @@ pub fn modular_canvas(
);
let data = ButtonData {
click_up: Some(vec![ButtonAction::WayVR(WayVRAction::DisplayClick {
display_name: Arc::from(display_name.as_str()),
action: WayVRDisplayClickAction::ToggleVisibility,
})]),
long_click_up: Some(vec![ButtonAction::WayVR(
WayVRAction::DisplayClick {
click_up: Some(vec![ButtonAction::WayVR {
action: WayVRAction::DisplayClick {
display_name: Arc::from(display_name.as_str()),
action: WayVRDisplayClickAction::ToggleVisibility,
},
}]),
long_click_up: Some(vec![ButtonAction::WayVR {
action: WayVRAction::DisplayClick {
display_name: Arc::from(display_name.as_str()),
action: WayVRDisplayClickAction::Reset,
},
)]),
}]),
..Default::default()
};