Skip to content

Commit

Permalink
Merge pull request #162 from hoodie/feature/format
Browse files Browse the repository at this point in the history
give in to the format pressure
  • Loading branch information
hoodie committed Dec 3, 2022
2 parents 6020bab + 6096c0a commit 0c2a33c
Show file tree
Hide file tree
Showing 26 changed files with 420 additions and 290 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [ pull_request ]

jobs:
check:
name: Check
name: Check Commit Message
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -18,3 +18,14 @@ jobs:
chmod +x convco
./convco check ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}
rm convco
fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt
20 changes: 9 additions & 11 deletions examples/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@ fn main() {
#[cfg(all(unix, not(target_os = "macos")))]
Notification::new()
.summary("click me")
.action("default", "default") // IDENTIFIER, LABEL
.action("default", "default") // IDENTIFIER, LABEL
.action("clicked_a", "button a") // IDENTIFIER, LABEL
.action("clicked_b", "button b") // IDENTIFIER, LABEL
.hint(Hint::Resident(true))
.show()
.unwrap()
.wait_for_action(|action|
match action {
"default" => println!("default"),
"clicked_a" => println!("clicked a"),
"clicked_b" => println!("clicked b"),
// FIXME: here "__closed" is a hardcoded keyword, it will be deprecated!!
"__closed" => println!("the notification was closed"),
_ => ()
}
);
.wait_for_action(|action| match action {
"default" => println!("default"),
"clicked_a" => println!("clicked a"),
"clicked_b" => println!("clicked b"),
// FIXME: here "__closed" is a hardcoded keyword, it will be deprecated!!
"__closed" => println!("the notification was closed"),
_ => (),
});

#[cfg(target_os = "macos")]
Notification::new()
Expand Down
4 changes: 3 additions & 1 deletion examples/countdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use notify_rust::Notification;
use std::time::Duration;

#[cfg(any(target_os = "windows", target_os = "macos"))]
fn main() { println!("this is a xdg only feature") }
fn main() {
println!("this is a xdg only feature")
}

#[cfg(all(unix, not(target_os = "macos")))]
fn main() {
Expand Down
18 changes: 14 additions & 4 deletions examples/hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Notification::new().hint(Hint::ActionIcons(true)).show()?;

freeze("urgency: low, medium, high");
Notification::new().summary("low").hint(Hint::Urgency(Low)).show()?;
Notification::new()
.summary("low")
.hint(Hint::Urgency(Low))
.show()?;
Notification::new()
.summary("normal")
.hint(Hint::Urgency(Normal))
Expand Down Expand Up @@ -68,7 +71,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
freeze("SoundFile");
Notification::new()
.summary("soundfile")
.hint(Hint::SoundFile("/usr/share/sounds/alsa/Front_Left.wav".to_owned()))
.hint(Hint::SoundFile(
"/usr/share/sounds/alsa/Front_Left.wav".to_owned(),
))
.hint(Hint::SoundName("system sound".to_owned()))
.hint(Hint::SuppressSound(false))
.show()?;
Expand All @@ -80,7 +85,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.show()?;

freeze("X and Y");
Notification::new().hint(Hint::X(200)).hint(Hint::Y(200)).show()?;
Notification::new()
.hint(Hint::X(200))
.hint(Hint::Y(200))
.show()?;

#[cfg(all(feature = "images", unix, not(target_os = "macos")))]
{
Expand All @@ -90,7 +98,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
image_data[i] = (i % 256) as u8;
}
Notification::new()
.hint(Hint::ImageData(Image::from_rgb(128, 128, image_data).unwrap()))
.hint(Hint::ImageData(
Image::from_rgb(128, 128, image_data).unwrap(),
))
.summary("You should see stripes in this notification");
}

Expand Down
19 changes: 14 additions & 5 deletions examples/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,25 @@ use notify_rust::Image;
use notify_rust::Notification;

#[cfg(target_os = "windows")]
fn main() { println!("this is a xdg only feature") }
fn main() {
println!("this is a xdg only feature")
}

#[cfg(all(not(feature = "images"), unix, not(target_os = "macos")))]
fn main() { println!("please build with '--features=images'") }
fn main() {
println!("please build with '--features=images'")
}

#[cfg(all(feature = "images", unix, not(target_os = "macos"), not(target_os = "windows")))]
#[cfg(all(
feature = "images",
unix,
not(target_os = "macos"),
not(target_os = "windows")
))]
fn main() -> Result<(), Box<dyn std::error::Error>> {
fn image_data() -> Vec<u8> {
let mut image_data = vec![0;128*128*3];
for i in 0..128*128*3 {
let mut image_data = vec![0; 128 * 128 * 3];
for i in 0..128 * 128 * 3 {
image_data[i] = (i % 256) as u8;
}
image_data
Expand Down
4 changes: 3 additions & 1 deletion examples/mac_app_id.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[cfg(target_os = "macos")]
fn main() -> Result<(), String> {
use notify_rust::{error::MacOsError, get_bundle_identifier_or_default, set_application, Notification};
use notify_rust::{
error::MacOsError, get_bundle_identifier_or_default, set_application, Notification,
};

let safari_id = get_bundle_identifier_or_default("Safari");
set_application(&safari_id).map_err(|f| format!("{}", f))?;
Expand Down
4 changes: 3 additions & 1 deletion examples/on_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ fn print() {
}

#[cfg(any(target_os = "macos", target_os = "windows"))]
fn main() { println!("this is a xdg only feature") }
fn main() {
println!("this is a xdg only feature")
}

#[cfg(all(unix, not(target_os = "macos")))]
fn main() {
Expand Down
6 changes: 4 additions & 2 deletions examples/on_close_reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::{io, thread};

#[cfg(all(unix, not(target_os = "macos")))]
use notify_rust::{Notification, CloseReason};
use notify_rust::{CloseReason, Notification};

fn wait_for_keypress() {
println!("halted until you hit the \"ANY\" key");
Expand All @@ -15,7 +15,9 @@ fn print_reason(reason: CloseReason) {
}

#[cfg(any(target_os = "macos", target_os = "windows"))]
fn main() { println!("this is a xdg only feature") }
fn main() {
println!("this is a xdg only feature")
}

#[cfg(all(unix, not(target_os = "macos")))]
fn main() {
Expand Down
1 change: 0 additions & 1 deletion examples/persistent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ fn main() {
println!("this is a xdg only feature")
}


#[cfg(all(unix, not(target_os = "macos")))]
fn main() -> Result<(), Box<dyn std::error::Error>> {
Notification::new()
Expand Down
4 changes: 3 additions & 1 deletion examples/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ fn main() {

#[cfg(all(unix, not(target_os = "macos")))]
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut notification = notify_rust::Notification::new().summary("progress").show()?;
let mut notification = notify_rust::Notification::new()
.summary("progress")
.show()?;
for i in 0..=10 {
let value = i * 10;
notification
Expand Down
2 changes: 1 addition & 1 deletion examples/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
use notify_rust::Notification;

let duration = chrono::Duration::milliseconds(4321);
let timestamp = (chrono::Utc::now() + duration).timestamp() as f64;
let timestamp = (chrono::Utc::now() + duration).timestamp() as f64;

Notification::new()
.summary("Oh by the way")
Expand Down
13 changes: 8 additions & 5 deletions examples/server.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#[cfg(all(feature = "server", unix, not(target_os = "macos")))]
use notify_rust::server::NotificationServer;

#[cfg(target_os = "macos")] fn main() { println!("this is a xdg only feature") }
#[cfg(target_os = "macos")]
fn main() {
println!("this is a xdg only feature")
}

#[cfg(target_os = "windows")]
fn main() { println!("this is a xdg only feature") }
fn main() {
println!("this is a xdg only feature")
}

#[cfg(all(unix, not(feature = "server"), not(target_os = "macos")))]
fn main() {
Expand All @@ -19,9 +24,7 @@ fn main() {

let server = NotificationServer::create();
thread::spawn(move || {
NotificationServer::start(&server, |notification| {
println!("{:#?}", notification)
})
NotificationServer::start(&server, |notification| println!("{:#?}", notification))
});

thread::sleep(Duration::from_millis(500));
Expand Down
5 changes: 3 additions & 2 deletions examples/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
use notify_rust::Notification;
use std::time::Duration;


#[cfg(target_os = "windows")]
fn main() { println!("This is not a windows feature") }
fn main() {
println!("This is not a windows feature")
}

#[cfg(all(unix, not(target_os = "macos")))]
fn update_via_handle() {
Expand Down
2 changes: 1 addition & 1 deletion examples/urgency.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::convert::TryInto;
use notify_rust::{Notification, Urgency::*};
use std::convert::TryInto;

#[cfg(target_os = "macos")]
fn main() {
Expand Down
18 changes: 0 additions & 18 deletions rustfmt.toml

This file was deleted.

7 changes: 5 additions & 2 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ impl fmt::Display for ImageError {
f,
"The given image is too big. DBus only has 32 bits for width / height"
),
WrongDataSize => writeln!(f, "The given bytes don't match the width, height and channel count"),
WrongDataSize => writeln!(
f,
"The given bytes don't match the width, height and channel count"
),
CantOpen(e) => writeln!(f, "Can't open given path {}", e),
CantConvert => writeln!(f, "Can't convert from given input"),
}
Expand All @@ -173,7 +176,7 @@ pub(crate) fn image_spec(version: Version) -> String {

/// matching image data key for each spec version
#[cfg(feature = "zbus")]
pub(crate) fn image_spec_str(version: Version) -> &'static str{
pub(crate) fn image_spec_str(version: Version) -> &'static str {
match version.cmp(&Version::new(1, 1)) {
Ordering::Less => constants::IMAGE_DATA_1_0,
Ordering::Equal => constants::IMAGE_DATA_1_1,
Expand Down

0 comments on commit 0c2a33c

Please sign in to comment.