mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-25 13:40:19 +00:00
ac3e33af46
* clean up logging to avoid random extra trace * fix race condition with updates * properly wire up verbose * fix bundling (macos) and logging * Add structured output * clean up clap names * extract out wire format * switch structured key to json * fix random println, fallback to `dioxus/platform` * clean up logging for run/build * clean up logging around project * remove manual exits * fix tokio runtime for mobile * rework dog app * rip out ssg * Switch dioxus/axum to dioxus/server * add android template inline * pre restructure for bundle prep * add the whole res directory * Better theme for the app * remove mobile demo now that most apps work natively * self-referential android * only use deep linking for assets * fix imports for android * clippy, fixup ios and android * I'm not boxing compiler message you can't make me * fix clippy on unix
43 lines
1.1 KiB
Rust
43 lines
1.1 KiB
Rust
//! A simple little clock that updates the time every few milliseconds.
|
|
//!
|
|
|
|
use async_std::task::sleep;
|
|
use dioxus::prelude::*;
|
|
use web_time::Instant;
|
|
|
|
fn main() {
|
|
dioxus::launch(app);
|
|
}
|
|
|
|
fn app() -> Element {
|
|
let mut millis = use_signal(|| 0);
|
|
|
|
use_future(move || async move {
|
|
// Save our initial timea
|
|
let start = Instant::now();
|
|
|
|
loop {
|
|
sleep(std::time::Duration::from_millis(27)).await;
|
|
|
|
// Update the time, using a more precise approach of getting the duration since we started the timer
|
|
millis.set(start.elapsed().as_millis() as i64);
|
|
}
|
|
});
|
|
|
|
// Format the time as a string
|
|
// This is rather cheap so it's fine to leave it in the render function
|
|
let time = format!(
|
|
"{:02}:{:02}:{:03}",
|
|
millis() / 1000 / 60 % 60,
|
|
millis() / 1000 % 60,
|
|
millis() % 1000
|
|
);
|
|
|
|
rsx! {
|
|
document::Stylesheet { href: asset!("/examples/assets/clock.css") }
|
|
div { id: "app",
|
|
div { id: "title", "Carpe diem 🎉" }
|
|
div { id: "clock-display", "{time}" }
|
|
}
|
|
}
|
|
}
|