mirror of
https://codeberg.org/waydeer/layer-shika.git
synced 2026-01-22 08:15:54 +00:00
refactor: add other error variants
This commit is contained in:
parent
d7008cd065
commit
0f9fb49558
4 changed files with 49 additions and 107 deletions
|
|
@ -29,11 +29,7 @@ impl PopupShell {
|
||||||
let handle = PopupHandle::new();
|
let handle = PopupHandle::new();
|
||||||
self.sender
|
self.sender
|
||||||
.send(ShellCommand::Popup(PopupCommand::Show { handle, config }))
|
.send(ShellCommand::Popup(PopupCommand::Show { handle, config }))
|
||||||
.map_err(|_| {
|
.map_err(|_| Error::Domain(DomainError::ChannelClosed))?;
|
||||||
Error::Domain(DomainError::Configuration {
|
|
||||||
message: "Failed to send popup show command: channel closed".to_string(),
|
|
||||||
})
|
|
||||||
})?;
|
|
||||||
Ok(handle)
|
Ok(handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -423,11 +423,8 @@ impl Shell {
|
||||||
let component_definition = compilation_result
|
let component_definition = compilation_result
|
||||||
.component(&definition.component)
|
.component(&definition.component)
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
Error::Domain(DomainError::Configuration {
|
Error::Domain(DomainError::ComponentNotFound {
|
||||||
message: format!(
|
name: definition.component.clone(),
|
||||||
"Component '{}' not found in compilation result",
|
|
||||||
definition.component
|
|
||||||
),
|
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
@ -475,11 +472,8 @@ impl Shell {
|
||||||
let component_definition = compilation_result
|
let component_definition = compilation_result
|
||||||
.component(&def.component)
|
.component(&def.component)
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
Error::Domain(DomainError::Configuration {
|
Error::Domain(DomainError::ComponentNotFound {
|
||||||
message: format!(
|
name: def.component.clone(),
|
||||||
"Component '{}' not found in compilation result",
|
|
||||||
def.component
|
|
||||||
),
|
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
@ -844,8 +838,8 @@ impl Shell {
|
||||||
) -> Result<SessionLock> {
|
) -> Result<SessionLock> {
|
||||||
let component = builder.component_name().to_string();
|
let component = builder.component_name().to_string();
|
||||||
if self.compilation_result.component(&component).is_none() {
|
if self.compilation_result.component(&component).is_none() {
|
||||||
return Err(Error::Domain(DomainError::Configuration {
|
return Err(Error::Domain(DomainError::ComponentNotFound {
|
||||||
message: format!("Component '{}' not found in compilation result", component),
|
name: component,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -891,11 +885,8 @@ impl Shell {
|
||||||
.compilation_result
|
.compilation_result
|
||||||
.component(&definition.component)
|
.component(&definition.component)
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
Error::Domain(DomainError::Configuration {
|
Error::Domain(DomainError::ComponentNotFound {
|
||||||
message: format!(
|
name: definition.component.clone(),
|
||||||
"Component '{}' not found in compilation result",
|
|
||||||
definition.component
|
|
||||||
),
|
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
@ -932,7 +923,7 @@ impl Shell {
|
||||||
/// Removes and destroys a surface by its handle
|
/// Removes and destroys a surface by its handle
|
||||||
pub fn despawn_surface(&mut self, handle: SurfaceHandle) -> Result<()> {
|
pub fn despawn_surface(&mut self, handle: SurfaceHandle) -> Result<()> {
|
||||||
let entry = self.registry.remove(handle).ok_or_else(|| {
|
let entry = self.registry.remove(handle).ok_or_else(|| {
|
||||||
Error::Domain(DomainError::Configuration {
|
Error::Domain(DomainError::SurfaceNotFound {
|
||||||
message: format!("Surface handle {:?} not found", handle),
|
message: format!("Surface handle {:?} not found", handle),
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
@ -989,7 +980,7 @@ impl Shell {
|
||||||
F: FnOnce(&ComponentInstance) -> R,
|
F: FnOnce(&ComponentInstance) -> R,
|
||||||
{
|
{
|
||||||
if !self.registry.contains_name(name) {
|
if !self.registry.contains_name(name) {
|
||||||
return Err(Error::Domain(DomainError::Configuration {
|
return Err(Error::Domain(DomainError::SurfaceNotFound {
|
||||||
message: format!("Window '{}' not found", name),
|
message: format!("Window '{}' not found", name),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
@ -1002,7 +993,7 @@ impl Shell {
|
||||||
.first()
|
.first()
|
||||||
.map(|surface| f(surface.component_instance()))
|
.map(|surface| f(surface.component_instance()))
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
Error::Domain(DomainError::Configuration {
|
Error::Domain(DomainError::SurfaceNotFound {
|
||||||
message: format!("No instance found for window '{}'", name),
|
message: format!("No instance found for window '{}'", name),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -1032,7 +1023,7 @@ impl Shell {
|
||||||
.app_state()
|
.app_state()
|
||||||
.get_output_by_handle(handle)
|
.get_output_by_handle(handle)
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
Error::Domain(DomainError::Configuration {
|
Error::Domain(DomainError::OutputNotFound {
|
||||||
message: format!("Output with handle {:?} not found", handle),
|
message: format!("Output with handle {:?} not found", handle),
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
|
||||||
|
|
@ -227,11 +227,7 @@ impl ShellControl {
|
||||||
pub fn close_popup(&self, handle: PopupHandle) -> Result<()> {
|
pub fn close_popup(&self, handle: PopupHandle) -> Result<()> {
|
||||||
self.sender
|
self.sender
|
||||||
.send(ShellCommand::Popup(PopupCommand::Close(handle)))
|
.send(ShellCommand::Popup(PopupCommand::Close(handle)))
|
||||||
.map_err(|_| {
|
.map_err(|_| Error::Domain(DomainError::ChannelClosed))
|
||||||
Error::Domain(DomainError::Configuration {
|
|
||||||
message: "Failed to send popup close command: channel closed".to_string(),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resizes a popup to the specified dimensions
|
/// Resizes a popup to the specified dimensions
|
||||||
|
|
@ -258,20 +254,14 @@ impl ShellControl {
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
}))
|
}))
|
||||||
.map_err(|_| {
|
.map_err(|_| Error::Domain(DomainError::ChannelClosed))
|
||||||
Error::Domain(DomainError::Configuration {
|
|
||||||
message: "Failed to send popup resize command: channel closed".to_string(),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Requests a redraw of all surfaces
|
/// Requests a redraw of all surfaces
|
||||||
pub fn request_redraw(&self) -> Result<()> {
|
pub fn request_redraw(&self) -> Result<()> {
|
||||||
self.sender.send(ShellCommand::Render).map_err(|_| {
|
self.sender
|
||||||
Error::Domain(DomainError::Configuration {
|
.send(ShellCommand::Render)
|
||||||
message: "Failed to send redraw command: channel closed".to_string(),
|
.map_err(|_| Error::Domain(DomainError::ChannelClosed))
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a control handle for a specific surface instance
|
/// Returns a control handle for a specific surface instance
|
||||||
|
|
@ -337,11 +327,7 @@ impl SurfaceControlHandle {
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
}))
|
}))
|
||||||
.map_err(|_| {
|
.map_err(|_| Error::Domain(DomainError::ChannelClosed))
|
||||||
Error::Domain(DomainError::Configuration {
|
|
||||||
message: "Failed to send surface resize command: channel closed".to_string(),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the surface width
|
/// Sets the surface width
|
||||||
|
|
@ -361,12 +347,7 @@ impl SurfaceControlHandle {
|
||||||
target: self.target.clone(),
|
target: self.target.clone(),
|
||||||
anchor,
|
anchor,
|
||||||
}))
|
}))
|
||||||
.map_err(|_| {
|
.map_err(|_| Error::Domain(DomainError::ChannelClosed))
|
||||||
Error::Domain(DomainError::Configuration {
|
|
||||||
message: "Failed to send surface set_anchor command: channel closed"
|
|
||||||
.to_string(),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the exclusive zone for the surface
|
/// Sets the exclusive zone for the surface
|
||||||
|
|
@ -376,12 +357,7 @@ impl SurfaceControlHandle {
|
||||||
target: self.target.clone(),
|
target: self.target.clone(),
|
||||||
zone,
|
zone,
|
||||||
}))
|
}))
|
||||||
.map_err(|_| {
|
.map_err(|_| Error::Domain(DomainError::ChannelClosed))
|
||||||
Error::Domain(DomainError::Configuration {
|
|
||||||
message: "Failed to send surface set_exclusive_zone command: channel closed"
|
|
||||||
.to_string(),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the margins for the surface
|
/// Sets the margins for the surface
|
||||||
|
|
@ -391,12 +367,7 @@ impl SurfaceControlHandle {
|
||||||
target: self.target.clone(),
|
target: self.target.clone(),
|
||||||
margins: margins.into(),
|
margins: margins.into(),
|
||||||
}))
|
}))
|
||||||
.map_err(|_| {
|
.map_err(|_| Error::Domain(DomainError::ChannelClosed))
|
||||||
Error::Domain(DomainError::Configuration {
|
|
||||||
message: "Failed to send surface set_margins command: channel closed"
|
|
||||||
.to_string(),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the layer for the surface
|
/// Sets the layer for the surface
|
||||||
|
|
@ -406,11 +377,7 @@ impl SurfaceControlHandle {
|
||||||
target: self.target.clone(),
|
target: self.target.clone(),
|
||||||
layer,
|
layer,
|
||||||
}))
|
}))
|
||||||
.map_err(|_| {
|
.map_err(|_| Error::Domain(DomainError::ChannelClosed))
|
||||||
Error::Domain(DomainError::Configuration {
|
|
||||||
message: "Failed to send surface set_layer command: channel closed".to_string(),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the output policy for the surface
|
/// Sets the output policy for the surface
|
||||||
|
|
@ -420,12 +387,7 @@ impl SurfaceControlHandle {
|
||||||
target: self.target.clone(),
|
target: self.target.clone(),
|
||||||
policy,
|
policy,
|
||||||
}))
|
}))
|
||||||
.map_err(|_| {
|
.map_err(|_| Error::Domain(DomainError::ChannelClosed))
|
||||||
Error::Domain(DomainError::Configuration {
|
|
||||||
message: "Failed to send surface set_output_policy command: channel closed"
|
|
||||||
.to_string(),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the scale factor for the surface
|
/// Sets the scale factor for the surface
|
||||||
|
|
@ -435,12 +397,7 @@ impl SurfaceControlHandle {
|
||||||
target: self.target.clone(),
|
target: self.target.clone(),
|
||||||
factor,
|
factor,
|
||||||
}))
|
}))
|
||||||
.map_err(|_| {
|
.map_err(|_| Error::Domain(DomainError::ChannelClosed))
|
||||||
Error::Domain(DomainError::Configuration {
|
|
||||||
message: "Failed to send surface set_scale_factor command: channel closed"
|
|
||||||
.to_string(),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the keyboard interactivity mode for the surface
|
/// Sets the keyboard interactivity mode for the surface
|
||||||
|
|
@ -452,13 +409,7 @@ impl SurfaceControlHandle {
|
||||||
mode,
|
mode,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
.map_err(|_| {
|
.map_err(|_| Error::Domain(DomainError::ChannelClosed))
|
||||||
Error::Domain(DomainError::Configuration {
|
|
||||||
message:
|
|
||||||
"Failed to send surface set_keyboard_interactivity command: channel closed"
|
|
||||||
.to_string(),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies a complete surface configuration
|
/// Applies a complete surface configuration
|
||||||
|
|
@ -468,12 +419,7 @@ impl SurfaceControlHandle {
|
||||||
target: self.target.clone(),
|
target: self.target.clone(),
|
||||||
config,
|
config,
|
||||||
}))
|
}))
|
||||||
.map_err(|_| {
|
.map_err(|_| Error::Domain(DomainError::ChannelClosed))
|
||||||
Error::Domain(DomainError::Configuration {
|
|
||||||
message: "Failed to send surface apply_config command: channel closed"
|
|
||||||
.to_string(),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a builder for configuring multiple properties at once
|
/// Returns a builder for configuring multiple properties at once
|
||||||
|
|
@ -655,7 +601,7 @@ impl EventDispatchContext<'_> {
|
||||||
F: FnOnce(&ComponentInstance) -> R,
|
F: FnOnce(&ComponentInstance) -> R,
|
||||||
{
|
{
|
||||||
let component = self.get_surface_component(name).ok_or_else(|| {
|
let component = self.get_surface_component(name).ok_or_else(|| {
|
||||||
Error::Domain(DomainError::Configuration {
|
Error::Domain(DomainError::SurfaceNotFound {
|
||||||
message: format!("Surface '{}' not found", name),
|
message: format!("Surface '{}' not found", name),
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
@ -667,7 +613,7 @@ impl EventDispatchContext<'_> {
|
||||||
F: FnOnce(&ComponentInstance) -> R,
|
F: FnOnce(&ComponentInstance) -> R,
|
||||||
{
|
{
|
||||||
let component = self.get_output_component(handle).ok_or_else(|| {
|
let component = self.get_output_component(handle).ok_or_else(|| {
|
||||||
Error::Domain(DomainError::Configuration {
|
Error::Domain(DomainError::OutputNotFound {
|
||||||
message: format!("Output with handle {:?} not found", handle),
|
message: format!("Output with handle {:?} not found", handle),
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
@ -811,11 +757,8 @@ impl EventDispatchContext<'_> {
|
||||||
"Component '{}' not found in compilation result",
|
"Component '{}' not found in compilation result",
|
||||||
config.component
|
config.component
|
||||||
);
|
);
|
||||||
Error::Domain(DomainError::Configuration {
|
Error::Domain(DomainError::ComponentNotFound {
|
||||||
message: format!(
|
name: config.component.clone(),
|
||||||
"{} component not found in compilation result",
|
|
||||||
config.component
|
|
||||||
),
|
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
@ -824,7 +767,7 @@ impl EventDispatchContext<'_> {
|
||||||
let is_using_active = self.app_state.active_output().is_some();
|
let is_using_active = self.app_state.active_output().is_some();
|
||||||
let active_surface = self.active_or_primary_output().ok_or_else(|| {
|
let active_surface = self.active_or_primary_output().ok_or_else(|| {
|
||||||
log::error!("No active or primary output available");
|
log::error!("No active or primary output available");
|
||||||
Error::Domain(DomainError::Configuration {
|
Error::Domain(DomainError::OutputNotFound {
|
||||||
message: "No active or primary output available".to_string(),
|
message: "No active or primary output available".to_string(),
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
@ -835,7 +778,7 @@ impl EventDispatchContext<'_> {
|
||||||
);
|
);
|
||||||
|
|
||||||
let popup_manager = active_surface.popup_manager().ok_or_else(|| {
|
let popup_manager = active_surface.popup_manager().ok_or_else(|| {
|
||||||
Error::Domain(DomainError::Configuration {
|
Error::Domain(DomainError::SurfaceNotFound {
|
||||||
message: "No popup manager available".to_string(),
|
message: "No popup manager available".to_string(),
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
@ -886,7 +829,7 @@ impl EventDispatchContext<'_> {
|
||||||
if let Some(popup_surface) = popup_manager.get_popup_window(handle.key()) {
|
if let Some(popup_surface) = popup_manager.get_popup_window(handle.key()) {
|
||||||
popup_surface.set_component_instance(instance);
|
popup_surface.set_component_instance(instance);
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::Domain(DomainError::Configuration {
|
return Err(Error::Domain(DomainError::SurfaceNotFound {
|
||||||
message: "Popup window not found after creation".to_string(),
|
message: "Popup window not found after creation".to_string(),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
@ -907,13 +850,13 @@ impl EventDispatchContext<'_> {
|
||||||
/// Resizes a popup to the specified dimensions
|
/// Resizes a popup to the specified dimensions
|
||||||
pub fn resize_popup(&mut self, handle: PopupHandle, width: f32, height: f32) -> Result<()> {
|
pub fn resize_popup(&mut self, handle: PopupHandle, width: f32, height: f32) -> Result<()> {
|
||||||
let active_surface = self.active_or_primary_output().ok_or_else(|| {
|
let active_surface = self.active_or_primary_output().ok_or_else(|| {
|
||||||
Error::Domain(DomainError::Configuration {
|
Error::Domain(DomainError::OutputNotFound {
|
||||||
message: "No active or primary output available".to_string(),
|
message: "No active or primary output available".to_string(),
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let popup_manager = active_surface.popup_manager().ok_or_else(|| {
|
let popup_manager = active_surface.popup_manager().ok_or_else(|| {
|
||||||
Error::Domain(DomainError::Configuration {
|
Error::Domain(DomainError::SurfaceNotFound {
|
||||||
message: "No popup manager available".to_string(),
|
message: "No popup manager available".to_string(),
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
@ -1080,7 +1023,7 @@ impl EventDispatchContext<'_> {
|
||||||
{
|
{
|
||||||
let surfaces = self.app_state.surfaces_by_name(name);
|
let surfaces = self.app_state.surfaces_by_name(name);
|
||||||
let surface = surfaces.first().ok_or_else(|| {
|
let surface = surfaces.first().ok_or_else(|| {
|
||||||
Error::Domain(DomainError::Configuration {
|
Error::Domain(DomainError::SurfaceNotFound {
|
||||||
message: format!("Surface '{}' not found", name),
|
message: format!("Surface '{}' not found", name),
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,18 @@ pub enum DomainError {
|
||||||
#[error("calculation error: {operation} failed - {reason}")]
|
#[error("calculation error: {operation} failed - {reason}")]
|
||||||
Calculation { operation: String, reason: String },
|
Calculation { operation: String, reason: String },
|
||||||
|
|
||||||
|
#[error("component '{name}' not found")]
|
||||||
|
ComponentNotFound { name: String },
|
||||||
|
|
||||||
|
#[error("channel closed")]
|
||||||
|
ChannelClosed,
|
||||||
|
|
||||||
|
#[error("surface not found: {message}")]
|
||||||
|
SurfaceNotFound { message: String },
|
||||||
|
|
||||||
|
#[error("output not found: {message}")]
|
||||||
|
OutputNotFound { message: String },
|
||||||
|
|
||||||
#[error("adapter error")]
|
#[error("adapter error")]
|
||||||
Adapter {
|
Adapter {
|
||||||
#[source]
|
#[source]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue