Changes the PageInner.size field to have no explicit default. It is only initialized (not None) when PageInner.panel_config is initialized. This implementation fails faster and more verbose, when program is in an unintended state.
This commit is contained in:
parent
95a82c0d69
commit
ba5fb65b44
2 changed files with 9 additions and 7 deletions
|
|
@ -22,9 +22,9 @@ use crate::pages::desktop::appearance::Roundness;
|
|||
pub struct PageInner {
|
||||
pub(crate) config_helper: Option<cosmic_config::Config>,
|
||||
pub(crate) panel_config: Option<CosmicPanelConfig>,
|
||||
pub size: Option<PanelSize>,
|
||||
pub opacity: f32,
|
||||
pub opacity_changing: bool,
|
||||
pub size: PanelSize,
|
||||
pub outputs: Vec<String>,
|
||||
pub anchors: Vec<String>,
|
||||
pub backgrounds: Vec<String>,
|
||||
|
|
@ -40,9 +40,9 @@ impl Default for PageInner {
|
|||
Self {
|
||||
config_helper: Option::default(),
|
||||
panel_config: Option::default(),
|
||||
size: Option::default(),
|
||||
opacity: 0.0,
|
||||
opacity_changing: false,
|
||||
size: PanelSize::M,
|
||||
outputs: vec![fl!("all-displays")],
|
||||
anchors: vec![
|
||||
Anchor(PanelAnchor::Left).to_string(),
|
||||
|
|
@ -209,7 +209,7 @@ pub(crate) fn style<
|
|||
text::body(fl!("small")).into(),
|
||||
slider(
|
||||
0..=4,
|
||||
match inner.size {
|
||||
match inner.size.as_ref().expect("inner.size is None even though inner.panel_config is Some") {
|
||||
PanelSize::XS => 0,
|
||||
PanelSize::S => 1,
|
||||
PanelSize::M => 2,
|
||||
|
|
@ -504,7 +504,7 @@ impl PageInner {
|
|||
if let Err(err) = default.write_entry(config) {
|
||||
tracing::error!(?err, "Error resetting panel config.");
|
||||
}
|
||||
self.size.clone_from(&default.size);
|
||||
self.size = Some(default.size.clone());
|
||||
self.system_default = Some(default.clone());
|
||||
self.panel_config.clone_from(&self.system_default);
|
||||
} else {
|
||||
|
|
@ -603,10 +603,10 @@ impl PageInner {
|
|||
_ = panel_config.set_border_radius(helper, new_radius).unwrap();
|
||||
}
|
||||
Message::PanelSize(size) => {
|
||||
self.size = size;
|
||||
self.size = Some(size);
|
||||
}
|
||||
Message::PanelSizeCommit => {
|
||||
_ = panel_config.set_size(helper, self.size.clone());
|
||||
_ = panel_config.set_size(helper, self.size.as_ref().expect("PageInner.size is None even though it should be Some").clone());
|
||||
// Reset any size overrides the user might have set
|
||||
_ = panel_config.set_size_center(helper, None);
|
||||
_ = panel_config.set_size_wings(helper, None);
|
||||
|
|
@ -669,7 +669,7 @@ impl PageInner {
|
|||
}
|
||||
}
|
||||
Message::PanelConfig(c) => {
|
||||
self.size = c.size.clone();
|
||||
self.size = Some(c.size.clone());
|
||||
self.panel_config = Some(*c);
|
||||
return Task::none();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ impl Default for Page {
|
|||
// If the config is not present, it will be created with the default values and the name will not match
|
||||
(panel_config.name == "Panel").then_some(panel_config)
|
||||
});
|
||||
let size = panel_config.as_ref().map(|c| c.size.clone());
|
||||
let system_default = cosmic::cosmic_config::Config::system(
|
||||
&format!("{}.Panel", cosmic_panel_config::NAME),
|
||||
CosmicPanelConfig::VERSION,
|
||||
|
|
@ -98,6 +99,7 @@ impl Default for Page {
|
|||
inner: PageInner {
|
||||
config_helper,
|
||||
panel_config,
|
||||
size,
|
||||
container_config,
|
||||
outputs_map: HashMap::new(),
|
||||
system_default,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue