Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hhstore committed Mar 27, 2024
1 parent acdf24e commit 40ffa84
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
14 changes: 14 additions & 0 deletions crates/rs-os/rs-cross/try-notify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,17 @@ edition = "2021"

[dependencies]
notify-rust = "4"
chrono = { version = "0.4", optional = true }


#
# cli usage:
# - cargo run --bin rs-eth-scanner -- scan "http://abc.url" "0xxxxx" "deposit" "100"
#
[[bin]]
name = "run2"
path = "src/run2.rs"

[[bin]]
name = "run3"
path = "src/run3.rs"
2 changes: 1 addition & 1 deletion crates/rs-os/rs-cross/try-notify/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tasks:
run:
aliases: [ "r" ]
cmds:
- cargo run
- cargo run {{.CLI_ARGS}}

build:
aliases: [ "b" ]
Expand Down
18 changes: 18 additions & 0 deletions crates/rs-os/rs-cross/try-notify/src/run2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#[cfg(any(target_os = "windows", target_os = "macos"))]
fn main() {
println!("this is a xdg only feature")
}

#[cfg(all(unix, not(target_os = "macos")))]
fn main() -> Result<(), Box<dyn std::error::Error>> {
use notify_rust::{Hint, Timeout};

notify_rust::Notification::new()
.summary("Persistent notification")
.body("This should not go away unless you want it to.")
.icon("firefox")
.hint(Hint::Resident(true)) // does not work on kde
.timeout(Timeout::Never) // works on kde and gnome
.show()?;
Ok(())
}
35 changes: 35 additions & 0 deletions crates/rs-os/rs-cross/try-notify/src/run3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#[cfg(target_os = "macos")]
fn main() -> Result<(), String> {
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))?;

match set_application(&safari_id) {
Ok(_) => {},
Err(MacOsError::Application(error)) => println!("{}", error),
Err(MacOsError::Notification(error)) => println!("{}", error),
}

Notification::new()
.summary("Safari Crashed")
.body("Just kidding, this is just the notify_rust example.")
.appname("Safari")
.icon("Safari")
.show()
.map_err(|f| format!("{}", f))?;

Ok(())
}

#[cfg(all(unix, not(target_os = "macos")))]
fn main() {
println!("this is a mac only feature")
}

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

0 comments on commit 40ffa84

Please sign in to comment.