mirror of
https://github.com/Linkatplug/Gotify-Windows-Basic-Client.git
synced 2026-12-06 08:46:21 +00:00
Gotify Lite 2.1.1 : corrections de la relecture
- Erreurs de connexion traduites à l'affichage (type i18n::Text, macro tr!) - Message DNS traduit - Infobulle : l'avertissement de blocage n'efface plus le silence - Dates anciennes dans l'ordre de la langue - Clés du menu écrites une fois (k!) et couvertes par le test de traduction - Le service réarme l'évènement d'arrêt au démarrage - Écritures de state.json sérialisées (last_id ne peut plus être écrasé) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b8c3b829c6
commit
91f07cc257
8 files changed
+194
-71
No files matched your search
@@ -1,15 +1,18 @@
|
||||
## Gotify Lite 2.1.0 — now in 5 languages
|
||||
## Gotify Lite 2.1.1 — fixes
|
||||
|
||||
### New
|
||||
- The app is translated into **English, French, Dutch, German and Spanish** (window, tray menu, notifications)
|
||||
- The language follows Windows by default and can be changed in *Settings → General → Language*
|
||||
- English documentation ([README](https://github.com/Linkatplug/Gotify-Windows-Basic-Client#readme)); French version in [README.fr.md](https://github.com/Linkatplug/Gotify-Windows-Basic-Client/blob/master/README.fr.md)
|
||||
### Fixed
|
||||
- Connection errors now follow a language change right away (they were kept in the previous language until the next reconnect)
|
||||
- The DNS error message is translated
|
||||
- Tray tooltip: the "notifications blocked by Windows" warning no longer hides the do-not-disturb countdown or the "notifications off" line
|
||||
- Dates of messages older than 30 days use the order of the chosen language (e.g. "Mar 12, 2026" in English)
|
||||
- Gotify Lite could quit right after being restarted if the stop signal of a previous instance was still pending
|
||||
- The last-read message id could be overwritten when the connection was established, which could skip the catch-up of missed messages
|
||||
- Translation tests now also cover the tray menu and the Windows blocking messages
|
||||
|
||||
### Install
|
||||
Download `gotify-lite.exe` below and run it. To update, quit Gotify Lite from the tray icon and replace the executable: your settings are kept.
|
||||
The executable isn't code-signed: SmartScreen may ask you to click *More info → Run anyway*.
|
||||
You need a Gotify **client** token (Clients → Create client).
|
||||
|
||||
---
|
||||
|
||||
**Nouveautés (FR)** : l'application est traduite en anglais, français, néerlandais, allemand et espagnol ; la langue suit Windows et se change dans *Paramètres → Général → Langue*. Pour mettre à jour, quittez Gotify Lite et remplacez l'exécutable : vos réglages sont conservés.
|
||||
**Corrections (FR)** : erreurs de connexion traduites dès le changement de langue, message DNS traduit, infobulle qui n'efface plus le silence, dates selon la langue, redémarrage du service fiabilisé, rattrapage des messages manqués fiabilisé.
|
||||
Generated
+1
-1
@@ -1255,7 +1255,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gotify-lite"
|
||||
version = "2.1.0"
|
||||
version = "2.1.1"
|
||||
dependencies = [
|
||||
"eframe",
|
||||
"image",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "gotify-lite"
|
||||
version = "2.1.0"
|
||||
version = "2.1.1"
|
||||
edition = "2024"
|
||||
description = "Client Gotify léger pour Windows (tray + notifications natives)"
|
||||
license = "MIT"
|
||||
|
||||
+46
-40
@@ -15,7 +15,7 @@ use windows::Win32::System::Threading::GetCurrentThreadId;
|
||||
use windows::Win32::UI::WindowsAndMessaging::*;
|
||||
|
||||
use crate::config::{Config, MUTE_FOREVER, State};
|
||||
use crate::i18n::{self, Lang, t};
|
||||
use crate::i18n::{self, Lang, Text, t};
|
||||
use crate::gotify::{self, Client, Message};
|
||||
use crate::icon::{self, Look};
|
||||
use crate::notify::{Notifier, Toast};
|
||||
@@ -24,12 +24,16 @@ use crate::sys;
|
||||
const READ_TIMEOUT: Duration = Duration::from_secs(100); // Gotify pingue toutes les 45 s par défaut
|
||||
const OPEN_URL: &str = "gotify-lite:open";
|
||||
|
||||
/// state.json est modifié par le thread de l'icône et par celui du flux : chaque
|
||||
/// lecture-modification-écriture se fait sous ce verrou pour ne pas perdre `last_id`.
|
||||
static STATE_LOCK: Mutex<()> = Mutex::new(());
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
enum Status {
|
||||
Unconfigured,
|
||||
Connecting,
|
||||
Connected(String),
|
||||
Error(String),
|
||||
Error(Text),
|
||||
}
|
||||
|
||||
struct Shared {
|
||||
@@ -162,27 +166,35 @@ fn tray_loop(shared: Arc<Shared>) {
|
||||
}));
|
||||
|
||||
let menu = Menu::new();
|
||||
let item = |id: &str, key: &'static str, enabled: bool| MenuItem::with_id(id, t(key), enabled, None);
|
||||
let status_item = MenuItem::with_id("status", t!("Connexion…"), false, None);
|
||||
let open = item("open", "Ouvrir Gotify Lite", true);
|
||||
let notif_toggle =
|
||||
CheckMenuItem::with_id("toggle", t!("Notifications activées"), true, shared.cfg.lock().unwrap().notifications, None);
|
||||
// Chaque libellé traduisible est enregistré dans `texts` pour suivre la langue.
|
||||
let mut texts: Vec<(MenuText, &'static str)> = Vec::new();
|
||||
let mut item = |id: &str, key: &'static str, enabled: bool| {
|
||||
let m = MenuItem::with_id(id, t(key), enabled, None);
|
||||
texts.push((MenuText::Item(m.clone()), key));
|
||||
m
|
||||
};
|
||||
let open = item("open", k!("Ouvrir Gotify Lite"), true);
|
||||
let mute_items = [
|
||||
("mute:30", "30 minutes"),
|
||||
("mute:60", "1 heure"),
|
||||
("mute:240", "4 heures"),
|
||||
("mute:morning", "Jusqu'à demain 8 h"),
|
||||
("mute:forever", "Jusqu'à réactivation"),
|
||||
]
|
||||
.map(|(id, key)| (item(id, key, true), key));
|
||||
let mute = Submenu::with_id("mute", t!("Silence"), true);
|
||||
for (m, _) in &mute_items {
|
||||
item("mute:30", k!("30 minutes"), true),
|
||||
item("mute:60", k!("1 heure"), true),
|
||||
item("mute:240", k!("4 heures"), true),
|
||||
item("mute:morning", k!("Jusqu'à demain 8 h"), true),
|
||||
item("mute:forever", k!("Jusqu'à réactivation"), true),
|
||||
];
|
||||
let unmute = item("unmute", k!("Réactiver le son et les bannières"), false);
|
||||
let settings = item("settings", k!("Paramètres…"), true);
|
||||
let reconnect = item("reconnect", k!("Reconnecter"), true);
|
||||
let quit = item("quit", k!("Quitter"), true);
|
||||
let status_item = MenuItem::with_id("status", t!("Connexion…"), false, None);
|
||||
let toggle_key = k!("Notifications activées");
|
||||
let notif_toggle = CheckMenuItem::with_id("toggle", t(toggle_key), true, shared.cfg.lock().unwrap().notifications, None);
|
||||
texts.push((MenuText::Check(notif_toggle.clone()), toggle_key));
|
||||
let mute_key = k!("Silence");
|
||||
let mute = Submenu::with_id("mute", t(mute_key), true);
|
||||
for m in &mute_items {
|
||||
let _ = mute.append(m);
|
||||
}
|
||||
let unmute = item("unmute", "Réactiver le son et les bannières", false);
|
||||
let settings = item("settings", "Paramètres…", true);
|
||||
let reconnect = item("reconnect", "Reconnecter", true);
|
||||
let quit = item("quit", "Quitter", true);
|
||||
texts.push((MenuText::Sub(mute.clone()), mute_key));
|
||||
let _ = menu.append_items(&[
|
||||
&status_item,
|
||||
&PredefinedMenuItem::separator(),
|
||||
@@ -195,16 +207,6 @@ fn tray_loop(shared: Arc<Shared>) {
|
||||
&reconnect,
|
||||
&quit,
|
||||
]);
|
||||
let mut texts = vec![
|
||||
(MenuText::Item(open), "Ouvrir Gotify Lite"),
|
||||
(MenuText::Check(notif_toggle.clone()), "Notifications activées"),
|
||||
(MenuText::Sub(mute), "Silence"),
|
||||
(MenuText::Item(unmute.clone()), "Réactiver le son et les bannières"),
|
||||
(MenuText::Item(settings), "Paramètres…"),
|
||||
(MenuText::Item(reconnect), "Reconnecter"),
|
||||
(MenuText::Item(quit), "Quitter"),
|
||||
];
|
||||
texts.extend(mute_items.into_iter().map(|(m, k)| (MenuText::Item(m), k)));
|
||||
|
||||
let tray = TrayIconBuilder::new()
|
||||
.with_icon(make_icon(Look::Disconnected))
|
||||
@@ -292,6 +294,7 @@ fn tray_loop(shared: Arc<Shared>) {
|
||||
}
|
||||
shared.quit.store(true, Ordering::SeqCst);
|
||||
shared.force_reconnect();
|
||||
let _g = STATE_LOCK.lock().unwrap();
|
||||
let mut st = State::load();
|
||||
st.status = "stopped".into();
|
||||
st.daemon_pid = 0;
|
||||
@@ -380,16 +383,17 @@ fn refresh_tray(shared: &Shared, ui: &mut TrayUi, last_state: &mut State) {
|
||||
ui.tooltip.clear(); // force la mise à jour du libellé d'état
|
||||
}
|
||||
let mut tooltip = format!("{}\n{}", sys::APP_NAME, status_text);
|
||||
if let Some(b) = ui.blocked {
|
||||
tooltip.push_str("\n⚠ ");
|
||||
tooltip.push_str(t(b));
|
||||
} else if !cfg.notifications {
|
||||
if !cfg.notifications {
|
||||
tooltip.push('\n');
|
||||
tooltip.push_str(t!("Notifications désactivées"));
|
||||
} else if let Some(m) = &mute {
|
||||
tooltip.push('\n');
|
||||
tooltip.push_str(m);
|
||||
}
|
||||
if let Some(b) = ui.blocked {
|
||||
tooltip.push_str("\n⚠ ");
|
||||
tooltip.push_str(t(b));
|
||||
}
|
||||
let tooltip: String = tooltip.chars().take(127).collect();
|
||||
if tooltip != ui.tooltip {
|
||||
let _ = ui.tray.set_tooltip(Some(&tooltip));
|
||||
@@ -404,8 +408,9 @@ fn refresh_tray(shared: &Shared, ui: &mut TrayUi, last_state: &mut State) {
|
||||
Status::Unconfigured => ("unconfigured", String::new()),
|
||||
Status::Connecting => ("connecting", String::new()),
|
||||
Status::Connected(h) => ("connected", h.clone()),
|
||||
Status::Error(e) => ("error", e.clone()),
|
||||
Status::Error(e) => ("error", e.to_string()),
|
||||
};
|
||||
let _g = STATE_LOCK.lock().unwrap();
|
||||
let mut st = State::load();
|
||||
st.status = code.into();
|
||||
st.detail = detail;
|
||||
@@ -453,7 +458,7 @@ fn worker(shared: Arc<Shared>) {
|
||||
if let Err(e) = &result {
|
||||
sys::log(&format!("flux : {e}"));
|
||||
}
|
||||
shared.set_status(Status::Error(result.err().unwrap_or_else(|| t!("connexion fermée par le serveur").into())));
|
||||
shared.set_status(Status::Error(result.err().unwrap_or_else(|| tr!("connexion fermée par le serveur"))));
|
||||
if started.elapsed() > Duration::from_secs(60) {
|
||||
backoff = 1;
|
||||
}
|
||||
@@ -470,7 +475,7 @@ fn wait(shared: &Shared, generation: u64, secs: u64) {
|
||||
}
|
||||
}
|
||||
|
||||
fn session(shared: &Shared, cfg: &Config, notifier: &Notifier) -> Result<(), String> {
|
||||
fn session(shared: &Shared, cfg: &Config, notifier: &Notifier) -> Result<(), Text> {
|
||||
let (mut ws, handle) = gotify::connect_stream(cfg, READ_TIMEOUT)?;
|
||||
*shared.sock.lock().unwrap() = Some(handle);
|
||||
let client = Client::new(cfg);
|
||||
@@ -510,9 +515,9 @@ fn session(shared: &Shared, cfg: &Config, notifier: &Notifier) -> Result<(), Str
|
||||
loop {
|
||||
let msg = ws.read().map_err(|e| match e {
|
||||
tungstenite::Error::Io(io) if io.kind() == std::io::ErrorKind::TimedOut || io.kind() == std::io::ErrorKind::WouldBlock => {
|
||||
t!("plus de nouvelles du serveur (timeout)").to_string()
|
||||
tr!("plus de nouvelles du serveur (timeout)")
|
||||
}
|
||||
other => other.to_string(),
|
||||
other => Text::Raw(other.to_string()),
|
||||
})?;
|
||||
match msg {
|
||||
tungstenite::Message::Text(t) => {
|
||||
@@ -527,13 +532,14 @@ fn session(shared: &Shared, cfg: &Config, notifier: &Notifier) -> Result<(), Str
|
||||
last_id = m.id;
|
||||
save_last_id(last_id);
|
||||
}
|
||||
tungstenite::Message::Close(_) => return Err(t!("connexion fermée par le serveur").into()),
|
||||
tungstenite::Message::Close(_) => return Err(tr!("connexion fermée par le serveur")),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn save_last_id(id: u64) {
|
||||
let _g = STATE_LOCK.lock().unwrap();
|
||||
let mut st = State::load();
|
||||
if st.last_id != id {
|
||||
st.last_id = id;
|
||||
|
||||
+15
-13
@@ -9,6 +9,7 @@ use tungstenite::stream::MaybeTlsStream;
|
||||
use tungstenite::{Connector, WebSocket};
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::i18n::Text;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct Message {
|
||||
@@ -225,53 +226,54 @@ pub type Stream = WebSocket<MaybeTlsStream<TcpStream>>;
|
||||
|
||||
/// Ouvre le flux temps réel. Retourne aussi un clone du socket TCP pour pouvoir
|
||||
/// interrompre la lecture bloquante depuis un autre thread (shutdown).
|
||||
pub fn connect_stream(cfg: &Config, read_timeout: Duration) -> Result<(Stream, TcpStream)> {
|
||||
pub fn connect_stream(cfg: &Config, read_timeout: Duration) -> std::result::Result<(Stream, TcpStream), Text> {
|
||||
let raw = |e: &dyn std::fmt::Display| Text::Raw(e.to_string());
|
||||
let base = normalize_url(&cfg.server_url);
|
||||
let ws_url = if let Some(rest) = base.strip_prefix("https://") {
|
||||
format!("wss://{rest}/stream")
|
||||
} else if let Some(rest) = base.strip_prefix("http://") {
|
||||
format!("ws://{rest}/stream")
|
||||
} else {
|
||||
return Err(t!("L'URL doit commencer par http:// ou https://").into());
|
||||
return Err(tr!("L'URL doit commencer par http:// ou https://"));
|
||||
};
|
||||
let mut req = ws_url.as_str().into_client_request().map_err(|e| e.to_string())?;
|
||||
let token = tungstenite::http::HeaderValue::from_str(cfg.token.trim()).map_err(|_| t!("Token invalide").to_string())?;
|
||||
let mut req = ws_url.as_str().into_client_request().map_err(|e| raw(&e))?;
|
||||
let token = tungstenite::http::HeaderValue::from_str(cfg.token.trim()).map_err(|_| tr!("Token invalide"))?;
|
||||
req.headers_mut().insert("X-Gotify-Key", token);
|
||||
|
||||
let uri = req.uri().clone();
|
||||
let host = uri.host().ok_or_else(|| t!("URL sans hôte").to_string())?.trim_start_matches('[').trim_end_matches(']').to_string();
|
||||
let host = uri.host().ok_or_else(|| tr!("URL sans hôte"))?.trim_start_matches('[').trim_end_matches(']').to_string();
|
||||
let port = uri.port_u16().unwrap_or(if uri.scheme_str() == Some("wss") { 443 } else { 80 });
|
||||
let addrs: Vec<_> = (host.as_str(), port).to_socket_addrs().map_err(|e| format!("DNS : {e}"))?.collect();
|
||||
let mut last_err = t!("aucune adresse").to_string();
|
||||
let addrs: Vec<_> = (host.as_str(), port).to_socket_addrs().map_err(|e| tr!("DNS : {}", e.to_string()))?.collect();
|
||||
let mut last_err = tr!("aucune adresse");
|
||||
let tcp = addrs
|
||||
.iter()
|
||||
.find_map(|a| match TcpStream::connect_timeout(a, Duration::from_secs(10)) {
|
||||
Ok(s) => Some(s),
|
||||
Err(e) => {
|
||||
last_err = e.to_string();
|
||||
last_err = raw(&e);
|
||||
None
|
||||
}
|
||||
})
|
||||
.ok_or_else(|| tf!("Connexion impossible à {}:{} : {}", host, port, last_err))?;
|
||||
.ok_or_else(|| tr!("Connexion impossible à {}:{} : {}", &host, port, last_err))?;
|
||||
tcp.set_nodelay(true).ok();
|
||||
tcp.set_read_timeout(Some(Duration::from_secs(15))).ok(); // handshake
|
||||
let handle = tcp.try_clone().map_err(|e| e.to_string())?;
|
||||
let handle = tcp.try_clone().map_err(|e| raw(&e))?;
|
||||
|
||||
let connector = if uri.scheme_str() == Some("wss") {
|
||||
let tls = native_tls::TlsConnector::builder()
|
||||
.danger_accept_invalid_certs(cfg.accept_invalid_certs)
|
||||
.danger_accept_invalid_hostnames(cfg.accept_invalid_certs)
|
||||
.build()
|
||||
.map_err(|e| e.to_string())?;
|
||||
.map_err(|e| raw(&e))?;
|
||||
Connector::NativeTls(tls)
|
||||
} else {
|
||||
Connector::Plain
|
||||
};
|
||||
let (mut ws, _resp) = tungstenite::client_tls_with_config(req, tcp, None, Some(connector)).map_err(|e| match e {
|
||||
tungstenite::HandshakeError::Failure(tungstenite::Error::Http(r)) if r.status() == 401 => {
|
||||
t!("Token refusé (401) : utilisez un token *client*").to_string()
|
||||
tr!("Token refusé (401) : utilisez un token *client*")
|
||||
}
|
||||
other => other.to_string(),
|
||||
other => raw(&other),
|
||||
})?;
|
||||
// Sous Windows, SO_RCVTIMEO n'est pas partagé entre handles dupliqués : on règle le socket réellement lu.
|
||||
match ws.get_mut() {
|
||||
|
||||
+79
-1
@@ -90,6 +90,68 @@ pub fn tf(key: &str, args: &[&dyn Display]) -> String {
|
||||
out
|
||||
}
|
||||
|
||||
/// Texte traduit au moment de l'affichage (et non à sa création) : un message d'erreur
|
||||
/// conservé suit ainsi un changement de langue.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Text {
|
||||
Raw(String),
|
||||
Key(&'static str, Vec<Text>),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Text {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Text::Raw(s) => f.write_str(s),
|
||||
Text::Key(k, args) if args.is_empty() => f.write_str(t(k)),
|
||||
Text::Key(k, args) => {
|
||||
let args: Vec<&dyn Display> = args.iter().map(|a| a as &dyn Display).collect();
|
||||
f.write_str(&tf(k, &args))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Argument de `tr!` : un `Text` reste traduisible, le reste est figé tel quel.
|
||||
pub trait ToText {
|
||||
fn to_text(self) -> Text;
|
||||
}
|
||||
|
||||
impl ToText for Text {
|
||||
fn to_text(self) -> Text {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! raw_to_text {
|
||||
($($t:ty),*) => {$(
|
||||
impl ToText for $t {
|
||||
fn to_text(self) -> Text {
|
||||
Text::Raw(self.to_string())
|
||||
}
|
||||
}
|
||||
)*};
|
||||
}
|
||||
raw_to_text!(String, &String, &str, u16, u32, u64, i64, usize);
|
||||
|
||||
/// Comme `t!`/`tf!`, mais la traduction est faite à l'affichage.
|
||||
#[macro_export]
|
||||
macro_rules! tr {
|
||||
($k:literal) => {
|
||||
$crate::i18n::Text::Key($k, Vec::new())
|
||||
};
|
||||
($k:literal, $($a:expr),+ $(,)?) => {
|
||||
$crate::i18n::Text::Key($k, vec![$($crate::i18n::ToText::to_text($a)),+])
|
||||
};
|
||||
}
|
||||
|
||||
/// Marque une clé traduite plus tard avec `t(…)` (vérifiée par le test `every_key_translated`).
|
||||
#[macro_export]
|
||||
macro_rules! k {
|
||||
($k:literal) => {
|
||||
$k
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! t {
|
||||
($k:literal) => {
|
||||
@@ -310,6 +372,7 @@ static TABLE: &[[&str; 5]] = &[
|
||||
["il y a {} min", "{} min ago", "{} min geleden", "vor {} Min.", "hace {} min"],
|
||||
["il y a {} h", "{} h ago", "{} u geleden", "vor {} Std.", "hace {} h"],
|
||||
["hier", "yesterday", "gisteren", "gestern", "ayer"],
|
||||
["DNS : {}", "DNS: {}", "DNS: {}", "DNS: {}", "DNS: {}"],
|
||||
["il y a {} j", "{} d ago", "{} d geleden", "vor {} T.", "hace {} d"],
|
||||
];
|
||||
|
||||
@@ -328,7 +391,7 @@ mod tests {
|
||||
continue;
|
||||
}
|
||||
let src = std::fs::read_to_string(path).unwrap();
|
||||
for mac in ["t!(\"", "tf!(\""] {
|
||||
for mac in ["t!(\"", "tf!(\"", "tr!(\"", "k!(\""] {
|
||||
for (i, _) in src.match_indices(mac) {
|
||||
// Ignore `format!(`, `print!(`… : le macro doit commencer un identifiant.
|
||||
if src[..i].chars().next_back().is_some_and(|c| c.is_alphanumeric() || c == '_') {
|
||||
@@ -372,10 +435,25 @@ mod tests {
|
||||
assert_eq!(index().len(), TABLE.len());
|
||||
}
|
||||
|
||||
/// Les tests qui changent la langue globale ne doivent pas s'exécuter en même temps.
|
||||
static LANG_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
|
||||
|
||||
#[test]
|
||||
fn format() {
|
||||
let _g = LANG_LOCK.lock().unwrap();
|
||||
CURRENT.store(Lang::En as u8, Ordering::Relaxed);
|
||||
assert_eq!(tf("Connexion impossible à {}:{} : {}", &[&"h", &443, &"x"]), "Cannot connect to h:443: x");
|
||||
assert_eq!(t("texte inconnu"), "texte inconnu");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_follows_language() {
|
||||
let _g = LANG_LOCK.lock().unwrap();
|
||||
let e = tr!("Connexion impossible à {}:{} : {}", "h", 443u16, tr!("aucune adresse"));
|
||||
CURRENT.store(Lang::En as u8, Ordering::Relaxed);
|
||||
assert_eq!(e.to_string(), "Cannot connect to h:443: no address");
|
||||
CURRENT.store(Lang::De as u8, Ordering::Relaxed);
|
||||
assert_eq!(e.to_string(), "Keine Verbindung zu h:443: keine Adresse");
|
||||
CURRENT.store(Lang::En as u8, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -59,11 +59,11 @@ impl Notifier {
|
||||
let setting = self.inner.as_ref()?.Setting().ok()?;
|
||||
match setting {
|
||||
S::Enabled => None,
|
||||
S::DisabledForUser => Some("Les notifications Windows sont désactivées pour votre session"),
|
||||
S::DisabledForApplication => Some("Les notifications de Gotify Lite sont désactivées dans Windows"),
|
||||
S::DisabledByGroupPolicy => Some("Les notifications sont désactivées par une stratégie de groupe"),
|
||||
S::DisabledByManifest => Some("Notifications refusées par Windows"),
|
||||
_ => Some("Notifications bloquées par Windows"),
|
||||
S::DisabledForUser => Some(k!("Les notifications Windows sont désactivées pour votre session")),
|
||||
S::DisabledForApplication => Some(k!("Les notifications de Gotify Lite sont désactivées dans Windows")),
|
||||
S::DisabledByGroupPolicy => Some(k!("Les notifications sont désactivées par une stratégie de groupe")),
|
||||
S::DisabledByManifest => Some(k!("Notifications refusées par Windows")),
|
||||
_ => Some(k!("Notifications bloquées par Windows")),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+37
-3
@@ -379,6 +379,26 @@ pub fn parse_rfc3339(s: &str) -> Option<i64> {
|
||||
Some(days * 86400 + h * 3600 + mi * 60 + se - offset)
|
||||
}
|
||||
|
||||
/// `AAAA-MM-JJ` → date courte dans l'ordre habituel de la langue.
|
||||
fn short_date(d: &str) -> String {
|
||||
short_date_in(d, crate::i18n::current())
|
||||
}
|
||||
|
||||
fn short_date_in(d: &str, lang: crate::i18n::Lang) -> String {
|
||||
use crate::i18n::Lang;
|
||||
let (y, m, day) = (&d[..4], &d[5..7], &d[8..10]);
|
||||
match lang {
|
||||
Lang::En => {
|
||||
const MONTHS: [&str; 12] = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
||||
let name = m.parse::<usize>().ok().and_then(|i| MONTHS.get(i.wrapping_sub(1))).unwrap_or(&"?");
|
||||
format!("{name} {}, {y}", day.trim_start_matches('0'))
|
||||
}
|
||||
Lang::De => format!("{day}.{m}.{y}"),
|
||||
Lang::Nl => format!("{day}-{m}-{y}"),
|
||||
Lang::Fr | Lang::Es => format!("{day}/{m}/{y}"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn relative_time(date: &str) -> String {
|
||||
let Some(t) = parse_rfc3339(date) else { return String::new() };
|
||||
let diff = now_unix() as i64 - t;
|
||||
@@ -388,7 +408,7 @@ pub fn relative_time(date: &str) -> String {
|
||||
3600..=86399 => tf!("il y a {} h", diff / 3600),
|
||||
86400..=172799 => t!("hier").into(),
|
||||
_ if diff < 30 * 86400 => tf!("il y a {} j", diff / 86400),
|
||||
_ => date.get(..10).map(|d| format!("{}/{}/{}", &d[8..10], &d[5..7], &d[..4])).unwrap_or_default(),
|
||||
_ => date.get(..10).map(short_date).unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,6 +416,14 @@ pub fn relative_time(date: &str) -> String {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn short_dates() {
|
||||
use crate::i18n::Lang;
|
||||
assert_eq!(short_date_in("2026-03-02", Lang::En), "Mar 2, 2026");
|
||||
assert_eq!(short_date_in("2026-03-12", Lang::Fr), "12/03/2026");
|
||||
assert_eq!(short_date_in("2026-03-12", Lang::De), "12.03.2026");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rfc3339() {
|
||||
assert_eq!(parse_rfc3339("1970-01-01T00:00:00Z"), Some(0));
|
||||
@@ -432,8 +460,14 @@ pub fn daemon_running() -> bool {
|
||||
|
||||
/// Événement nommé que le service surveille pour s'arrêter proprement.
|
||||
pub fn quit_event() -> Option<HANDLE> {
|
||||
use windows::Win32::System::Threading::CreateEventW;
|
||||
unsafe { CreateEventW(None, true, false, &HSTRING::from(QUIT_EVENT)).ok() }
|
||||
use windows::Win32::System::Threading::{CreateEventW, ResetEvent};
|
||||
unsafe {
|
||||
let h = CreateEventW(None, true, false, &HSTRING::from(QUIT_EVENT)).ok()?;
|
||||
// L'évènement peut rester signalé si un autre processus garde un handle ouvert
|
||||
// après un arrêt : le nouveau service (seule instance) le réarme.
|
||||
let _ = ResetEvent(h);
|
||||
Some(h)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn quit_requested(ev: HANDLE) -> bool {
|
||||
|
||||
Reference in new issue
Block a user