diff --git a/crates/ewwii/src/app.rs b/crates/ewwii/src/app.rs index d80ee22..9797707 100644 --- a/crates/ewwii/src/app.rs +++ b/crates/ewwii/src/app.rs @@ -3,7 +3,7 @@ use crate::{ daemon_response::DaemonResponseSender, display_backend::DisplayBackend, error_handling_ctx, - gtk::prelude::{Cast, ContainerExt, CssProviderExt, GtkWindowExt, MonitorExt, StyleContextExt, WidgetExt}, + gtk::prelude::{ContainerExt, CssProviderExt, GtkWindowExt, MonitorExt, StyleContextExt, WidgetExt}, paths::EwwPaths, widgets::window::Window, // dynval::DynVal, @@ -336,7 +336,6 @@ impl App { // listening/polling let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel::(); - let (update_sender, update_receiver) = glib::MainContext::channel(0.into()); let config_path = self.paths.get_rhai_path(); let store = iirhai::updates::handle_state_changes(self.ewwii_config.get_root_node()?, tx); @@ -345,15 +344,13 @@ impl App { log::debug!("Received update for var: {}", var_name); let vars = store.read().unwrap().clone(); - match generate_new_widgetnode(&vars, &config_path).await { - Ok(new_widget) => { - if let Err(e) = update_sender.send(new_widget) { - log::warn!("Failed to send new widget update: {:?}", e); - } - } - Err(e) => { - log::error!("Failed to generate new widgetnode: {:?}", e); - } + if let Ok(new_widget) = generate_new_widgetnode(&vars, &config_path).await { + let mut id_to_prop = HashMap::new(); + let _ = get_id_to_props_map(&new_widget, &mut id_to_prop); + + widget_reg_store.update_prop_changes(id_to_prop); + } else { + log::error!("Failed to generate new widgetnode"); } } log::debug!("Receiver loop exited"); @@ -382,31 +379,6 @@ impl App { } })); - update_receiver.attach(None, move |new_root_widget| { - let mut id_to_prop = HashMap::new(); - let _ = get_id_to_props_map(&new_root_widget, &mut id_to_prop); - - widget_reg_store.update_prop_changes(id_to_prop); - - // for child in container_for_task.children() { - // container_for_task.remove(&child); - // } - - // match new_root_widget { - // Ok(node) => { - // let gtk_widget: gtk::Widget = - // build_gtk_widget(WidgetInput::Node(node)).expect("Unable to create the gtk widget."); - // container_for_task.add(>k_widget); - // container_for_task.show_all(); - // } - // Err(err) => { - // eprintln!("Widget render failed: {:?}", err); - // } - // } - - glib::ControlFlow::Continue - }); - let duration = window_args.duration; if let Some(duration) = duration { let app_evt_sender = self.app_evt_send.clone(); diff --git a/crates/ewwii/src/diag_error.rs b/crates/ewwii/src/diag_error.rs index 39811f2..2e191e7 100644 --- a/crates/ewwii/src/diag_error.rs +++ b/crates/ewwii/src/diag_error.rs @@ -3,7 +3,7 @@ use codespan_reporting::diagnostic; use crate::dynval; use thiserror::Error; -pub type DiagResult = Result; +// pub type DiagResult = Result; #[derive(Debug, Error)] // #[error("{}", .0.to_message())] // old one @@ -13,25 +13,25 @@ pub struct DiagError(pub diagnostic::Diagnostic); static_assertions::assert_impl_all!(DiagError: Send, Sync); static_assertions::assert_impl_all!(dynval::ConversionError: Send, Sync); -/// Code used by yuck I suppose. +// /// Code used by yuck I suppose. // impl From for DiagError { // fn from(x: T) -> Self { // Self(x.to_diagnostic()) // } // } -impl DiagError { - pub fn note(self, note: &str) -> Self { - DiagError(self.0.with_notes(vec![note.to_string()])) - } -} +// impl DiagError { +// pub fn note(self, note: &str) -> Self { +// DiagError(self.0.with_notes(vec![note.to_string()])) +// } +// } -pub trait DiagResultExt { - fn note(self, note: &str) -> DiagResult; -} +// pub trait DiagResultExt { +// fn note(self, note: &str) -> DiagResult; +// } -impl DiagResultExt for DiagResult { - fn note(self, note: &str) -> DiagResult { - self.map_err(|e| e.note(note)) - } -} +// impl DiagResultExt for DiagResult { +// fn note(self, note: &str) -> DiagResult { +// self.map_err(|e| e.note(note)) +// } +// } diff --git a/crates/ewwii/src/dynval.rs b/crates/ewwii/src/dynval.rs index 6e29003..cbac5af 100644 --- a/crates/ewwii/src/dynval.rs +++ b/crates/ewwii/src/dynval.rs @@ -1,7 +1,7 @@ use ewwii_shared_util::{Span, Spanned}; use itertools::Itertools; use serde::{Deserialize, Serialize}; -use std::{convert::TryFrom, fmt, iter::FromIterator, str::FromStr}; +use std::{convert::TryFrom, fmt, iter::FromIterator}; pub type Result = std::result::Result; @@ -80,18 +80,18 @@ impl std::str::FromStr for DynVal { // fn from_dynval(x: &DynVal) -> std::result::Result; // } -impl> FromDynVal for T { - type Err = E; +// impl> FromDynVal for T { +// type Err = E; - fn from_dynval(x: &DynVal) -> std::result::Result { - x.0.parse() - } -} +// fn from_dynval(x: &DynVal) -> std::result::Result { +// x.0.parse() +// } +// } -pub trait FromDynVal: Sized { - type Err; - fn from_dynval(x: &DynVal) -> std::result::Result; -} +// pub trait FromDynVal: Sized { +// type Err; +// fn from_dynval(x: &DynVal) -> std::result::Result; +// } macro_rules! impl_dynval_from { ($($t:ty),*) => { @@ -196,31 +196,31 @@ impl DynVal { } } - // TODO this should return Result> and use json parsing - pub fn as_vec(&self) -> Result> { - if self.0.is_empty() { - Ok(Vec::new()) - } else { - match self.0.strip_prefix('[').and_then(|x| x.strip_suffix(']')) { - Some(content) => { - let mut items: Vec = content.split(',').map(|x: &str| x.to_string()).collect(); - let mut removed = 0; - for times_ran in 0..items.len() { - // escapes `,` if there's a `\` before em - if items[times_ran - removed].ends_with('\\') { - items[times_ran - removed].pop(); - let it = items.remove((times_ran + 1) - removed); - items[times_ran - removed] += ","; - items[times_ran - removed] += ⁢ - removed += 1; - } - } - Ok(items) - } - None => Err(ConversionError { value: self.clone(), target_type: "vec", source: None }), - } - } - } + // // TODO this should return Result> and use json parsing + // pub fn as_vec(&self) -> Result> { + // if self.0.is_empty() { + // Ok(Vec::new()) + // } else { + // match self.0.strip_prefix('[').and_then(|x| x.strip_suffix(']')) { + // Some(content) => { + // let mut items: Vec = content.split(',').map(|x: &str| x.to_string()).collect(); + // let mut removed = 0; + // for times_ran in 0..items.len() { + // // escapes `,` if there's a `\` before em + // if items[times_ran - removed].ends_with('\\') { + // items[times_ran - removed].pop(); + // let it = items.remove((times_ran + 1) - removed); + // items[times_ran - removed] += ","; + // items[times_ran - removed] += ⁢ + // removed += 1; + // } + // } + // Ok(items) + // } + // None => Err(ConversionError { value: self.clone(), target_type: "vec", source: None }), + // } + // } + // } // pub fn as_json_value(&self) -> Result { // serde_json::from_str::(&self.0) @@ -235,11 +235,11 @@ impl DynVal { // .ok_or_else(|| ConversionError { value: self.clone(), target_type: "json-array", source: None }) // } - pub fn as_json_object(&self) -> Result> { - serde_json::from_str::(&self.0) - .map_err(|e| ConversionError::new(self.clone(), "json-value", Box::new(e)))? - .as_object() - .cloned() - .ok_or_else(|| ConversionError { value: self.clone(), target_type: "json-object", source: None }) - } + // pub fn as_json_object(&self) -> Result> { + // serde_json::from_str::(&self.0) + // .map_err(|e| ConversionError::new(self.clone(), "json-value", Box::new(e)))? + // .as_object() + // .cloned() + // .ok_or_else(|| ConversionError { value: self.clone(), target_type: "json-object", source: None }) + // } } diff --git a/crates/ewwii/src/error_handling_ctx.rs b/crates/ewwii/src/error_handling_ctx.rs index b9b64a6..c4bb226 100644 --- a/crates/ewwii/src/error_handling_ctx.rs +++ b/crates/ewwii/src/error_handling_ctx.rs @@ -15,9 +15,9 @@ use once_cell::sync::Lazy; pub static FILE_DATABASE: Lazy>> = Lazy::new(|| Arc::new(RwLock::new(FileDatabase::new()))); -pub fn clear_files() { - *FILE_DATABASE.write().unwrap() = FileDatabase::new(); -} +// pub fn clear_files() { +// *FILE_DATABASE.write().unwrap() = FileDatabase::new(); +// } pub fn print_error(err: anyhow::Error) { match anyhow_err_to_diagnostic(&err) { diff --git a/crates/ewwii/src/file_database.rs b/crates/ewwii/src/file_database.rs index 4a6c1a2..bd477cf 100644 --- a/crates/ewwii/src/file_database.rs +++ b/crates/ewwii/src/file_database.rs @@ -101,14 +101,14 @@ impl CodeFile { #[derive(Clone, Debug)] enum CodeSource { - File(std::path::PathBuf), + // File(std::path::PathBuf), Literal(String), } impl CodeSource { fn read_content(&self) -> std::io::Result { match self { - CodeSource::File(path) => Ok(std::fs::read_to_string(path)?), + // CodeSource::File(path) => Ok(std::fs::read_to_string(path)?), CodeSource::Literal(x) => Ok(x.to_string()), } } diff --git a/crates/ewwii/src/opts.rs b/crates/ewwii/src/opts.rs index 08ee37e..f191586 100644 --- a/crates/ewwii/src/opts.rs +++ b/crates/ewwii/src/opts.rs @@ -203,11 +203,11 @@ impl From for Opt { } /// Parse a window-name:window-id pair of the form `name:id` or `name` into a tuple of `(name, id)`. -fn parse_window_config_and_id(s: &str) -> Result<(String, String)> { - let (name, id) = s.split_once(':').unwrap_or((s, s)); +// fn parse_window_config_and_id(s: &str) -> Result<(String, String)> { +// let (name, id) = s.split_once(':').unwrap_or((s, s)); - Ok((name.to_string(), id.to_string())) -} +// Ok((name.to_string(), id.to_string())) +// } /// Parse a window-id specific variable value declaration with the syntax `window-id:variable_name="new_value"` /// into a tuple of `(id, variable_name, new_value)`. diff --git a/crates/ewwii/src/util.rs b/crates/ewwii/src/util.rs index 05e6aea..0f4be35 100644 --- a/crates/ewwii/src/util.rs +++ b/crates/ewwii/src/util.rs @@ -56,22 +56,22 @@ macro_rules! enum_parse { /// elements that where in a but not in b, /// elements that where in b but not in a /// ). -pub fn list_difference<'a, 'b, T: PartialEq>(a: &'a [T], b: &'b [T]) -> (Vec<&'a T>, Vec<&'b T>) { - let mut missing = Vec::new(); - for elem in a { - if !b.contains(elem) { - missing.push(elem); - } - } +// pub fn list_difference<'a, 'b, T: PartialEq>(a: &'a [T], b: &'b [T]) -> (Vec<&'a T>, Vec<&'b T>) { +// let mut missing = Vec::new(); +// for elem in a { +// if !b.contains(elem) { +// missing.push(elem); +// } +// } - let mut new = Vec::new(); - for elem in b { - if !a.contains(elem) { - new.push(elem); - } - } - (missing, new) -} +// let mut new = Vec::new(); +// for elem in b { +// if !a.contains(elem) { +// new.push(elem); +// } +// } +// (missing, new) +// } #[ext(pub, name = StringExt)] impl> T { @@ -87,21 +87,21 @@ impl> T { } } -pub trait IterAverage { - fn avg(self) -> f32; -} +// pub trait IterAverage { +// fn avg(self) -> f32; +// } -impl> IterAverage for I { - fn avg(self) -> f32 { - let mut total = 0f32; - let mut cnt = 0f32; - for value in self { - total += value; - cnt += 1f32; - } - total / cnt - } -} +// impl> IterAverage for I { +// fn avg(self) -> f32 { +// let mut total = 0f32; +// let mut cnt = 0f32; +// for value in self { +// total += value; +// cnt += 1f32; +// } +// total / cnt +// } +// } /// Replace all env-var references of the format `"something ${foo}"` in a string /// by the actual env-variables. If the env-var isn't found, will replace the diff --git a/crates/ewwii/src/window/backend_window_options.rs b/crates/ewwii/src/window/backend_window_options.rs index f12ee8b..f188e18 100644 --- a/crates/ewwii/src/window/backend_window_options.rs +++ b/crates/ewwii/src/window/backend_window_options.rs @@ -61,7 +61,7 @@ impl BackendWindowOptionsDef { // pass rhai map from WindowDefinition here pub fn from_map(map: &Map) -> Result { - let get = |key: &str| map.get(key).cloned(); + // let get = |key: &str| map.get(key).cloned(); let struts = Self::get_optional(map, "reserve")?; let window_type = Self::get_optional(map, "windowtype")?; diff --git a/crates/iirhai/src/helper.rs b/crates/iirhai/src/helper.rs index 4b62580..5c0f63c 100644 --- a/crates/iirhai/src/helper.rs +++ b/crates/iirhai/src/helper.rs @@ -27,7 +27,7 @@ pub fn extract_poll_and_listen_vars(code: &str) -> Result Vec { let mut exprs = Vec::new(); let mut i = 0; - let code_bytes = code.as_bytes(); + // let code_bytes = code.as_bytes(); let len = code.len(); while i < len { diff --git a/crates/iirhai/src/providers/builtin_signals.rs b/crates/iirhai/src/providers/builtin_signals.rs index 0eb0aa3..8b36ebc 100644 --- a/crates/iirhai/src/providers/builtin_signals.rs +++ b/crates/iirhai/src/providers/builtin_signals.rs @@ -317,6 +317,6 @@ // chrono::offset::Utc::now().timestamp().to_string() // } -pub fn register_all_signals(engine: &mut rhai::Engine) { +pub fn register_all_signals(_engine: &mut rhai::Engine) { // TODO } diff --git a/crates/iirhai/src/providers/stdlib/env.rs b/crates/iirhai/src/providers/stdlib/env.rs index 16dd78d..f4441c2 100644 --- a/crates/iirhai/src/providers/stdlib/env.rs +++ b/crates/iirhai/src/providers/stdlib/env.rs @@ -13,7 +13,7 @@ pub mod env { } pub fn get_home_dir() -> Option { - std::env::home_dir().and_then(|p| p.into_os_string().into_string().ok()) + std::env::var("HOME").ok() } #[rhai_fn(return_raw)] diff --git a/crates/iirhai/src/updates/mod.rs b/crates/iirhai/src/updates/mod.rs index 367fbd7..e7fa0f2 100644 --- a/crates/iirhai/src/updates/mod.rs +++ b/crates/iirhai/src/updates/mod.rs @@ -18,17 +18,14 @@ mod listen; mod poll; use crate::widgetnode::WidgetNode; -use anyhow::{bail, Result}; use listen::handle_listen; use poll::handle_poll; -use rhai::{Dynamic, Scope}; use std::{ collections::HashMap, - path::{Path, PathBuf}, sync::Arc, sync::RwLock, }; -use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender}; +use tokio::sync::mpsc::{UnboundedSender}; pub type ReactiveVarStore = Arc>>; diff --git a/crates/iirhai/src/widgetnode.rs b/crates/iirhai/src/widgetnode.rs index a0d27fe..303462c 100644 --- a/crates/iirhai/src/widgetnode.rs +++ b/crates/iirhai/src/widgetnode.rs @@ -1,6 +1,6 @@ use ahash::AHasher; -use anyhow::{bail, Result}; -use rhai::{Array, Dynamic, Map}; +use anyhow::{Result}; +use rhai::Map; use std::collections::HashMap; use std::hash::{Hash, Hasher}; @@ -118,7 +118,13 @@ pub fn get_id_to_props_map(root_node: &WidgetNode, id_to_props: &mut HashMap insert_props(props, "Scroll", id_to_props)?, + WidgetNode::Scroll { props, children } => { + insert_props(props, "Scroll", id_to_props)?; + + for child in children { + get_id_to_props_map(child, id_to_props)?; + } + }, WidgetNode::OverLay { children } => { for child in children { get_id_to_props_map(child, id_to_props)?; diff --git a/docs/src/modules/modules.md b/docs/src/modules/modules.md index 67e889b..031c141 100644 --- a/docs/src/modules/modules.md +++ b/docs/src/modules/modules.md @@ -6,7 +6,7 @@ Every module follows the syntax: ```rust,ignore import "std::env" as env; -let home = env::get_home_dir(); +let home = env::get_home_dir(); // returns `$HOME` env var value ``` This allows you to write expressive, modular Rhai code with functions grouped logically under `std` or custom namespaces.