diff --git a/Cargo.lock b/Cargo.lock index 9fac504..fec1f9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -965,6 +965,17 @@ dependencies = [ "objc2 0.6.5", ] +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + [[package]] name = "dlib" version = "0.5.3" @@ -1098,6 +1109,7 @@ dependencies = [ "raw-window-handle", "smithay-clipboard", "web-time", + "webbrowser", "winit", ] @@ -1410,6 +1422,15 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + [[package]] name = "futures-core" version = "0.3.34" @@ -1728,6 +1749,110 @@ dependencies = [ "typenum", ] +[[package]] +name = "icu_collections" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0" + +[[package]] +name = "icu_properties" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa" + +[[package]] +name = "icu_provider" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d27bbb9d3abbefac45d55f647c9de1d44aafcd1186eb91879afef17c396c3e73" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + [[package]] name = "image" version = "0.25.10" @@ -1974,6 +2099,12 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + [[package]] name = "litrs" version = "1.0.1" @@ -2957,6 +3088,15 @@ dependencies = [ "portable-atomic", ] +[[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "zerovec", +] + [[package]] name = "ppmd-rust" version = "1.5.0" @@ -3635,6 +3775,12 @@ dependencies = [ "bitflags 2.13.2", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + [[package]] name = "static_assertions" version = "1.1.0" @@ -3835,6 +3981,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "synstructure" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + [[package]] name = "sys-locale" version = "0.3.2" @@ -3957,6 +4114,16 @@ dependencies = [ "strict-num", ] +[[package]] +name = "tinystr" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "tokio" version = "1.53.3" @@ -4164,6 +4331,18 @@ dependencies = [ "log", ] +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + [[package]] name = "usvg" version = "0.45.1" @@ -4192,6 +4371,12 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8c0a043c9540bae7c578c88f91dda8bd82e59ae27c21baca69c8b191aaf5a6e" +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "uuid" version = "1.28.0" @@ -4472,6 +4657,22 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webbrowser" +version = "1.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62c35be770821a214dbc362fc26908c853e776c0004294d0b10b8a6bad582f94" +dependencies = [ + "jni 0.22.4", + "log", + "ndk-context", + "objc2 0.6.5", + "objc2-app-kit 0.3.2", + "objc2-foundation 0.3.2", + "url", + "web-sys", +] + [[package]] name = "webpki-roots" version = "1.0.9" @@ -5040,6 +5241,12 @@ dependencies = [ "wayland-protocols-wlr", ] +[[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + [[package]] name = "x11-dl" version = "2.21.0" @@ -5119,6 +5326,29 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9" +[[package]] +name = "yoke" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8ebde2db3681e8c9980cc27822030e68752690ddfa9473e739aeb4dbde6d71" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", + "synstructure", +] + [[package]] name = "zbus" version = "5.19.0" @@ -5245,12 +5475,66 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", + "synstructure", +] + [[package]] name = "zeroize" version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" +[[package]] +name = "zerotrie" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0464e17806c1d976d5cba29399c7f08e516e279e2ba493f63123b5fca67dd8" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34df6fc39dbd26ddc9c10e6a2984476e13acce22e64e4487636ef494369225da" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + [[package]] name = "zip" version = "9.0.5" diff --git a/Cargo.toml b/Cargo.toml index 62261a4..5ddea60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ thiserror = "2" serde = { version = "1", features = ["derive"] } serde_json = "1" egui = "=0.36.2" -eframe = { version = "=0.36.2", default-features = false, features = ["wgpu", "wayland", "x11", "accesskit", "default_fonts"] } +eframe = { version = "=0.36.2", default-features = false, features = ["wgpu", "wayland", "x11", "accesskit", "default_fonts", "links"] } egui_extras = { version = "=0.36.2", features = ["svg", "image"] } image = { version = "0.25", default-features = false, features = ["jpeg", "png"] } rfd = "0.17" diff --git a/apps/desktop/src/app.rs b/apps/desktop/src/app.rs index b94ddce..26633af 100644 --- a/apps/desktop/src/app.rs +++ b/apps/desktop/src/app.rs @@ -59,7 +59,7 @@ pub struct App { /// Dev-only startup automation for screenshots/manual QA (see docs/dev/desktop.md): /// `CP_OPEN=` opens a game from the first database, `CP_PLY=` steps -/// along the main line, `CP_ANALYZE=1` starts the engine, `CP_SETTINGS=1` opens settings, +/// along the main line, `CP_ANALYZE=1` starts the engine, `CP_SETTINGS=1` opens settings (`=board`, `=about`: that tab), /// `CP_REVIEW=1` starts the whole-game analysis (`=dialog` only opens its dialog). #[derive(Default)] struct DebugStartup { @@ -148,8 +148,10 @@ impl App { if let Ok(tab) = std::env::var("CP_SETTINGS") { // Opened after a short delay (see debug_screenshot) so a fullscreen switch is done first. self.debug.open_settings = true; - if tab == "board" { - self.settings_ui.tab = Tab::Board; + match tab.as_str() { + "board" => self.settings_ui.tab = Tab::Board, + "about" => self.settings_ui.tab = Tab::About, + _ => {} } } self diff --git a/apps/desktop/src/i18n.rs b/apps/desktop/src/i18n.rs index a21795b..ac0b5f6 100644 --- a/apps/desktop/src/i18n.rs +++ b/apps/desktop/src/i18n.rs @@ -2691,6 +2691,86 @@ const ROWS: &[[&str; 6]] = &[ "Aljechin", "Alekhine", "Aljechin", + ], // Settings → About. + [ + "About", + "О программе", + "À propos", + "Über", + "Acerca de", + "Informazioni", + ], + [ + "Version", + "Версия", + "Version", + "Version", + "Versión", + "Versione", + ], + [ + "Free chess database software for Windows, macOS and Linux.", + "Бесплатная программа для работы с шахматными базами на Windows, macOS и Linux.", + "Logiciel gratuit pour bases de données d'échecs sur Windows, macOS et Linux.", + "Kostenloses Programm für Schachdatenbanken unter Windows, macOS und Linux.", + "Programa gratuito para bases de datos de ajedrez en Windows, macOS y Linux.", + "Programma gratuito per database di scacchi su Windows, macOS e Linux.", + ], + [ + "Website", + "Сайт", + "Site web", + "Website", + "Sitio web", + "Sito web", + ], + [ + "What's new", + "Что нового", + "Nouveautés", + "Neuigkeiten", + "Novedades", + "Novità", + ], + [ + "Source code", + "Исходный код", + "Code source", + "Quellcode", + "Código fuente", + "Codice sorgente", + ], + [ + "Found a problem or have an idea? Write to us:", + "Нашли проблему или есть идея? Напишите нам:", + "Un problème ou une idée ? Écrivez-nous :", + "Ein Problem gefunden oder eine Idee? Schreiben Sie uns:", + "¿Has encontrado un problema o tienes una idea? Escríbenos:", + "Hai trovato un problema o hai un'idea? Scrivici:", + ], + [ + "ChessPenguin is free. If it is useful to you, you can support its development.", + "ChessPenguin бесплатен. Если программа вам полезна, вы можете поддержать её развитие.", + "ChessPenguin est gratuit. S'il vous est utile, vous pouvez soutenir son développement.", + "ChessPenguin ist kostenlos. Wenn es Ihnen nützt, können Sie die Entwicklung unterstützen.", + "ChessPenguin es gratuito. Si te resulta útil, puedes apoyar su desarrollo.", + "ChessPenguin è gratuito. Se ti è utile, puoi sostenerne lo sviluppo.", + ], + [ + "Support the project", + "Поддержать проект", + "Soutenir le projet", + "Projekt unterstützen", + "Apoyar el proyecto", + "Sostieni il progetto", + ], + [ + "Free software under GPL-3.0-or-later. Piece sets, boards and sounds come from Lichess under their own free licences.", + "Свободная программа под лицензией GPL-3.0-or-later. Наборы фигур, доски и звуки взяты из Lichess под их собственными свободными лицензиями.", + "Logiciel libre sous GPL-3.0-or-later. Les jeux de pièces, échiquiers et sons viennent de Lichess, sous leurs propres licences libres.", + "Freie Software unter GPL-3.0-or-later. Figurensätze, Bretter und Sounds stammen von Lichess, unter ihren eigenen freien Lizenzen.", + "Software libre bajo GPL-3.0-or-later. Los juegos de piezas, tableros y sonidos provienen de Lichess, con sus propias licencias libres.", + "Software libero sotto GPL-3.0-or-later. Set di pezzi, scacchiere e suoni provengono da Lichess, con le loro licenze libere.", ], ]; diff --git a/apps/desktop/src/settings_ui.rs b/apps/desktop/src/settings_ui.rs index 5c14f99..87bbc34 100644 --- a/apps/desktop/src/settings_ui.rs +++ b/apps/desktop/src/settings_ui.rs @@ -1,4 +1,4 @@ -//! Settings window: engines, board & pieces, sound, interface. +//! Settings window: engines, board & pieces, sound, interface, about. use crate::i18n::{Lang, tr, trf}; use egui::{RichText, Sense, Ui, vec2}; @@ -14,6 +14,7 @@ pub enum Tab { Board, Sound, Interface, + About, } pub enum SettingsAction { @@ -67,12 +68,14 @@ impl SettingsWindow { ui.selectable_value(&mut self.tab, Tab::Board, tr("Board & pieces")); ui.selectable_value(&mut self.tab, Tab::Sound, tr("Sound")); ui.selectable_value(&mut self.tab, Tab::Interface, tr("Interface")); + ui.selectable_value(&mut self.tab, Tab::About, tr("About")); }); ui.separator(); egui::ScrollArea::vertical().show(ui, |ui| match self.tab { Tab::Engines => self.engines(ui, s, &mut actions, &mut changed), Tab::Board => board_tab(ui, s, &mut changed), Tab::Sound => sound_tab(ui, s, &mut actions, &mut changed), + Tab::About => about_tab(ui, s.language), Tab::Interface => { ui.horizontal(|ui| { ui.label(tr("Language:")); @@ -464,6 +467,65 @@ fn board_tab(ui: &mut Ui, s: &mut Settings, changed: &mut bool) { .changed(); } +const SITE: &str = "https://chess.vrubel.xyz"; +const REPO: &str = "https://github.com/vrubelroman/chessPenguin"; + +/// Version, links to the website and the sources, support contacts, donations. +fn about_tab(ui: &mut Ui, lang: Lang) { + let version = env!("CARGO_PKG_VERSION"); + // The website page in the interface language. + let site = match lang { + Lang::En => format!("{SITE}/"), + Lang::Ru => format!("{SITE}/ru/"), + Lang::Fr => format!("{SITE}/fr/"), + Lang::De => format!("{SITE}/de/"), + Lang::Es => format!("{SITE}/es/"), + Lang::It => format!("{SITE}/it/"), + }; + ui.add_space(6.0); + ui.label(RichText::new("ChessPenguin").size(22.0).strong()); + ui.label(format!("{} {version}", tr("Version"))); + ui.label( + RichText::new(tr( + "Free chess database software for Windows, macOS and Linux.", + )) + .weak(), + ); + ui.add_space(8.0); + ui.horizontal_wrapped(|ui| { + ui.hyperlink_to(tr("Website"), &site); + ui.label("·"); + ui.hyperlink_to(tr("What's new"), format!("{REPO}/releases/tag/v{version}")); + ui.label("·"); + ui.hyperlink_to(tr("Source code"), REPO); + }); + ui.add_space(14.0); + ui.label(RichText::new(tr("Found a problem or have an idea? Write to us:")).strong()); + ui.horizontal_wrapped(|ui| { + ui.hyperlink_to("vrubelroman@gmail.com", "mailto:vrubelroman@gmail.com"); + ui.label("·"); + ui.hyperlink_to("Telegram @vrubelr", "https://t.me/vrubelr"); + }); + ui.add_space(14.0); + ui.label( + RichText::new(tr( + "ChessPenguin is free. If it is useful to you, you can support its development.", + )) + .weak(), + ); + if ui.button(tr("Support the project")).clicked() { + // The website sends this on to the current donation page. + ui.ctx() + .open_url(egui::OpenUrl::new_tab(format!("{SITE}/donate"))); + } + ui.add_space(14.0); + ui.label( + RichText::new(tr("Free software under GPL-3.0-or-later. Piece sets, boards and sounds come from Lichess under their own free licences.")) + .weak() + .small(), + ); +} + fn sound_tab(ui: &mut Ui, s: &mut Settings, actions: &mut Vec, changed: &mut bool) { *changed |= ui .checkbox(&mut s.sound_enabled, tr("Move sounds")) diff --git a/docs/dev/desktop.md b/docs/dev/desktop.md index d9eeeec..3c9a1e5 100644 --- a/docs/dev/desktop.md +++ b/docs/dev/desktop.md @@ -42,7 +42,7 @@ XDG_CONFIG_HOME=/tmp/cfg CP_OPEN=11 CP_PLY=3 CP_ANALYZE=1 ./target/debug/chesspe ``` `CP_OPEN` — индекс партии (с 0) в первой базе списка, `CP_PLY` — шагов по основной линии, -`CP_ANALYZE` — запустить активный движок, `CP_SETTINGS` — открыть настройки, `CP_ENGINE_PANEL` — раскрыть панель настроек движка, `CP_VAR` — перейти в первый вариант после `CP_PLY`, `CP_REVIEW=1` — запустить анализ партии (`=dialog` — только открыть окно), `CP_REPORT=1` — открыть вкладку «Отчёт» (нужен готовый анализ), `CP_BEST=k` — показать на доске k-й ход лучшей линии у первой отметки движка (нужен готовый анализ), `CP_ENGINE_OFFER=1` — окно предложения скачать Stockfish (`=download` — сразу начать загрузку), `CP_BOARD="e4 c5 Nf3"` — доска поиска большой базы с этими ходами (SAN), `CP_SORT=date` — большая база по дате (новые сверху), `CP_PANE=hidden` — большая база без правой панели, `CP_FILTER="player=carlsen;years=2015-2026;elo=2600"` — несколько фильтров большой базы, `CP_FILTER_PLAYER=имя` — фильтр «Игрок» большой базы ChessBase при запуске, `CP_SCREENSHOT=file.png` (+ `CP_SCREENSHOT_DELAY=сек`) — полноэкранный снимок окна и выход; так сделаны `docs/screenshots/`. +`CP_ANALYZE` — запустить активный движок, `CP_SETTINGS` — открыть настройки (`=board`, `=about` — сразу эту вкладку), `CP_ENGINE_PANEL` — раскрыть панель настроек движка, `CP_VAR` — перейти в первый вариант после `CP_PLY`, `CP_REVIEW=1` — запустить анализ партии (`=dialog` — только открыть окно), `CP_REPORT=1` — открыть вкладку «Отчёт» (нужен готовый анализ), `CP_BEST=k` — показать на доске k-й ход лучшей линии у первой отметки движка (нужен готовый анализ), `CP_ENGINE_OFFER=1` — окно предложения скачать Stockfish (`=download` — сразу начать загрузку), `CP_BOARD="e4 c5 Nf3"` — доска поиска большой базы с этими ходами (SAN), `CP_SORT=date` — большая база по дате (новые сверху), `CP_PANE=hidden` — большая база без правой панели, `CP_FILTER="player=carlsen;years=2015-2026;elo=2600"` — несколько фильтров большой базы, `CP_FILTER_PLAYER=имя` — фильтр «Игрок» большой базы ChessBase при запуске, `CP_SCREENSHOT=file.png` (+ `CP_SCREENSHOT_DELAY=сек`) — полноэкранный снимок окна и выход; так сделаны `docs/screenshots/`. ## Языки diff --git a/website/.env.example b/website/.env.example index a4cd142..d2ffa68 100644 --- a/website/.env.example +++ b/website/.env.example @@ -15,3 +15,7 @@ STATS_PASSWORD= GITHUB_REPO=vrubelroman/chessPenguin # Take the visitor address from X-Forwarded-For / X-Real-IP (set by nginx). TRUST_PROXY=1 + +# Where /donate leads (the program's "Support the project" button). Empty: the support +# section of the page. +DONATE_URL= diff --git a/website/server/src/main.rs b/website/server/src/main.rs index cf75177..3cbe854 100644 --- a/website/server/src/main.rs +++ b/website/server/src/main.rs @@ -58,6 +58,9 @@ struct Config { stats_password: String, /// Take the client address from `X-Forwarded-For` / `X-Real-IP` (behind nginx). trust_proxy: bool, + /// Where `/donate` (the program's "Support the project") leads; the support + /// section of the page while it is empty. + donate_url: String, } impl Config { @@ -78,6 +81,7 @@ impl Config { stats_user: var("STATS_USER", "admin"), stats_password: var("STATS_PASSWORD", ""), trust_proxy: var("TRUST_PROXY", "1") != "0", + donate_url: var("DONATE_URL", ""), } } } @@ -207,6 +211,7 @@ async fn main() { .route("/api/release", get(api_release)) .route("/download/{platform}", get(download)) .route("/hit", post(hit)) + .route("/donate", get(donate)) .route("/stats", get(stats)) .route("/stats.csv", get(stats_csv)) .route("/healthz", get(|| async { "ok" })) @@ -405,6 +410,15 @@ async fn hit( StatusCode::NO_CONTENT } +/// `/donate`: the current donation page, so the program's link never has to change. +async fn donate(State(state): State) -> Redirect { + if state.config.donate_url.is_empty() { + Redirect::temporary("/#support") + } else { + Redirect::temporary(&state.config.donate_url) + } +} + /// `/`: English, or `?lang=xx` → `/xx/`. async fn home(state: State, Query(q): Query>) -> Response { if let Some(lang) = q.get("lang")