parent
b4f928d3c0
commit
61f2103b3e
2 changed files with 30 additions and 42 deletions
|
|
@ -58,6 +58,7 @@ use std::{borrow::Cow, str::FromStr};
|
|||
#[allow(clippy::struct_excessive_bools)]
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
pub struct SettingsApp {
|
||||
last_active_page: Box<str>,
|
||||
active_page: page::Entity,
|
||||
active_context_page: Option<page::Entity>,
|
||||
loaded_pages: BTreeSet<page::Entity>,
|
||||
|
|
@ -182,11 +183,14 @@ impl cosmic::Application for SettingsApp {
|
|||
}
|
||||
|
||||
fn init(core: Core, flags: Self::Flags) -> (Self, Task<Self::Message>) {
|
||||
let config = Config::new();
|
||||
|
||||
let mut app = SettingsApp {
|
||||
active_page: page::Entity::default(),
|
||||
active_context_page: None,
|
||||
last_active_page: config.active_page(),
|
||||
loaded_pages: BTreeSet::new(),
|
||||
config: Config::new(),
|
||||
config,
|
||||
core,
|
||||
nav_model: nav_bar::Model::default(),
|
||||
page_sender: None,
|
||||
|
|
@ -219,7 +223,7 @@ impl cosmic::Application for SettingsApp {
|
|||
Some(p) => app.subtask_to_page(&p),
|
||||
None => app
|
||||
.pages
|
||||
.find_page_by_id(&app.config.active_page)
|
||||
.find_page_by_id(&app.last_active_page)
|
||||
.map(|(id, _info)| id),
|
||||
}
|
||||
.unwrap_or(desktop_id);
|
||||
|
|
@ -849,9 +853,8 @@ impl SettingsApp {
|
|||
.unwrap_or(iced::Task::none())
|
||||
.map(Message::PageMessage)
|
||||
.map(Into::into);
|
||||
self.config.active_page = Box::from(&*self.pages.info[page].id);
|
||||
self.config
|
||||
.set_active_page(Box::from(&*self.pages.info[page].id));
|
||||
self.last_active_page = Box::from(&*self.pages.info[page].id);
|
||||
self.config.set_active_page(self.last_active_page.clone());
|
||||
}
|
||||
|
||||
self.search_clear();
|
||||
|
|
|
|||
|
|
@ -8,68 +8,53 @@ use cosmic::{
|
|||
|
||||
const NAME: &str = "com.system76.CosmicSettings";
|
||||
|
||||
const ACTIVE_PAGE: &str = "active-page";
|
||||
const ACTIVE_PAGE: &str = "active_page";
|
||||
const ACCENT_PALETTE_DARK: &str = "accent_palette_dark";
|
||||
const ACCENT_PALETTE_LIGHT: &str = "accent_palette_light";
|
||||
|
||||
#[must_use]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config {
|
||||
pub cosmic_config: Option<cosmic_config::Config>,
|
||||
pub active_page: Box<str>,
|
||||
config: cosmic_config::Config,
|
||||
state: cosmic_config::Config,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn new() -> Self {
|
||||
let mut config = Self::default();
|
||||
|
||||
let context = match cosmic_config::Config::new(NAME, 1) {
|
||||
Ok(context) => context,
|
||||
let config = match cosmic_config::Config::new(NAME, 1) {
|
||||
Ok(config) => config,
|
||||
Err(why) => {
|
||||
tracing::warn!(?why, "failed to get config");
|
||||
return Self::default();
|
||||
panic!("failed to get {NAME} config: {:?}", why);
|
||||
}
|
||||
};
|
||||
|
||||
if let Ok(page) = context.get::<Box<str>>(ACTIVE_PAGE) {
|
||||
config.active_page = page;
|
||||
}
|
||||
let state = match cosmic_config::Config::new_state(NAME, 1) {
|
||||
Ok(state) => state,
|
||||
Err(why) => {
|
||||
panic!("failed to get {NAME} state: {:?}", why);
|
||||
}
|
||||
};
|
||||
|
||||
config.cosmic_config = Some(context);
|
||||
|
||||
config
|
||||
Self { config, state }
|
||||
}
|
||||
|
||||
pub fn accent_palette_dark(&self) -> Result<Vec<Srgba>, cosmic_config::Error> {
|
||||
self.cosmic_config
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.get::<Vec<Srgba>>(ACCENT_PALETTE_DARK)
|
||||
self.config.get::<Vec<Srgba>>(ACCENT_PALETTE_DARK)
|
||||
}
|
||||
|
||||
pub fn accent_palette_light(&self) -> Result<Vec<Srgba>, cosmic_config::Error> {
|
||||
self.cosmic_config
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.get::<Vec<Srgba>>(ACCENT_PALETTE_LIGHT)
|
||||
self.config.get::<Vec<Srgba>>(ACCENT_PALETTE_LIGHT)
|
||||
}
|
||||
|
||||
pub fn set_active_page(&mut self, page: Box<str>) {
|
||||
if let Some(context) = self.cosmic_config.as_ref() {
|
||||
if let Err(why) = context.set::<Box<str>>(ACTIVE_PAGE, page.clone()) {
|
||||
tracing::error!(?why, "failed to store active page ID");
|
||||
}
|
||||
}
|
||||
|
||||
self.active_page = page;
|
||||
pub fn active_page(&self) -> Box<str> {
|
||||
self.state
|
||||
.get::<Box<str>>(ACTIVE_PAGE)
|
||||
.unwrap_or_else(|_| Box::from("desktop"))
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
cosmic_config: None,
|
||||
active_page: Box::from("desktop"),
|
||||
pub fn set_active_page(&self, page: Box<str>) {
|
||||
if let Err(why) = self.state.set::<Box<str>>(ACTIVE_PAGE, page.clone()) {
|
||||
tracing::error!(?why, "failed to store active page ID");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue