From c9d852e2e36af22a0c3ed3d42a39efd9366618dd Mon Sep 17 00:00:00 2001 From: Raphael Nestler Date: Mon, 5 Dec 2022 23:33:59 +0100 Subject: [PATCH 1/5] Make notification timeout configurable Fixes #105. --- src/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index d09a353..326f77e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,6 +23,13 @@ struct Args { #[clap(long)] disable_notification: bool, + /// Timeout for the desktop notification in milliseconds. + /// + /// -1 will leave the timeout to be set by the server and + /// 0 will cause the notification never to expire. + #[clap(long, default_value = "-1")] + notification_timeout: i32, + /// Comma separated list of packages were we should reboot after an upgrade. #[clap( long, @@ -77,7 +84,7 @@ fn main() { Notification::new() .summary(result.summary()) .body(result.body()) - .timeout(6000) //milliseconds + .timeout(args.notification_timeout) .show() .map_err(|e| error!("Couldn't send notification: {}", e)) .ok(); From 51affd6b034cf16cdef3e0fec98c680dfb3b903b Mon Sep 17 00:00:00 2001 From: Raphael Nestler Date: Mon, 5 Dec 2022 23:36:35 +0100 Subject: [PATCH 2/5] Mention notification timeout in CHANGELOG --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5d6326..ee2c49a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + + * Make destkop notification timeout configurable + ([#106](https://github.com/rnestler/reboot-arch-btw/pull/106)) + ## [v0.5.2] - 2022-12-04 * Update dependencies From 04b54550b8b9647dc803384ae30b5bc5c8d0105d Mon Sep 17 00:00:00 2001 From: Raphael Nestler Date: Mon, 5 Dec 2022 23:38:54 +0100 Subject: [PATCH 3/5] Update --help output in README --- README.md | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7324616..cc668ca 100644 --- a/README.md +++ b/README.md @@ -65,12 +65,27 @@ Usage: reboot-arch-btw [OPTIONS] Options: --disable-notification Disable desktop notification + + --notification-timeout + Timeout for the desktop notification in milliseconds. + + -1 will leave the timeout to be set by the server and 0 will cause the notification never to expire. + + [default: -1] + --reboot-packages - Comma separated list of packages were we should reboot after an upgrade [default: systemd,linux-firmware,amd-ucode,intel-ucode] + Comma separated list of packages were we should reboot after an upgrade + + [default: systemd,linux-firmware,amd-ucode,intel-ucode] + --session-restart-packages - Comma separated list of packages were we should restart our session after an upgrade [default: xorg-server,xorg-xwayland] + Comma separated list of packages were we should restart our session after an upgrade + + [default: xorg-server,xorg-xwayland] + -h, --help - Print help information + Print help information (use `-h` for a summary) + -V, --version Print version information ``` From ddca531cca24fb9d74947c45fdb39ed2818f5234 Mon Sep 17 00:00:00 2001 From: Raphael Nestler Date: Sat, 10 Dec 2022 14:32:27 +0100 Subject: [PATCH 4/5] Use the keywords default and never instead of the magic integer values This maps directly to the types provided by `notify_rust` and makes it possible to explicitly pass "default" on the command line if so desired (-1 isn't possible to pass without workarounds in the code.) --- src/main.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 326f77e..bc5af6b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,8 @@ +use std::{num::ParseIntError, str::FromStr}; + use clap::Parser; use log::error; -use notify_rust::Notification; +use notify_rust::{Notification, Timeout}; mod package; @@ -13,6 +15,14 @@ mod critical_packages_check; use critical_packages_check::CriticalPackagesCheck; mod session; +fn timeout_from_str(s: &str) -> Result { + match s { + "default" => Ok(Timeout::Default), + "never" => Ok(Timeout::Never), + milliseconds => Ok(Timeout::Milliseconds(u32::from_str(milliseconds)?)), + } +} + #[derive(Debug, Parser)] #[clap( version, @@ -25,10 +35,13 @@ struct Args { /// Timeout for the desktop notification in milliseconds. /// - /// -1 will leave the timeout to be set by the server and - /// 0 will cause the notification never to expire. - #[clap(long, default_value = "-1")] - notification_timeout: i32, + /// * "default" will leave the timeout to be set by the server. + /// + /// * "never" or "0" will cause the notification never to expire. + /// + /// * Any other number will be interpreted as the timeout in milliseconds. + #[clap(long, value_parser(timeout_from_str), default_value = "default")] + notification_timeout: Timeout, /// Comma separated list of packages were we should reboot after an upgrade. #[clap( From 0b60cc8cb19b4df817ed8ae1b17bb9f8a281b5b2 Mon Sep 17 00:00:00 2001 From: Raphael Nestler Date: Sat, 10 Dec 2022 14:36:08 +0100 Subject: [PATCH 5/5] Update --help output --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cc668ca..303d990 100644 --- a/README.md +++ b/README.md @@ -69,9 +69,13 @@ Options: --notification-timeout Timeout for the desktop notification in milliseconds. - -1 will leave the timeout to be set by the server and 0 will cause the notification never to expire. + * "default" will leave the timeout to be set by the server. - [default: -1] + * "never" or "0" will cause the notification never to expire. + + * Any other number will be interpreted as the timeout in milliseconds. + + [default: default] --reboot-packages Comma separated list of packages were we should reboot after an upgrade