Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make notification timeout configurable #106

Merged
merged 5 commits into from Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
25 changes: 22 additions & 3 deletions README.md
Expand Up @@ -65,12 +65,31 @@ Usage: reboot-arch-btw [OPTIONS]
Options:
--disable-notification
Disable desktop notification

--notification-timeout <NOTIFICATION_TIMEOUT>
Timeout for the desktop notification in milliseconds.

* "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.

[default: default]

--reboot-packages <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 <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
```
Expand Down
24 changes: 22 additions & 2 deletions 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;

Expand All @@ -13,6 +15,14 @@ mod critical_packages_check;
use critical_packages_check::CriticalPackagesCheck;
mod session;

fn timeout_from_str(s: &str) -> Result<Timeout, ParseIntError> {
match s {
"default" => Ok(Timeout::Default),
"never" => Ok(Timeout::Never),
milliseconds => Ok(Timeout::Milliseconds(u32::from_str(milliseconds)?)),
}
}

#[derive(Debug, Parser)]
#[clap(
version,
Expand All @@ -23,6 +33,16 @@ struct Args {
#[clap(long)]
disable_notification: bool,

/// Timeout for the desktop notification in milliseconds.
///
/// * "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(
long,
Expand Down Expand Up @@ -77,7 +97,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();
Expand Down