forked from NG-SD-Plugins/PowerTools
Fix loading & saving non-persistent configs, hopefully
This commit is contained in:
parent
6878897784
commit
c13f35a4a1
5 changed files with 19 additions and 15 deletions
2
backend/Cargo.lock
generated
2
backend/Cargo.lock
generated
|
@ -567,7 +567,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "powertools-rs"
|
||||
version = "1.0.4"
|
||||
version = "1.0.5"
|
||||
dependencies = [
|
||||
"log",
|
||||
"serde",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "powertools-rs"
|
||||
version = "1.0.4"
|
||||
version = "1.0.5"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
|
@ -31,12 +31,17 @@ impl Default for SettingsJson {
|
|||
impl SettingsJson {
|
||||
pub fn save<P: AsRef<std::path::Path>>(&self, path: P) -> Result<(), JsonError> {
|
||||
let path = path.as_ref();
|
||||
if !self.persistent && path.exists() {
|
||||
// remove settings file when persistence is turned off, to prevent it from be loaded next time.
|
||||
std::fs::remove_file(path).map_err(JsonError::Io)
|
||||
} else {
|
||||
if let Some(parent) = path.parent() {
|
||||
std::fs::create_dir_all(parent).map_err(JsonError::Io)?;
|
||||
}
|
||||
let mut file = std::fs::File::create(path).map_err(JsonError::Io)?;
|
||||
serde_json::to_writer_pretty(&mut file, &self).map_err(JsonError::Serde)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open<P: AsRef<std::path::Path>>(path: P) -> Result<Self, JsonError> {
|
||||
let mut file = std::fs::File::open(path).map_err(JsonError::Io)?;
|
||||
|
|
|
@ -37,13 +37,6 @@ pub struct General {
|
|||
|
||||
impl OnSet for General {
|
||||
fn on_set(&mut self) -> Result<(), SettingError> {
|
||||
// remove settings file when persistence is turned off, to prevent it from be loaded next time.
|
||||
if !self.persistent && self.path.exists() {
|
||||
std::fs::remove_file(&self.path).map_err(|e| SettingError {
|
||||
msg: format!("Failed to delete `{}`: {}", self.path.display(), e),
|
||||
setting: SettingVariant::General,
|
||||
})?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -143,6 +136,12 @@ impl Settings {
|
|||
msg: e.to_string(),
|
||||
setting: SettingVariant::General,
|
||||
})?;
|
||||
if !settings_json.persistent {
|
||||
log::warn!("Loaded persistent config `{}` with persistent=false", json_path.display());
|
||||
general_lock.persistent = false;
|
||||
general_lock.name = settings_json.name;
|
||||
return Ok(false);
|
||||
}
|
||||
let new_cpus = Self::convert_cpus(settings_json.cpus, settings_json.version);
|
||||
let new_gpu = Gpu::from_json(settings_json.gpu, settings_json.version);
|
||||
let new_battery = Battery::from_json(settings_json.battery, settings_json.version);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "PowerTools",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.5",
|
||||
"description": "Power tweaks for power users",
|
||||
"scripts": {
|
||||
"build": "shx rm -rf dist && rollup -c",
|
||||
|
@ -39,7 +39,7 @@
|
|||
"typescript": "^4.6.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"decky-frontend-lib": "*",
|
||||
"decky-frontend-lib": "3.*",
|
||||
"react-icons": "^4.4.0",
|
||||
"usdpl-front": "file:./src/usdpl_front"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue