* wip: update libcosmic * fix: damge issue resolved by updating iced * fix: high cpu usage by time applet and app-list * refactor subscriptions to produce fewer events * refactor network applet to use less cpu * fix: text size * refactor: i18n for audio applet * refactor: power applet i18n setup * fix (battery): always send profile update * fix (battery): set toggler width to layout correctly * fix (app-list): backoff for restarts of toplevel subscription * fix (network): alignment * feat: ask for comfirmation before applying power applet actions * wip: integrate cosmic-config * update zbus * feat: update to use latest libcosmic * update iced * udpate deps * update deps * refactor: move applet helpers to this repo, outside of libcosmic. this should help alleviate some dependency hell * chore update deps * update deps * cleanup
60 lines
1.9 KiB
Rust
60 lines
1.9 KiB
Rust
use anyhow::anyhow;
|
|
|
|
use cosmic::cosmic_config::cosmic_config_derive::CosmicConfigEntry;
|
|
use cosmic::cosmic_config::{self, Config, ConfigGet, ConfigSet, CosmicConfigEntry};
|
|
use serde::{Deserialize, Serialize};
|
|
use std::fmt::Debug;
|
|
use std::fs::File;
|
|
use std::path::PathBuf;
|
|
use xdg::BaseDirectories;
|
|
pub const APP_ID: &str = "com.system76.CosmicAppList";
|
|
pub const VERSION: &str = "0.1.0";
|
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize, Default, PartialEq, Eq)]
|
|
pub enum TopLevelFilter {
|
|
#[default]
|
|
ActiveWorkspace,
|
|
ConfiguredOutput,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq, Eq, CosmicConfigEntry)]
|
|
pub struct AppListConfig {
|
|
pub filter_top_levels: Option<TopLevelFilter>,
|
|
pub favorites: Vec<String>,
|
|
}
|
|
|
|
impl AppListConfig {
|
|
// TODO async?
|
|
/// load config with the provided name
|
|
pub fn load() -> anyhow::Result<AppListConfig> {
|
|
let mut relative_path = PathBuf::from(APP_ID);
|
|
relative_path.push("config.ron");
|
|
let file = match BaseDirectories::new()
|
|
.ok()
|
|
.and_then(|dirs| dirs.find_config_file(relative_path))
|
|
.and_then(|p| File::open(p).ok())
|
|
{
|
|
Some(path) => path,
|
|
_ => {
|
|
anyhow::bail!("Failed to load config");
|
|
}
|
|
};
|
|
|
|
ron::de::from_reader::<_, AppListConfig>(file)
|
|
.map_err(|err| anyhow!("Failed to parse config file: {}", err))
|
|
}
|
|
|
|
pub fn add_favorite(&mut self, id: String, config: &Config) {
|
|
if !self.favorites.contains(&id) {
|
|
self.favorites.push(id);
|
|
let _ = self.write_entry(&config);
|
|
}
|
|
}
|
|
|
|
pub fn remove_favorite(&mut self, id: String, config: &Config) {
|
|
if let Some(pos) = self.favorites.iter().position(|e| e == &id) {
|
|
self.favorites.remove(pos);
|
|
let _ = self.write_entry(&config);
|
|
}
|
|
}
|
|
}
|