feat: fixed all compilation warnings
This commit is contained in:
@@ -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<B: DisplayBackend> App<B> {
|
||||
|
||||
// listening/polling
|
||||
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel::<String>();
|
||||
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<B: DisplayBackend> App<B> {
|
||||
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<B: DisplayBackend> App<B> {
|
||||
}
|
||||
}));
|
||||
|
||||
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();
|
||||
|
||||
@@ -3,7 +3,7 @@ use codespan_reporting::diagnostic;
|
||||
use crate::dynval;
|
||||
use thiserror::Error;
|
||||
|
||||
pub type DiagResult<T> = Result<T, DiagError>;
|
||||
// pub type DiagResult<T> = Result<T, DiagError>;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
// #[error("{}", .0.to_message())] // old one
|
||||
@@ -13,25 +13,25 @@ pub struct DiagError(pub diagnostic::Diagnostic<usize>);
|
||||
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<T: ToDiagnostic> From<T> 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<T> {
|
||||
fn note(self, note: &str) -> DiagResult<T>;
|
||||
}
|
||||
// pub trait DiagResultExt<T> {
|
||||
// fn note(self, note: &str) -> DiagResult<T>;
|
||||
// }
|
||||
|
||||
impl<T> DiagResultExt<T> for DiagResult<T> {
|
||||
fn note(self, note: &str) -> DiagResult<T> {
|
||||
self.map_err(|e| e.note(note))
|
||||
}
|
||||
}
|
||||
// impl<T> DiagResultExt<T> for DiagResult<T> {
|
||||
// fn note(self, note: &str) -> DiagResult<T> {
|
||||
// self.map_err(|e| e.note(note))
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -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<T> = std::result::Result<T, ConversionError>;
|
||||
|
||||
@@ -80,18 +80,18 @@ impl std::str::FromStr for DynVal {
|
||||
// fn from_dynval(x: &DynVal) -> std::result::Result<Self, Self::Err>;
|
||||
// }
|
||||
|
||||
impl<E, T: FromStr<Err = E>> FromDynVal for T {
|
||||
type Err = E;
|
||||
// impl<E, T: FromStr<Err = E>> FromDynVal for T {
|
||||
// type Err = E;
|
||||
|
||||
fn from_dynval(x: &DynVal) -> std::result::Result<Self, Self::Err> {
|
||||
x.0.parse()
|
||||
}
|
||||
}
|
||||
// fn from_dynval(x: &DynVal) -> std::result::Result<Self, Self::Err> {
|
||||
// x.0.parse()
|
||||
// }
|
||||
// }
|
||||
|
||||
pub trait FromDynVal: Sized {
|
||||
type Err;
|
||||
fn from_dynval(x: &DynVal) -> std::result::Result<Self, Self::Err>;
|
||||
}
|
||||
// pub trait FromDynVal: Sized {
|
||||
// type Err;
|
||||
// fn from_dynval(x: &DynVal) -> std::result::Result<Self, Self::Err>;
|
||||
// }
|
||||
|
||||
macro_rules! impl_dynval_from {
|
||||
($($t:ty),*) => {
|
||||
@@ -196,31 +196,31 @@ impl DynVal {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO this should return Result<Vec<DynVal>> and use json parsing
|
||||
pub fn as_vec(&self) -> Result<Vec<String>> {
|
||||
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<String> = 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<Vec<DynVal>> and use json parsing
|
||||
// pub fn as_vec(&self) -> Result<Vec<String>> {
|
||||
// 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<String> = 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::Value> {
|
||||
// serde_json::from_str::<serde_json::Value>(&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::Map<String, serde_json::Value>> {
|
||||
serde_json::from_str::<serde_json::Value>(&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::Map<String, serde_json::Value>> {
|
||||
// serde_json::from_str::<serde_json::Value>(&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 })
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ use once_cell::sync::Lazy;
|
||||
|
||||
pub static FILE_DATABASE: Lazy<Arc<RwLock<FileDatabase>>> = 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) {
|
||||
|
||||
@@ -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<String> {
|
||||
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()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,11 +203,11 @@ impl From<RawOpt> 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)`.
|
||||
|
||||
@@ -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: AsRef<str>> T {
|
||||
@@ -87,21 +87,21 @@ impl<T: AsRef<str>> T {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait IterAverage {
|
||||
fn avg(self) -> f32;
|
||||
}
|
||||
// pub trait IterAverage {
|
||||
// fn avg(self) -> f32;
|
||||
// }
|
||||
|
||||
impl<I: Iterator<Item = f32>> 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<I: Iterator<Item = f32>> 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
|
||||
|
||||
@@ -61,7 +61,7 @@ impl BackendWindowOptionsDef {
|
||||
|
||||
// pass rhai map from WindowDefinition here
|
||||
pub fn from_map(map: &Map) -> Result<Self> {
|
||||
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")?;
|
||||
|
||||
@@ -27,7 +27,7 @@ pub fn extract_poll_and_listen_vars(code: &str) -> Result<Vec<(String, Option<St
|
||||
pub fn extract_poll_listen_exprs(code: &str) -> Vec<String> {
|
||||
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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ pub mod env {
|
||||
}
|
||||
|
||||
pub fn get_home_dir() -> Option<String> {
|
||||
std::env::home_dir().and_then(|p| p.into_os_string().into_string().ok())
|
||||
std::env::var("HOME").ok()
|
||||
}
|
||||
|
||||
#[rhai_fn(return_raw)]
|
||||
|
||||
@@ -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<RwLock<HashMap<String, String>>>;
|
||||
|
||||
|
||||
@@ -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<u64
|
||||
get_id_to_props_map(child, id_to_props)?;
|
||||
}
|
||||
}
|
||||
WidgetNode::Scroll { props, children } => 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)?;
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user