feat: misc improvements

This commit is contained in:
2025-03-18 23:27:17 +00:00
parent fe1a32f31b
commit 1191cdd95c
15 changed files with 264 additions and 68 deletions

View File

@ -1,5 +1,6 @@
use std::hash::{DefaultHasher, Hash, Hasher};
use crate::model::config::GlobalConfig;
use crate::pkg::{Feature, Status};
use crate::profiles::AnyProfile;
use crate::{model::misc::Game, pkg::PkgKey};
use crate::pkg_store::PackageStore;
@ -18,6 +19,13 @@ pub struct AppData {
pub state: GlobalState,
}
#[derive(PartialEq, Debug, Copy, Clone)]
pub enum ToggleAction {
Disable,
EnableSelf,
EnableRecursive,
}
impl AppData {
pub fn new(apph: AppHandle) -> AppData {
let cfg = std::fs::read_to_string(util::config_dir().join("config.json"))
@ -59,26 +67,34 @@ impl AppData {
}
}
pub fn toggle_package(&mut self, key: PkgKey, enable: bool) -> Result<()> {
log::debug!("toggle: {} {}", key, enable);
pub fn toggle_package(&mut self, key: PkgKey, action: ToggleAction) -> Result<()> {
log::debug!("toggle: {} {:?}", key, action);
let profile = self.profile.as_mut().ok_or_else(|| anyhow!("No profile"))?;
if enable {
if action != ToggleAction::Disable {
let pkg = self.pkgs.get(&key)?;
let loc = pkg.loc
.clone()
.ok_or_else(|| anyhow!("Attempted to enable a non-existent package"))?;
profile.mod_pkgs_mut().insert(key);
for d in &loc.dependencies {
_ = self.toggle_package(d.clone(), true);
if let Status::OK(feature_set) = loc.status {
log::debug!("{:?}", feature_set);
if feature_set.contains(Feature::Mod) {
profile.mod_pkgs_mut().insert(key);
}
}
if action == ToggleAction::EnableRecursive {
for d in &loc.dependencies {
_ = self.toggle_package(d.clone(), action);
}
}
} else {
profile.mod_pkgs_mut().remove(&key);
for (ckey, pkg) in self.pkgs.get_all() {
if let Some(loc) = pkg.loc {
if loc.dependencies.contains(&key) {
self.toggle_package(ckey, false)?;
self.toggle_package(ckey, action)?;
}
}
}
@ -99,4 +115,10 @@ impl AppData {
}
hasher.finish().to_string()
}
pub fn fix(&mut self) {
if let Some(p) = &mut self.profile {
p.fix(&self.pkgs);
}
}
}