mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 06:21:23 +00:00
refactor: replace unsafe unwrap with if let in config saving (#24)
Removed the unsafe `.unwrap()` call when attempting to get the parent directory of `config_path` in `DaemonConfig::save_to_file` and `GuiConfig::save_to_file`. Replaced it with an idiomatic `if let Some(config_dir)` check to improve code safety and maintainability. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
4b50645c93
commit
aa77a8d212
+8
-6
@@ -12,10 +12,11 @@ pub struct DaemonConfig {
|
||||
impl DaemonConfig {
|
||||
pub fn save_to_file(&self) -> Result<(), Box<dyn Error>> {
|
||||
let config_path = get_config_path()?.join("daemon.json");
|
||||
let config_dir = config_path.parent().unwrap();
|
||||
|
||||
if !config_path.exists() {
|
||||
fs::create_dir_all(config_dir)?;
|
||||
if let Some(config_dir) = config_path.parent() {
|
||||
if !config_path.exists() {
|
||||
fs::create_dir_all(config_dir)?;
|
||||
}
|
||||
}
|
||||
|
||||
let config_json = serde_json::to_string_pretty(self)?;
|
||||
@@ -63,10 +64,11 @@ impl Default for GuiConfig {
|
||||
impl GuiConfig {
|
||||
pub fn save_to_file(&mut self) -> Result<(), Box<dyn Error>> {
|
||||
let config_path = get_config_path()?.join("gui.json");
|
||||
let config_dir = config_path.parent().unwrap();
|
||||
|
||||
if !config_path.exists() {
|
||||
fs::create_dir_all(config_dir)?;
|
||||
if let Some(config_dir) = config_path.parent() {
|
||||
if !config_path.exists() {
|
||||
fs::create_dir_all(config_dir)?;
|
||||
}
|
||||
}
|
||||
|
||||
// Do not save scale factor if user does not want to
|
||||
|
||||
Reference in New Issue
Block a user