summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorpml68 <contact@pml68.dev>2025-06-15 00:25:20 +0200
committerpml68 <contact@pml68.dev>2025-06-15 00:25:20 +0200
commitfaa89b670385b09cef1b1e7b2f64f34a5689f06e (patch)
tree2f8234d9fe7500da068132a035c017972c159bb8 /src/config.rs
parentfeat: create config file on startup if it doesn't exist (diff)
downloadiced-builder-faa89b670385b09cef1b1e7b2f64f34a5689f06e.tar.gz
feat: write defaults to newly created config file if it's missing
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/config.rs b/src/config.rs
index 8db16bb..8e2a63b 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
use std::sync::Arc;
use material_theme::Theme;
-use serde::Deserialize;
+use serde::{Deserialize, Serialize};
use tokio_stream::StreamExt;
use tokio_stream::wrappers::ReadDirStream;
@@ -57,8 +57,9 @@ impl Config {
pub async fn load() -> Result<Self, Error> {
use tokio::fs;
+ use tokio::io::AsyncWriteExt;
- #[derive(Deserialize)]
+ #[derive(Deserialize, Serialize)]
pub struct Configuration {
#[serde(default)]
pub theme: String,
@@ -67,9 +68,22 @@ impl Config {
let path = Self::config_file_path();
if !path.try_exists()? {
- let _ = fs::File::create(path)
+ let mut config = fs::File::create(path)
.await
.expect("expected permissions to create config file");
+ let default_config = Configuration {
+ theme: Theme::default().to_string(),
+ last_project: None,
+ };
+
+ config
+ .write_all(
+ toml::to_string_pretty(&default_config)
+ .expect("stringify default configuration")
+ .as_bytes(),
+ )
+ .await
+ .expect("expected config write operation to succeed");
return Err(Error::ConfigMissing);
}