fix: use cosmic config to load config

This commit is contained in:
Ashley Wulber 2023-11-16 16:25:57 -05:00 committed by Jeremy Soller
parent b9723dd5e0
commit 41d0893b49
2 changed files with 5 additions and 28 deletions

View file

@ -11,8 +11,7 @@ use cctk::sctk::reexports::calloop::channel::Sender;
use cctk::toplevel_info::ToplevelInfo;
use cctk::wayland_client::protocol::wl_data_device_manager::DndAction;
use cctk::wayland_client::protocol::wl_seat::WlSeat;
use cosmic::cosmic_config;
use cosmic::cosmic_config::Config;
use cosmic::cosmic_config::{self, Config, CosmicConfigEntry};
use cosmic::iced;
use cosmic::iced::subscription::events_with;
use cosmic::iced::wayland::actions::data_device::DataFromMimeType;
@ -376,7 +375,10 @@ impl cosmic::Application for CosmicAppList {
core: cosmic::app::Core,
_flags: Self::Flags,
) -> (Self, iced::Command<cosmic::app::Message<Self::Message>>) {
let config = config::AppListConfig::load().unwrap_or_default();
let config = Config::new(APP_ID, 1)
.ok()
.and_then(|c| AppListConfig::get_entry(&c).ok())
.unwrap_or_default();
let mut self_ = Self {
core,
favorite_list: desktop_info_for_app_ids(config.favorites.clone())

View file

@ -1,12 +1,7 @@
use anyhow::anyhow;
use cosmic::cosmic_config::cosmic_config_derive::CosmicConfigEntry;
use cosmic::cosmic_config::{self, Config, 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";
@ -24,26 +19,6 @@ pub struct AppListConfig {
}
impl AppListConfig {
// TODO async?
/// load config with the provided name
pub fn load() -> anyhow::Result<Self> {
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::<_, Self>(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);