Skip to content

Commit

Permalink
Replace chrono-tz with time-tz and improve Time Zone selection (#99)
Browse files Browse the repository at this point in the history
This PR updates the DateTime converter implementation to use the
[time-tz crate](https://github.com/Yuri6037/time-tz) instead of
chrono-tz. This patches
https://github.com/esimkowitz/dev-widgets/security/dependabot/1. It also
adds functionality to get the local timezone for the target system. The
specific revision of this crate used here includes a proposed change I
have added which extends support for getting the local time zone to WASM
targets (Yuri6037/time-tz#14).

This PR also adds support for logging, replacing use of println! in the
application logic. This way, support for logging will be equal for both
WASM and desktop targets. It also removes an unnecessary direct clap
dependency.
  • Loading branch information
esimkowitz authored Jul 22, 2023
1 parent 941f145 commit 865a5b8
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 91 deletions.
153 changes: 106 additions & 47 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@ readme = "README.md"
build = "build.rs"

[build-dependencies]
clap = "4.3.11"
curl = "0.4.44"
grass = "0.13.1"
zip-extract = "0.1.2"

[dependencies]
base64ct = { version = "1.6.0", features = ["alloc"] }
chrono = "0.4.26"
chrono-tz = "0.8.3"
digest = "0.10.7"
dioxus = { git = "https://github.com/DioxusLabs/dioxus.git", rev = "a75223cd8895ca6733164ddf03de314c91c1dbab" }
dioxus-free-icons = { git = "https://github.com/esimkowitz/dioxus-free-icons.git", rev = "35995f8577954a83bab2f3b1242bce33d12d3593", features = ["bootstrap"] }
dioxus-router = { git = "https://github.com/DioxusLabs/dioxus.git", rev = "a75223cd8895ca6733164ddf03de314c91c1dbab" }
getrandom = { version= "0.2.10", features = ["js"] }
md-5 = "0.10.5"
num-traits = "0.2.15"
phf = { version = "0.11.1", features = ["macros"] }
Expand All @@ -29,18 +25,24 @@ sha1 = "0.10.5"
sha2 = "0.10.7"
strum = "0.25.0"
strum_macros = "0.25.1"
time = "0.3.23"
uuid = { version = "1.4.0", features = ["v4", "fast-rng"] }
wasm-bindgen = { version = "0.2.87", features = ["enable-interning"] }
time-tz = { version = "1.0.3", features = ["db", "system"], git = "https://github.com/esimkowitz/time-tz.git", rev = "9bad169699e6f0af98e1a2550e4cb991cade858d" }
log = { version = "0.4.19", features = ["std"] }

[target."cfg(not(target_family = \"wasm\"))".dev-dependencies]
[target.'cfg(not(target_family = "wasm"))'.dev-dependencies]
dioxus-hot-reload = { git = "https://github.com/DioxusLabs/dioxus.git", rev = "a75223cd8895ca6733164ddf03de314c91c1dbab" }

[target."cfg(not(target_family = \"wasm\"))".dependencies]
[target.'cfg(not(target_family = "wasm"))'.dependencies]
dioxus-desktop = { git = "https://github.com/DioxusLabs/dioxus.git", rev = "a75223cd8895ca6733164ddf03de314c91c1dbab" }
getrandom = "0.2.10"
time = "0.3.23"

[target."cfg(target_family = \"wasm\")".dependencies]
[target.'cfg(target_family = "wasm")'.dependencies]
dioxus-web = { git = "https://github.com/DioxusLabs/dioxus.git", rev = "a75223cd8895ca6733164ddf03de314c91c1dbab" }
getrandom = { version= "0.2.10", features = ["js"] }
time = { version = "0.3.23", features = ["wasm-bindgen"]}
wasm-bindgen = { version = "0.2.87", features = ["enable-interning"] }
wasm-logger = "0.2.0"

[package.metadata.bundle]
name = "Dev Widgets"
Expand Down
19 changes: 19 additions & 0 deletions src/logger/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use log::*;

#[cfg(not(target_family = "wasm"))]
mod simple_logger;

pub fn init(level: log::Level) {
#[cfg(target_family = "wasm")]
{
wasm_logger::init(wasm_logger::Config::new(level));
}

#[cfg(not(target_family = "wasm"))]
{
match set_boxed_logger(Box::new(simple_logger::SimpleLogger)) {
Ok(_) => log::set_max_level(level.to_level_filter()),
Err(e) => panic!("Failed to initialize logger: {}", e),
}
}
}
17 changes: 17 additions & 0 deletions src/logger/simple_logger.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use log::{Record, Metadata};

pub struct SimpleLogger;

impl log::Log for SimpleLogger {
fn enabled(&self, metadata: &Metadata) -> bool {
metadata.level() <= log::max_level()
}

fn log(&self, record: &Record) {
if self.enabled(record.metadata()) {
println!("{} - {}", record.level(), record.args());
}
}

fn flush(&self) {}
}
8 changes: 8 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@ use std::env;

const USE_HOT_RELOAD: bool = false;

mod logger;

fn main() {
let mut log_level = log::Level::Warn;
if cfg!(debug_assertions) {
#[cfg(not(target_family = "wasm"))]
env::set_var("RUST_BACKTRACE", "1");
if USE_HOT_RELOAD {
environment::init_hot_reload();
}
log_level = log::Level::Info;
}

logger::init(log_level);

log::info!("Starting app");

environment::init(App);
}
Loading

0 comments on commit 865a5b8

Please sign in to comment.