commit 48c93f651ecc8d08708ab0acc36ca99b7c696a1a
parent 44c3b3a0377df8c1862f6a6fabbb6e774372b4e4
Author: Sylvia Ivory <git@sivory.net>
Date: Fri, 20 Jun 2025 01:07:02 -0700
Allow basic web rendering
Diffstat:
6 files changed, 75 insertions(+), 29 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,9 +1,4 @@
/target
+/dist
/notes.md
-
-
-# Added by cargo
-#
-# already existing elements were commented out
-
-#/target
+/schema.json
diff --git a/Cargo.lock b/Cargo.lock
@@ -740,6 +740,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be8aed40e4edbf4d3b4431ab260b63fdc40f5780a4766824329ea0f1eefe3c0f"
dependencies = [
"log",
+ "wasm-bindgen",
"web-sys",
]
@@ -1339,9 +1340,11 @@ dependencies = [
"fjordgard-unsplash",
"fjordgard-weather",
"iced",
+ "instant",
"log",
"open",
"rfd",
+ "send_wrapper",
"serde",
"serde_json",
"strum",
@@ -2349,6 +2352,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222"
dependencies = [
"cfg-if",
+ "js-sys",
+ "wasm-bindgen",
+ "web-sys",
]
[[package]]
@@ -4131,6 +4137,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f7d95a54511e0c7be3f51e8867aa8cf35148d7b9445d44de2f943e2b206e749"
[[package]]
+name = "send_wrapper"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73"
+
+[[package]]
name = "serde"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
@@ -15,7 +15,6 @@ chrono = "0.4.41"
directories = "6.0.0"
fjordgard-unsplash = { version = "0.1.0", path = "crates/unsplash" }
fjordgard-weather = { version = "0.1.0", path = "crates/weather" }
-iced = { version = "0.13.1", features = ["tokio", "canvas", "image", "svg"] }
log = "0.4.27"
rfd = "0.15.3"
serde = { version = "1.0.219", features = ["derive"] }
@@ -23,11 +22,16 @@ serde_json = "1.0.140"
strum = { version = "0.27.1", features = ["derive"] }
[target.'cfg(not(target_arch="wasm32"))'.dependencies]
-tokio = { version = "1.45.1", features = ["rt-multi-thread", "fs", "time"] }
+iced = { version = "0.13.1", features = ["canvas", "image", "svg", "tokio"] }
+tokio = { version = "1.45.1", features = ["fs", "time"] }
env_logger = "0.11.8"
open = "5.3.2"
[target.'cfg(target_arch="wasm32")'.dependencies]
-tokio = { version = "1.45.1", features = ["rt", "time"] }
+iced = { version = "0.13.1", features = ["canvas", "image", "svg", "webgl", "fira-sans"] }
+tokio = { version = "1.45.1", features = ["time"] }
console_error_panic_hook = "0.1.7"
-console_log = "1.0.0"
+console_log = { version = "1.0.0", features = ["color"] }
+send_wrapper = "0.6.0"
+# will not work without this
+instant = { version = "0.1", features = ["wasm-bindgen"] }
diff --git a/index.html b/index.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html lang="en" style="height: 100%">
+<head>
+ <meta charset="utf-8" content="text/html; charset=utf-8"/>
+ <meta name="viewport" content="width=device-width, initial-scale=1"/>
+ <title>Fjordgard</title>
+ <base data-trunk-public-url/>
+
+ <link data-trunk rel="copy-dir" href="icons"/>
+</head>
+<body style="height: 100%; margin: 0">
+<link data-trunk rel="rust" href="Cargo.toml" data-wasm-opt="z"/>
+</body>
+</html>
diff --git a/src/main.rs b/src/main.rs
@@ -10,25 +10,24 @@ use fjordgard_weather::{
};
use iced::{
Color, Element, Font, Length, Size, Subscription, Task,
- font::Weight,
time,
widget::{center, column, container, horizontal_space, row, stack, text},
window,
};
+#[cfg(not(target_arch = "wasm32"))]
+use iced::font::Weight;
use background::BackgroundHandle;
-use config::Config;
+use config::{BackgroundMode, Config};
use icon::{icon, icon_button};
use log::{debug, error};
-use crate::config::BackgroundMode;
-
mod background;
mod config;
mod icon;
mod settings;
-struct Fjordgard {
+pub struct Fjordgard {
config: Rc<RefCell<Config>>,
meteo: Arc<MeteoClient>,
time: DateTime<Local>,
@@ -46,14 +45,14 @@ struct Fjordgard {
}
#[derive(Debug, Clone, Copy)]
-enum MediaControl {
+pub enum MediaControl {
Pause,
Previous,
Next,
}
#[derive(Debug, Clone)]
-enum Message {
+pub enum Message {
Tick(DateTime<Local>),
Media(MediaControl),
OpenSettings,
@@ -75,7 +74,11 @@ impl Fjordgard {
let settings = window::Settings::default();
let main_window_size = settings.size;
+ // #[cfg(not(target_arch = "wasm32"))]
let (id, open) = window::open(settings);
+ // #[cfg(target_arch = "wasm32")]
+ // let (id, open) = wasm::window_open(settings);
+
let config = Config::load().unwrap();
let format_string = config.time_format.clone();
@@ -353,8 +356,12 @@ impl Fjordgard {
}
fn view_main(&self) -> Element<Message> {
+ #[cfg_attr(target_arch = "wasm32", allow(unused_mut))]
let mut bold = Font::DEFAULT;
- bold.weight = Weight::Bold;
+ #[cfg(not(target_arch = "wasm32"))]
+ {
+ bold.weight = Weight::Bold;
+ }
let time_text = self.time.format_with_items(self.format_parsed.iter());
let time_widget = text(time_text.to_string())
@@ -410,19 +417,17 @@ impl Fjordgard {
}
}
-#[cfg(not(target_arch = "wasm32"))]
fn main() -> iced::Result {
+ #[cfg(not(target_arch = "wasm32"))]
env_logger::init();
+ #[cfg(target_arch = "wasm32")]
+ {
+ std::panic::set_hook(Box::new(console_error_panic_hook::hook));
+ console_log::init_with_level(log::Level::Info).unwrap();
+ }
+
iced::daemon(Fjordgard::title, Fjordgard::update, Fjordgard::view)
.subscription(Fjordgard::subscription)
.run_with(Fjordgard::new)
}
-
-#[cfg(target_arch = "wasm32")]
-fn main() -> iced::Result {
- std::panic::set_hook(Box::new(console_error_panic_hook::hook));
- console_log::init_with_level(log::Level::Info).unwrap();
-
- Ok(())
-}
diff --git a/src/settings.rs b/src/settings.rs
@@ -1,3 +1,5 @@
+#[cfg(target_arch = "wasm32")]
+use std::ops::Deref;
use std::{cell::RefCell, rc::Rc, sync::Arc};
use fjordgard_weather::{MeteoClient, model::Location};
@@ -61,6 +63,9 @@ pub enum Message {
Latitude(String),
Longitude(String),
FileSelector,
+ #[cfg(target_arch = "wasm32")]
+ FileSelected(send_wrapper::SendWrapper<Option<FileHandle>>),
+ #[cfg(not(target_arch = "wasm32"))]
FileSelected(Option<FileHandle>),
Save,
@@ -209,11 +214,22 @@ impl Settings {
.add_filter("image", &["png", "jpeg", "jpg"])
.pick_file();
- Task::future(file_task).map(Message::FileSelected)
+ #[cfg(not(target_arch = "wasm32"))]
+ {
+ Task::future(file_task).map(Message::FileSelected)
+ }
+ #[cfg(target_arch = "wasm32")]
+ {
+ Task::future(file_task)
+ .map(|h| Message::FileSelected(send_wrapper::SendWrapper::new(h)))
+ }
}
Message::FileSelected(file) => {
self.file_selector_open = false;
+ #[cfg(target_arch = "wasm32")]
+ let file = file.deref();
+
if let Some(file) = file {
#[cfg(not(target_arch = "wasm32"))]
{