commit 8322ab86f1e79514395ff925a4021313484caa77
parent 20ed9b4655d13a6b8711dcafca50bbdb02a04df4
Author: Sylvia Ivory <git@sivory.net>
Date: Thu, 19 Jun 2025 20:06:46 -0700
Ensure proper image credits
Diffstat:
3 files changed, 105 insertions(+), 11 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
@@ -1289,6 +1289,7 @@ dependencies = [
"fjordgard-weather",
"iced",
"log",
+ "open",
"rfd",
"strum",
"tokio",
@@ -2314,6 +2315,25 @@ dependencies = [
]
[[package]]
+name = "is-docker"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3"
+dependencies = [
+ "once_cell",
+]
+
+[[package]]
+name = "is-wsl"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5"
+dependencies = [
+ "is-docker",
+ "once_cell",
+]
+
+[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3110,6 +3130,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
[[package]]
+name = "open"
+version = "5.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e2483562e62ea94312f3576a7aca397306df7990b8d89033e18766744377ef95"
+dependencies = [
+ "is-wsl",
+ "libc",
+ "pathdiff",
+]
+
+[[package]]
name = "openssl"
version = "0.10.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3276,6 +3307,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
[[package]]
+name = "pathdiff"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
+
+[[package]]
name = "percent-encoding"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
@@ -16,6 +16,7 @@ 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"
+open = "5.3.2"
rfd = "0.15.3"
strum = { version = "0.27.1", features = ["derive"] }
tokio = { version = "1.45.1", features = ["full"] }
diff --git a/src/background.rs b/src/background.rs
@@ -3,8 +3,9 @@ use fjordgard_unsplash::{
model::{Collection, CollectionPhotos, CollectionPhotosOptions, Format, PhotoFetchOptions},
};
use iced::{
- Color, ContentFit, Element, Length, Point, Renderer, Size, Task, Theme, mouse,
- widget::{canvas, container, image, stack, text},
+ Color, ContentFit, Element, Length, Point, Renderer, Size, Task, Theme,
+ mouse,
+ widget::{button, canvas, container, image, row, stack, text},
};
use log::{debug, error};
use tokio::fs;
@@ -65,6 +66,7 @@ pub enum Message {
UnsplashCollectionPhotos(Result<CollectionPhotos, String>),
RequestUnsplash(isize),
PauseUnsplash,
+ OpenUrl(String),
}
impl BackgroundHandle {
@@ -270,6 +272,13 @@ impl BackgroundHandle {
Task::none()
}
}
+ Message::OpenUrl(url) => {
+ if let Err(e) = open::that_detached(url) {
+ error!("failed to open link: {e}")
+ }
+
+ Task::none()
+ }
}
}
@@ -295,15 +304,62 @@ impl BackgroundHandle {
if self.mode == BackgroundMode::Local {
img.into()
} else {
- stack![
- img,
- // TODO; finish credits
- container(text("Photo, John Doe, Unsplash"))
- .align_left(Length::Fill)
- .align_bottom(Length::Fill)
- .padding(15)
- ]
- .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);
+
+ 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();
+ }
+ }
+
+ img.into()
}
} else {
Self::solid(Color::BLACK)