Add error handling for configuration conversion to regex rules

This commit is contained in:
Richard Weber 2024-08-15 17:36:42 +03:00 committed by Victoria Brekenfeld
parent e8947b8742
commit ec86fc33e0
2 changed files with 13 additions and 7 deletions

View file

@ -55,14 +55,14 @@ pub fn is_dialog(window: &CosmicSurface) -> bool {
false
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct TilingExceptions {
app_ids: RegexSet,
titles: RegexSet,
}
impl TilingExceptions {
pub fn new(config: &Config) -> Self {
pub fn new(config: &Config) -> Result<Self, regex::Error> {
let mut app_ids = Vec::new();
let mut titles = Vec::new();
@ -73,10 +73,10 @@ impl TilingExceptions {
}
}
Self {
app_ids: RegexSet::new(app_ids).unwrap(),
titles: RegexSet::new(titles).unwrap(),
}
Ok(Self {
app_ids: RegexSet::new(app_ids)?,
titles: RegexSet::new(titles)?,
})
}
}

View file

@ -7,6 +7,7 @@ use std::{
sync::atomic::Ordering,
time::{Duration, Instant},
};
use tracing::error;
use wayland_backend::server::ClientId;
use crate::wayland::protocols::workspace::WorkspaceCapabilities;
@ -1235,6 +1236,11 @@ impl Shell {
pub fn new(config: &Config) -> Self {
let theme = cosmic::theme::system_preference();
let tiling_exceptions = layout::TilingExceptions::new(config).unwrap_or_else(|e| {
error!(?e, "Could not load tiling exceptions, using default");
layout::TilingExceptions::default()
});
Shell {
workspaces: Workspaces::new(config, theme.clone()),
seats: Seats::new(),
@ -1252,7 +1258,7 @@ impl Shell {
resize_mode: ResizeMode::None,
resize_state: None,
resize_indicator: None,
tiling_exceptions: layout::TilingExceptions::new(config),
tiling_exceptions,
#[cfg(feature = "debug")]
debug_active: false,