feat: more breaking changes
This commit is contained in:
@ -14,56 +14,51 @@ pub struct GlobalConfig {
|
||||
pub struct AppData {
|
||||
pub profile: Option<Profile>,
|
||||
pub pkgs: PackageStore,
|
||||
pub cfg: GlobalConfig
|
||||
pub cfg: GlobalConfig,
|
||||
}
|
||||
|
||||
impl AppData {
|
||||
pub fn new(app: AppHandle) -> AppData {
|
||||
let path = util::get_dirs()
|
||||
.config_dir()
|
||||
.join("config.json");
|
||||
|
||||
let cfg = std::fs::read_to_string(&path)
|
||||
pub fn new(apph: AppHandle) -> AppData {
|
||||
let cfg = std::fs::read_to_string(util::config_dir().join("config.json"))
|
||||
.and_then(|s| Ok(serde_json::from_str::<GlobalConfig>(&s)?))
|
||||
.unwrap_or_default();
|
||||
|
||||
let profile = match cfg.recent_profile {
|
||||
Some((ref game, ref name)) => Profile::load(game, name).ok(),
|
||||
Some((ref game, ref name)) => Profile::load(game.clone(), name.clone()).ok(),
|
||||
None => None
|
||||
};
|
||||
|
||||
AppData {
|
||||
profile,
|
||||
pkgs: PackageStore::new(app),
|
||||
cfg
|
||||
pkgs: PackageStore::new(apph.clone()),
|
||||
cfg,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write(&self) -> Result<(), std::io::Error> {
|
||||
let path = util::get_dirs()
|
||||
.config_dir()
|
||||
.join("config.json");
|
||||
|
||||
std::fs::write(&path, serde_json::to_string(&self.cfg)?)
|
||||
std::fs::write(util::config_dir().join("config.json"), serde_json::to_string(&self.cfg)?)
|
||||
}
|
||||
|
||||
pub fn switch_profile(&mut self, game: &Game, name: &str) -> Result<()> {
|
||||
self.profile = Profile::load(game, name).ok();
|
||||
if self.profile.is_some() {
|
||||
self.cfg.recent_profile = Some((game.to_owned(), name.to_owned()));
|
||||
} else {
|
||||
self.cfg.recent_profile = None;
|
||||
pub fn switch_profile(&mut self, game: Game, name: String) -> Result<()> {
|
||||
match Profile::load(game.clone(), name.clone()) {
|
||||
Ok(profile) => {
|
||||
self.profile = Some(profile);
|
||||
self.cfg.recent_profile = Some((game, name));
|
||||
self.write()?;
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
self.profile = None;
|
||||
self.cfg.recent_profile = None;
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
self.write()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn toggle_package(&mut self, key: PkgKey, enable: bool) -> Result<()> {
|
||||
log::debug!("toggle: {} {}", key, enable);
|
||||
|
||||
let profile = self.profile.as_mut()
|
||||
.ok_or_else(|| anyhow!("No profile"))?;
|
||||
let profile = self.profile.as_mut().ok_or_else(|| anyhow!("No profile"))?;
|
||||
|
||||
if enable {
|
||||
let pkg = self.pkgs.get(&key)?;
|
||||
|
Reference in New Issue
Block a user