commit dfb6db868a0774d50d839abe8972918f360f641f
parent 9310680f597d0c2b8814be3209d88fac7d92aca5
Author: Sylvia Ivory <git@sivory.net>
Date: Fri, 20 Jun 2025 03:02:50 -0700
Remove local background from web
Diffstat:
5 files changed, 98 insertions(+), 118 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
@@ -15,7 +15,6 @@ chrono = "0.4.41"
fjordgard-unsplash = { version = "0.1.0", path = "crates/unsplash" }
fjordgard-weather = { version = "0.1.0", path = "crates/weather" }
log = "0.4.27"
-rfd = "0.15.3"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
strum = { version = "0.27.1", features = ["derive"] }
@@ -23,6 +22,7 @@ strum = { version = "0.27.1", features = ["derive"] }
[target.'cfg(not(target_arch="wasm32"))'.dependencies]
iced = { version = "0.13.1", features = ["canvas", "image", "svg", "tokio"] }
tokio = { version = "1.45.1", features = ["fs", "time"] }
+rfd = "0.15.3"
directories = "6.0.0"
env_logger = "0.11.8"
open = "5.3.2"
diff --git a/index.html b/index.html
@@ -5,8 +5,6 @@
<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"/>
diff --git a/src/background.rs b/src/background.rs
@@ -107,18 +107,12 @@ impl BackgroundHandle {
);
match self.mode {
+ #[cfg(not(target_arch = "wasm32"))]
BackgroundMode::Local => {
- #[cfg(not(target_arch = "wasm32"))]
- {
- let path = self.background.clone();
+ let path = self.background.clone();
- Task::future(async move { tokio::fs::read(&path).await })
- .map(|r| Message::BackgroundRead(r.map_err(|e| e.to_string())))
- }
- #[cfg(target_arch = "wasm32")]
- {
- Task::none()
- }
+ Task::future(async move { tokio::fs::read(&path).await })
+ .map(|r| Message::BackgroundRead(r.map_err(|e| e.to_string())))
}
BackgroundMode::Unsplash => {
if !refresh_unsplash {
@@ -317,64 +311,67 @@ impl BackgroundHandle {
.width(Length::Fill)
.height(Length::Fill);
+ #[cfg(not(target_arch = "wasm32"))]
if self.mode == BackgroundMode::Local {
- img.into()
- } else {
- if let Some(state) = &self.unsplash_state {
- let idx = state.current % 10;
- if let Some(photo) = state
- .current_page_photos
- .as_ref()
- .and_then(|c| c.photos.get(idx))
- {
- let suffix = "?utm_source=fjordgard&utm_medium=referral";
-
- let photo_url = format!("{}{suffix}", photo.links.html);
-
- let user = &photo.user;
-
- let author = format!(
- "{}{}",
- user.first_name,
- user.last_name
- .as_ref()
- .map(|l| format!(" {l}"))
- .unwrap_or_default()
- );
- let author_url = format!("{}{suffix}", user.links.html);
-
- return stack![
- img,
- container(
- row![
- button(text("Photo").color(Color::WHITE))
- .style(button::text)
- .on_press_with(move || Message::OpenUrl(
- photo_url.clone()
- )),
- text(".").color(Color::WHITE),
- button(text(author).color(Color::WHITE))
- .style(button::text)
- .on_press_with(move || Message::OpenUrl(
- author_url.clone()
- )),
- text(".").color(Color::WHITE),
- button(text("Unsplash").color(Color::WHITE))
- .style(button::text)
- .on_press_with(move || Message::OpenUrl(format!(
- "https://unsplash.com/{suffix}"
- ))),
- ]
- .spacing(0)
- )
- .align_left(Length::Fill)
- .align_bottom(Length::Fill)
- .padding(15)
- ]
- .into();
- }
- }
+ return img.into();
+ }
+ if let Some(state) = &self.unsplash_state {
+ let idx = state.current % 10;
+ if let Some(photo) = state
+ .current_page_photos
+ .as_ref()
+ .and_then(|c| c.photos.get(idx))
+ {
+ let suffix = "?utm_source=fjordgard&utm_medium=referral";
+
+ let photo_url = format!("{}{suffix}", photo.links.html);
+
+ let user = &photo.user;
+
+ let author = format!(
+ "{}{}",
+ user.first_name,
+ user.last_name
+ .as_ref()
+ .map(|l| format!(" {l}"))
+ .unwrap_or_default()
+ );
+ let author_url = format!("{}{suffix}", user.links.html);
+
+ stack![
+ img,
+ container(
+ row![
+ button(text("Photo").color(Color::WHITE))
+ .style(button::text)
+ .on_press_with(move || Message::OpenUrl(
+ photo_url.clone()
+ )),
+ text(".").color(Color::WHITE),
+ button(text(author).color(Color::WHITE))
+ .style(button::text)
+ .on_press_with(move || Message::OpenUrl(
+ author_url.clone()
+ )),
+ text(".").color(Color::WHITE),
+ button(text("Unsplash").color(Color::WHITE))
+ .style(button::text)
+ .on_press_with(move || Message::OpenUrl(format!(
+ "https://unsplash.com/{suffix}"
+ ))),
+ ]
+ .spacing(0)
+ )
+ .align_left(Length::Fill)
+ .align_bottom(Length::Fill)
+ .padding(15)
+ ]
+ .into()
+ } else {
+ img.into()
+ }
+ } else {
img.into()
}
} else {
diff --git a/src/config.rs b/src/config.rs
@@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize};
pub enum BackgroundMode {
Unsplash,
Solid,
+ #[cfg(not(target_arch = "wasm32"))]
Local,
}
@@ -17,6 +18,7 @@ impl BackgroundMode {
// https://unsplash.com/collections/1053828/tabliss-official
Self::Unsplash => "1053828",
Self::Solid => "#000000",
+ #[cfg(not(target_arch = "wasm32"))]
Self::Local => "",
}
}
@@ -25,6 +27,7 @@ impl BackgroundMode {
match self {
Self::Unsplash => "Unsplash collection",
Self::Solid => "Color (#rrggbb)",
+ #[cfg(not(target_arch = "wasm32"))]
Self::Local => "File path",
}
}
diff --git a/src/settings.rs b/src/settings.rs
@@ -1,5 +1,3 @@
-#[cfg(target_arch = "wasm32")]
-use std::ops::Deref;
use std::{cell::RefCell, rc::Rc, sync::Arc};
use fjordgard_weather::{MeteoClient, model::Location};
@@ -8,6 +6,7 @@ use iced::{
widget::{button, column, combo_box, container, row, scrollable, text, text_input, tooltip},
};
use log::error;
+#[cfg(not(target_arch = "wasm32"))]
use rfd::{AsyncFileDialog, FileHandle};
use strum::VariantArray;
@@ -33,6 +32,7 @@ pub struct Settings {
meteo: Arc<MeteoClient>,
backgrounds: combo_box::State<BackgroundMode>,
locations: combo_box::State<WeatherLocation>,
+ #[cfg(not(target_arch = "wasm32"))]
file_selector_open: bool,
time_format: String,
@@ -62,9 +62,8 @@ pub enum Message {
LocationSelected(LocationRow),
Latitude(String),
Longitude(String),
+ #[cfg(not(target_arch = "wasm32"))]
FileSelector,
- #[cfg(target_arch = "wasm32")]
- FileSelected(send_wrapper::SendWrapper<Option<FileHandle>>),
#[cfg(not(target_arch = "wasm32"))]
FileSelected(Option<FileHandle>),
Save,
@@ -109,6 +108,7 @@ impl Settings {
meteo,
backgrounds: combo_box::State::new(BackgroundMode::VARIANTS.to_vec()),
locations: combo_box::State::new(WeatherLocation::VARIANTS.to_vec()),
+ #[cfg(not(target_arch = "wasm32"))]
file_selector_open: false,
time_format: original_config.time_format,
@@ -204,6 +204,7 @@ impl Settings {
self.longitude = longitude;
Task::none()
}
+ #[cfg(not(target_arch = "wasm32"))]
Message::FileSelector => {
if self.file_selector_open {
return Task::none();
@@ -215,37 +216,14 @@ impl Settings {
.add_filter("image", &["png", "jpeg", "jpg"])
.pick_file();
- #[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)))
- }
+ Task::future(file_task).map(Message::FileSelected)
}
+ #[cfg(not(target_arch = "wasm32"))]
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"))]
- {
- self.background = file.path().to_string_lossy().to_string();
- }
- #[cfg(target_arch = "wasm32")]
- {
- self.background = file.file_name();
-
- let f = file.clone();
-
- return Task::future(async move { f.read().await }).map(|r| {
- Message::ToBackground(crate::background::Message::BackgroundRead(Ok(r)))
- });
- }
+ self.background = file.path().to_string_lossy().to_string();
}
Task::none()
@@ -357,26 +335,30 @@ impl Settings {
let mut background_mode_row =
row![text(self.background_mode.edit_text()).width(Length::FillPortion(1))];
- if self.background_mode == BackgroundMode::Local {
- let text = if self.background.is_empty() {
- save_message = None;
- "Select file..."
- } else {
- &self.background
- };
+ match self.background_mode {
+ #[cfg(not(target_arch = "wasm32"))]
+ BackgroundMode::Local => {
+ let text = if self.background.is_empty() {
+ save_message = None;
+ "Select file..."
+ } else {
+ &self.background
+ };
- background_mode_row = background_mode_row.push(
- button(text)
- .on_press(Message::FileSelector)
- .width(Length::FillPortion(2)),
- );
- } else {
- background_mode_row = background_mode_row.push(
- text_input(self.background_mode.default_background(), &self.background)
- .on_input(Message::Background)
- .width(Length::FillPortion(2))
- .style(color_style),
- );
+ background_mode_row = background_mode_row.push(
+ button(text)
+ .on_press(Message::FileSelector)
+ .width(Length::FillPortion(2)),
+ );
+ }
+ _ => {
+ background_mode_row = background_mode_row.push(
+ text_input(self.background_mode.default_background(), &self.background)
+ .on_input(Message::Background)
+ .width(Length::FillPortion(2))
+ .style(color_style),
+ );
+ }
}
let mut results = column![];