summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.rs20
-rw-r--r--src/error.rs2
-rw-r--r--src/main.rs19
-rw-r--r--src/types.rs6
4 files changed, 30 insertions, 17 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);
}
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,