summaryrefslogtreecommitdiff
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
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 '')
-rw-r--r--Cargo.lock123
-rw-r--r--Cargo.toml2
-rw-r--r--src/config.rs20
-rw-r--r--src/error.rs2
-rw-r--r--src/main.rs19
-rw-r--r--src/types.rs6
6 files changed, 103 insertions, 69 deletions
diff --git a/Cargo.lock b/Cargo.lock
index f9f6e52..10b6d0b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -29,9 +29,9 @@ dependencies = [
[[package]]
name = "adler2"
-version = "2.0.0"
+version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
+checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
[[package]]
name = "aes"
@@ -74,9 +74,12 @@ checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd"
[[package]]
name = "aligned-vec"
-version = "0.5.0"
+version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4aa90d7ce82d4be67b64039a3d588d38dbcc6736577de4a847025ce5b0c468d1"
+checksum = "dc890384c8602f339876ded803c97ad529f3842aba97f6392b3dba0dd171769b"
+dependencies = [
+ "equator",
+]
[[package]]
name = "android-activity"
@@ -682,9 +685,9 @@ checksum = "0da45bc31171d8d6960122e222a67740df867c1dd53b4d51caa297084c185cab"
[[package]]
name = "cc"
-version = "1.2.26"
+version = "1.2.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "956a5e21988b87f372569b66183b78babf23ebc2e744b733e4350a752c4dafac"
+checksum = "d487aa071b5f64da6f19a3e848e3578944b726ee5a4854b82172f02aa876bfdc"
dependencies = [
"jobserver",
"libc",
@@ -709,9 +712,9 @@ dependencies = [
[[package]]
name = "cfg-if"
-version = "1.0.0"
+version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
[[package]]
name = "cfg_aliases"
@@ -1211,9 +1214,9 @@ checksum = "a3d8a32ae18130a3c84dd492d4215c3d913c3b07c6b63c2eb3eb7ff1101ab7bf"
[[package]]
name = "enumflags2"
-version = "0.7.11"
+version = "0.7.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ba2f4b465f5318854c6f8dd686ede6c0a9dc67d4b1ac241cf0eb51521a309147"
+checksum = "1027f7680c853e056ebcec683615fb6fbbc07dbaa13b4d5d9442b146ded4ecef"
dependencies = [
"enumflags2_derive",
"serde",
@@ -1221,9 +1224,29 @@ dependencies = [
[[package]]
name = "enumflags2_derive"
-version = "0.7.11"
+version = "0.7.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "67c78a4d8fdf9953a5c9d458f9efe940fd97a0cab0941c075a813ac594733827"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "equator"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4711b213838dfee0117e3be6ac926007d7f433d7bbe33595975d4190cb07e6fc"
+dependencies = [
+ "equator-macro",
+]
+
+[[package]]
+name = "equator-macro"
+version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fc4caf64a58d7a6d65ab00639b046ff54399a39f5f2554728895ace4b297cd79"
+checksum = "44f23cf4b44bfce11a86ace86f8a73ffdec849c9fd00a386a53d278bd9e81fb3"
dependencies = [
"proc-macro2",
"quote",
@@ -1608,7 +1631,7 @@ version = "0.2.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cba6ae63eb948698e300f645f87c70f76630d505f23b8907cf1e193ee85048c1"
dependencies = [
- "unicode-width 0.2.0",
+ "unicode-width 0.2.1",
]
[[package]]
@@ -1619,7 +1642,7 @@ checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
dependencies = [
"cfg-if",
"libc",
- "wasi 0.11.0+wasi-snapshot-preview1",
+ "wasi 0.11.1+wasi-snapshot-preview1",
]
[[package]]
@@ -1815,9 +1838,9 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "hermit-abi"
-version = "0.5.1"
+version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f154ce46856750ed433c8649605bf7ed2de3bc35fd9d2a9f30cddd873c80cb08"
+checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c"
[[package]]
name = "hex"
@@ -2359,9 +2382,9 @@ dependencies = [
[[package]]
name = "image-webp"
-version = "0.2.1"
+version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b77d01e822461baa8409e156015a1d91735549f0f2c17691bd2d996bef238f7f"
+checksum = "14d75c7014ddab93c232bc6bb9f64790d3dfd1d605199acd4b40b6d69e691e9f"
dependencies = [
"byteorder-lite",
"quick-error",
@@ -2551,9 +2574,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
[[package]]
name = "libc"
-version = "0.2.172"
+version = "0.2.173"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
+checksum = "d8cfeafaffdbc32176b64fb251369d52ea9f0a8fbc6f8759edffef7b525d64bb"
[[package]]
name = "libfuzzer-sys"
@@ -2572,7 +2595,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667"
dependencies = [
"cfg-if",
- "windows-targets 0.53.0",
+ "windows-targets 0.53.2",
]
[[package]]
@@ -2609,7 +2632,7 @@ checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [
"bitflags 2.9.1",
"libc",
- "redox_syscall 0.5.12",
+ "redox_syscall 0.5.13",
]
[[package]]
@@ -2778,9 +2801,9 @@ dependencies = [
[[package]]
name = "memchr"
-version = "2.7.4"
+version = "2.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
+checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
[[package]]
name = "memmap2"
@@ -2839,9 +2862,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
-version = "0.8.8"
+version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a"
+checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
dependencies = [
"adler2",
"simd-adler32",
@@ -2854,7 +2877,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c"
dependencies = [
"libc",
- "wasi 0.11.0+wasi-snapshot-preview1",
+ "wasi 0.11.1+wasi-snapshot-preview1",
"windows-sys 0.59.0",
]
@@ -3464,7 +3487,7 @@ checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5"
dependencies = [
"cfg-if",
"libc",
- "redox_syscall 0.5.12",
+ "redox_syscall 0.5.13",
"smallvec",
"windows-targets 0.52.6",
]
@@ -3892,9 +3915,9 @@ dependencies = [
[[package]]
name = "redox_syscall"
-version = "0.5.12"
+version = "0.5.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af"
+checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6"
dependencies = [
"bitflags 2.9.1",
]
@@ -3947,9 +3970,9 @@ checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832"
[[package]]
name = "reqwest"
-version = "0.12.19"
+version = "0.12.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a2f8e5513d63f2e5b386eb5106dc67eaf3f84e95258e210489136b8b92ad6119"
+checksum = "eabf4c97d9130e2bf606614eb937e86edac8292eaa6f422f995d7e8de1eb1813"
dependencies = [
"base64",
"bytes",
@@ -3965,13 +3988,11 @@ dependencies = [
"hyper-rustls",
"hyper-tls",
"hyper-util",
- "ipnet",
"js-sys",
"log",
"mime",
"mime_guess",
"native-tls",
- "once_cell",
"percent-encoding",
"pin-project-lite",
"rustls-pki-types",
@@ -4067,9 +4088,9 @@ checksum = "60e7c00b6c3bf5e38a880eec01d7e829d12ca682079f8238a464def3c4b31627"
[[package]]
name = "rustc-demangle"
-version = "0.1.24"
+version = "0.1.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
+checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f"
[[package]]
name = "rustc-hash"
@@ -4498,7 +4519,7 @@ dependencies = [
"objc2-foundation 0.2.2",
"objc2-quartz-core",
"raw-window-handle",
- "redox_syscall 0.5.12",
+ "redox_syscall 0.5.13",
"rustix 0.38.44",
"tiny-xlib",
"wasm-bindgen",
@@ -4597,9 +4618,9 @@ dependencies = [
[[package]]
name = "syn"
-version = "2.0.101"
+version = "2.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf"
+checksum = "e4307e30089d6fd6aff212f2da3a1f9e32f3223b1f010fb09b7c95f90f3ca1e8"
dependencies = [
"proc-macro2",
"quote",
@@ -5147,9 +5168,9 @@ checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
[[package]]
name = "unicode-width"
-version = "0.2.0"
+version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
+checksum = "4a1a07cc7db3810833284e8d372ccdc6da29741639ecc70c9ec107df0fa6154c"
[[package]]
name = "unicode-xid"
@@ -5216,9 +5237,9 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]]
name = "v_frame"
-version = "0.3.8"
+version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d6f32aaa24bacd11e488aa9ba66369c7cd514885742c9fe08cfe85884db3e92b"
+checksum = "666b7727c8875d6ab5db9533418d7c764233ac9c0cff1d469aec8fa127597be2"
dependencies = [
"aligned-vec",
"num-traits",
@@ -5290,9 +5311,9 @@ dependencies = [
[[package]]
name = "wasi"
-version = "0.11.0+wasi-snapshot-preview1"
+version = "0.11.1+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
+checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
[[package]]
name = "wasi"
@@ -5724,9 +5745,9 @@ dependencies = [
[[package]]
name = "windows-link"
-version = "0.1.1"
+version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38"
+checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
[[package]]
name = "windows-registry"
@@ -5860,9 +5881,9 @@ dependencies = [
[[package]]
name = "windows-targets"
-version = "0.53.0"
+version = "0.53.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b1e4c7e8ceaaf9cb7d7507c974735728ab453b67ef8f18febdd7c11fe59dca8b"
+checksum = "c66f69fcc9ce11da9966ddb31a40968cad001c5bedeb5c2b82ede4253ab48aef"
dependencies = [
"windows_aarch64_gnullvm 0.53.0",
"windows_aarch64_msvc 0.53.0",
@@ -6117,9 +6138,9 @@ dependencies = [
[[package]]
name = "winnow"
-version = "0.7.10"
+version = "0.7.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec"
+checksum = "74c7b26e3480b707944fc872477815d29a8e429d2f93a1ce000f5fa84a15cbcd"
dependencies = [
"memchr",
]
diff --git a/Cargo.toml b/Cargo.toml
index c9819ee..2adda8b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,7 +20,7 @@ material_theme = { path = "crates/material_theme", features = ["animate", "serde
serde.workspace = true
serde_json = "1.0.140"
toml.workspace = true
-tokio = { version = "1.45.1", features = ["fs"] }
+tokio = { version = "1.45.1", features = ["fs", "io-util"] }
tokio-stream = { version = "0.1", features = ["fs"] }
# TODO: enable tokio when it doesn't crash anymore
# rfd = { version = "0.15.2", default-features = false, features = ["tokio", "xdg-portal"] }
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);
}
diff --git a/src/error.rs b/src/error.rs
index a65fb54..8c405b3 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -8,7 +8,7 @@ use thiserror::Error;
#[error(transparent)]
pub enum Error {
IO(Arc<io::Error>),
- #[error("Config file does not exist, so an empty one was created")]
+ #[error("Config file does not exist, so a default one was created")]
ConfigMissing,
#[error("JSON parsing error: {0}")]
SerdeJSON(Arc<serde_json::Error>),
diff --git a/src/main.rs b/src/main.rs
index eee354d..db8e4e9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,7 +3,7 @@ mod config;
mod dialogs;
mod environment;
mod error;
-#[allow(clippy::all, dead_code)]
+#[allow(dead_code)]
mod icon;
mod options;
mod panes;
@@ -12,7 +12,6 @@ mod values;
mod widget;
use std::path::PathBuf;
-use std::sync::Arc;
use config::Config;
use dialogs::{Action as DialogAction, Dialog, UnsavedChanges};
@@ -26,7 +25,7 @@ use iced_anim::transition::Easing;
use iced_anim::{Animated, Animation};
use material_theme::Theme;
use panes::{code_view, designer_view, element_list};
-use types::{Action, DesignerPane, Element, Message, Project};
+use types::{Action, DesignerPane, Element, Message, Panes, Project};
fn main() -> iced::Result {
let version = std::env::args()
@@ -42,8 +41,8 @@ fn main() -> iced::Result {
iced::application(IcedBuilder::boot, IcedBuilder::update, IcedBuilder::view)
.title(IcedBuilder::title)
- .subscription(IcedBuilder::subscription)
.theme(IcedBuilder::theme)
+ .subscription(IcedBuilder::subscription)
.exit_on_close_request(false)
.font(icon::FONT)
.antialiasing(true)
@@ -56,7 +55,7 @@ struct IcedBuilder {
is_loading: bool,
project_path: Option<PathBuf>,
project: Project,
- config: Arc<Config>,
+ config: Config,
theme: Animated<Theme>,
pane_state: pane_grid::State<Panes>,
focus: Option<pane_grid::Pane>,
@@ -65,12 +64,6 @@ struct IcedBuilder {
editor_content: text_editor::Content,
}
-#[derive(Clone, Copy, Debug)]
-enum Panes {
- Designer,
- ElementList,
-}
-
impl IcedBuilder {
fn boot() -> (Self, Task<Message>) {
let state = pane_grid::State::with_configuration(
@@ -82,7 +75,7 @@ impl IcedBuilder {
},
);
- let config = Arc::new(Config::default());
+ let config = Config::default();
let theme = config.selected_theme();
(
@@ -131,7 +124,7 @@ impl IcedBuilder {
match message {
Message::ConfigLoad(result) => match result {
Ok(config) => {
- self.config = Arc::new(config);
+ self.config = config;
self.theme.settle_at(self.config.selected_theme());
if let Some(path) = self.config.last_project() {
diff --git a/src/types.rs b/src/types.rs
index ef6d5c3..dfb85d8 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -49,6 +49,12 @@ pub enum Message {
}
#[derive(Debug, Clone, Copy)]
+pub enum Panes {
+ Designer,
+ ElementList,
+}
+
+#[derive(Debug, Clone, Copy)]
pub enum DesignerPane {
DesignerView,
CodeView,