This commit is contained in:
Lucas Nogueira
2024-02-21 13:29:09 -03:00
parent 4709c343bc
commit 569defbe94
51 changed files with 278 additions and 612 deletions
+1 -1
View File
@@ -24,6 +24,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -23,6 +23,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -24,6 +24,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -27,6 +27,6 @@
"tslib": "2.6.0"
},
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -23,6 +23,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -23,6 +23,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+2 -2
View File
@@ -10,11 +10,11 @@
"tauri": "tauri"
},
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1",
"@tauri-apps/api": "2.0.0-beta.2",
"@tauri-apps/plugin-deep-link": "2.0.0-beta.0"
},
"devDependencies": {
"@tauri-apps/cli": "2.0.0-beta.2",
"@tauri-apps/cli": "2.0.0-beta.3",
"internal-ip": "^8.0.0",
"typescript": "^5.2.2",
"vite": "^5.0.12"
+1 -1
View File
@@ -24,6 +24,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -23,6 +23,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -24,6 +24,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -23,6 +23,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -23,6 +23,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -24,6 +24,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -27,6 +27,6 @@
"tslib": "2.6.0"
},
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+5
View File
@@ -46,6 +46,11 @@ chrono = { version = "0.4", optional = true}
[target.'cfg(target_os="windows")'.dependencies]
winrt-notification = { package = "tauri-winrt-notification", version = "0.1" }
[dev-dependencies]
color-backtrace = "0.5"
ctor = "0.2"
maplit = "1.0"
[features]
default = [ "zbus", "async" ]
async = []
+1 -1
View File
@@ -23,6 +23,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1
View File
@@ -32,6 +32,7 @@ mod commands;
mod error;
mod models;
#[allow(dead_code, unused_imports, deprecated)]
mod notify_rust;
pub use error::{Error, Result};
@@ -1,13 +1,13 @@
#![allow(missing_docs)]
#[cfg(all(feature = "images", unix, not(target_os = "macos")))]
use crate::image::ImageError;
use super::image::ImageError;
use std::{fmt, num};
/// Convenient wrapper around `std::Result`.
pub type Result<T> = ::std::result::Result<T, Error>;
#[cfg(target_os = "macos")]
pub use crate::macos::{ApplicationError, MacOsError, NotificationError};
pub use super::macos::{ApplicationError, MacOsError, NotificationError};
/// The Error type.
#[derive(Debug)]
@@ -154,7 +154,7 @@ fn test_hints_to_map() {
// custom value should only be there once if the names are identical
let n1 = crate::Notification::new()
let n1 = super::Notification::new()
.hint(Hint::Custom("foo".into(), "bar1".into()))
.hint(Hint::Custom("foo".into(), "bar2".into()))
.hint(Hint::Custom("f00".into(), "bar3".into()))
@@ -8,7 +8,7 @@ use std::error::Error;
use std::fmt;
use std::path::Path;
use crate::miniver::Version;
use super::miniver::Version;
mod constants {
pub const IMAGE_DATA: &str = "image-data";
@@ -12,69 +12,6 @@
//! in these cases you will have to add platform specific toggles to your code.
//! For more see [platform differences](#platform-differences)
//!
//! # Examples
//!
//! ## Example 1: Simple Notification
//!
//! ```no_run
//! # use notify_rust::*;
//! Notification::new()
//! .summary("Firefox News")
//! .body("This will almost look like a real firefox notification.")
//! .icon("firefox")
//! .timeout(Timeout::Milliseconds(6000)) //milliseconds
//! .show().unwrap();
//! ```
//!
//! ## Example 2: Persistent Notification
//!
//! ```no_run
//! # use notify_rust::*;
//! Notification::new()
//! .summary("Category:email")
//! .body("This has nothing to do with emails.\nIt should not go away until you acknowledge it.")
//! .icon("thunderbird")
//! .appname("thunderbird")
//! .hint(Hint::Category("email".to_owned()))
//! .hint(Hint::Resident(true)) // this is not supported by all implementations
//! .timeout(Timeout::Never) // this however is
//! .show().unwrap();
//! ```
//!
//! Careful! There are no checks whether you use hints twice.
//! It is possible to set `urgency=Low` AND `urgency=Critical`, in which case the behavior of the server is undefined.
//!
//! ## Example 3: Ask the user to do something
//!
//! ```no_run
//! # use notify_rust::*;
//! # #[cfg(all(unix, not(target_os = "macos")))]
//! Notification::new().summary("click me")
//! .action("default", "default")
//! .action("clicked", "click here")
//! .hint(Hint::Resident(true))
//! .show()
//! .unwrap()
//! .wait_for_action(|action| match action {
//! "default" => println!("you clicked \"default\""),
//! "clicked" => println!("that was correct"),
//! // here "__closed" is a hard coded keyword
//! "__closed" => println!("the notification was closed"),
//! _ => ()
//! });
//! ```
//!
//! ## Minimal Example
//!
//! You can omit almost everything
//!
//! ```no_run
//! # use notify_rust::Notification;
//! Notification::new().show();
//! ```
//!
//! more [examples](https://github.com/hoodie/notify-rust/tree/main/examples) in the repository.
//!
//! # Platform Differences
//! <details>
//! ✔︎ = works <br/>
@@ -32,17 +32,6 @@ fn exe_name() -> String {
/// Desktop notification.
///
/// A desktop notification is configured via builder pattern, before it is launched with `show()`.
///
/// # Example
/// ``` no_run
/// # use notify_rust::*;
/// # fn _doc() -> Result<(), Box<dyn std::error::Error>> {
/// Notification::new()
/// .summary("☝️ A notification")
/// .show()?;
/// # Ok(())
/// # }
/// ```
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct Notification {
@@ -247,18 +236,6 @@ impl Notification {
/// * [`image_data(...)`](#method.image_data)
/// * [`image_path(...)`](#method.image_path)
///
/// ```no_run
/// # use notify_rust::Notification;
/// # use notify_rust::Hint;
/// Notification::new().summary("Category:email")
/// .body("This should not go away until you acknowledge it.")
/// .icon("thunderbird")
/// .appname("thunderbird")
/// .hint(Hint::Category("email".to_owned()))
/// .hint(Hint::Resident(true))
/// .show();
/// ```
///
/// # Platform support
/// Most of these hints don't even have an effect on the big XDG Desktops, they are completely tossed on macOS.
#[cfg(all(unix, not(target_os = "macos")))]
@@ -300,23 +277,6 @@ impl Notification {
///
/// When passing a [`Duration`](`std::time::Duration`) we will try convert it into milliseconds.
///
///
/// ```
/// # use std::time::Duration;
/// # use notify_rust::Timeout;
/// assert_eq!(Timeout::from(Duration::from_millis(2000)), Timeout::Milliseconds(2000));
/// ```
/// ### Caveats!
///
/// 1. If the duration is zero milliseconds then the original behavior will apply and the notification will **Never** timeout.
/// 2. Should the number of milliseconds not fit within an [`i32`] then we will fall back to the default timeout.
/// ```
/// # use std::time::Duration;
/// # use notify_rust::Timeout;
/// assert_eq!(Timeout::from(Duration::from_millis(0)), Timeout::Never);
/// assert_eq!(Timeout::from(Duration::from_millis(u64::MAX)), Timeout::Default);
/// ```
///
/// # Platform support
/// This only works on XDG Desktops, macOS does not support manually setting the timeout.
pub fn timeout<T: Into<Timeout>>(&mut self, timeout: T) -> &mut Notification {
@@ -21,7 +21,7 @@ use dbus::{
};
use super::{Hint, Notification, Timeout};
use crate::xdg::{NOTIFICATION_NAMESPACE, NOTIFICATION_OBJECTPATH};
use super::xdg::{NOTIFICATION_NAMESPACE, NOTIFICATION_OBJECTPATH};
static DBUS_ERROR_FAILED: &str = "org.freedesktop.DBus.Error.Failed";
/// Version of the crate equals the version server.
@@ -4,12 +4,6 @@ use std::{convert::TryInto, num::ParseIntError, str::FromStr, time::Duration};
///
/// # `FromStr`
/// You can also parse a `Timeout` from a `&str`.
/// ```
/// # use notify_rust::Timeout;
/// assert_eq!("default".parse(), Ok(Timeout::Default));
/// assert_eq!("never".parse(), Ok(Timeout::Never));
/// assert_eq!("42".parse(), Ok(Timeout::Milliseconds(42)));
/// ```
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Timeout {
/// Expires according to server default.
@@ -11,20 +11,6 @@ use std::convert::TryFrom;
/// > **Critical notifications should not automatically expire**, as they are things that the user will most likely want to know about. They should only be closed when the user dismisses them, for example, by clicking on the notification.
///
/// <cite> — see [Galago](http://www.galago-project.org/specs/notification/0.9/x320.html) or [Gnome](https://developer.gnome.org/notification-spec/#urgency-levels) specification.</cite>
///
/// # Example
/// ```no_run
/// # use notify_rust::*;
/// # fn _doc() -> Result<(), Box<dyn std::error::Error>> {
/// Notification::new()
/// .summary("oh no")
/// .icon("dialog-warning")
/// .urgency(Urgency::Critical)
/// .show()?;
/// # Ok(())
/// # }
/// ```
///
#[derive(Eq, PartialEq, Hash, Copy, Clone, Debug)]
pub enum Urgency {
/// The behavior for `Low` urgency depends on the notification server.
@@ -1,6 +1,6 @@
use winrt_notification::Toast;
pub use crate::{error::*, notification::Notification, timeout::Timeout};
pub use super::{error::*, notification::Notification, timeout::Timeout};
use std::{path::Path, str::FromStr};
@@ -1,4 +1,4 @@
use crate::xdg::NOTIFICATION_DEFAULT_BUS;
use super::super::xdg::NOTIFICATION_DEFAULT_BUS;
fn skip_first_slash(s: &str) -> &str {
if let Some('/') = s.chars().next() {
@@ -9,7 +9,7 @@ use super::{
NOTIFICATION_INTERFACE,
};
use crate::{
use super::super::{
error::*,
hints::message::HintMessage,
notification::Notification,
@@ -18,7 +18,7 @@ use crate::{
pub mod bus {
use crate::xdg::NOTIFICATION_DEFAULT_BUS;
use super::super::super::xdg::NOTIFICATION_DEFAULT_BUS;
fn skip_first_slash(s: &str) -> &str {
if let Some('/') = s.chars().next() {
@@ -119,22 +119,6 @@ impl NotificationHandle {
}
/// Manually close the notification
///
/// # Example
///
/// ```no_run
/// # use notify_rust::*;
/// let handle: NotificationHandle = Notification::new()
/// .summary("oh no")
/// .hint(notify_rust::Hint::Transient(true))
/// .body("I'll be here till you close me!")
/// .hint(Hint::Resident(true)) // does not work on kde
/// .timeout(Timeout::Never) // works on kde and gnome
/// .show()
/// .unwrap();
/// // ... and then later
/// handle.close();
/// ```
pub fn close(self) {
match self.inner {
#[cfg(feature = "dbus")]
@@ -145,30 +129,6 @@ impl NotificationHandle {
}
/// Executes a closure after the notification has closed.
///
/// ## Example 1: *I don't care about why it closed* (the good ole API)
///
/// ```no_run
/// # use notify_rust::Notification;
/// Notification::new().summary("Time is running out")
/// .body("This will go away.")
/// .icon("clock")
/// .show()
/// .unwrap()
/// .on_close(|| println!("closed"));
/// ```
///
/// ## Example 2: *I **do** care about why it closed* (added in v4.5.0)
///
/// ```no_run
/// # use notify_rust::Notification;
/// Notification::new().summary("Time is running out")
/// .body("This will go away.")
/// .icon("clock")
/// .show()
/// .unwrap()
/// .on_close(|reason| println!("closed: {:?}", reason));
/// ```
pub fn on_close<A>(self, handler: impl CloseHandler<A>) {
match self.inner {
#[cfg(feature = "dbus")]
@@ -190,26 +150,6 @@ impl NotificationHandle {
};
}
/// Replace the original notification with an updated version
/// ## Example
/// ```no_run
/// # use notify_rust::Notification;
/// let mut notification = Notification::new().summary("Latest News")
/// .body("Bayern Dortmund 3:2")
/// .show()
/// .unwrap();
///
/// std::thread::sleep_ms(1_500);
///
/// notification.summary("Latest News (Correction)")
/// .body("Bayern Dortmund 3:3");
///
/// notification.update();
/// ```
/// Watch out for different implementations of the
/// notification server! On plasma5 for instance, you should also change the appname, so the old
/// message is really replaced and not just amended. Xfce behaves well, all others have not
/// been tested by the developer.
pub fn update(&mut self) {
match self.inner {
#[cfg(feature = "dbus")]
+1 -1
View File
@@ -23,6 +23,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -24,6 +24,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -23,6 +23,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -23,6 +23,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -32,4 +32,4 @@ features = [
]
[target."cfg(target_os = \"linux\")".dependencies]
zbus = "3"
zbus = "4"
@@ -9,6 +9,6 @@
"author": "",
"license": "MIT",
"devDependencies": {
"@tauri-apps/cli": "2.0.0-beta.2"
"@tauri-apps/cli": "2.0.0-beta.3"
}
}
@@ -10,8 +10,8 @@ use tauri::{
AppHandle, Config, Manager, RunEvent, Runtime,
};
use zbus::{
blocking::{Connection, ConnectionBuilder},
dbus_interface,
blocking::{Builder, Connection},
interface,
};
struct ConnectionHandle(Connection);
@@ -21,7 +21,7 @@ struct SingleInstanceDBus<R: Runtime> {
app_handle: AppHandle<R>,
}
#[dbus_interface(name = "org.SingleInstance.DBus")]
#[interface(name = "org.SingleInstance.DBus")]
impl<R: Runtime> SingleInstanceDBus<R> {
fn execute_callback(&mut self, argv: Vec<String>, cwd: String) {
(self.callback)(&self.app_handle, argv, cwd);
@@ -43,7 +43,7 @@ pub fn init<R: Runtime>(f: Box<SingleInstanceCallback<R>>) -> TauriPlugin<R> {
let dbus_name = format!("org.{id}.SingleInstance");
let dbus_path = format!("/org/{id}/SingleInstance");
match ConnectionBuilder::session()
match Builder::session()
.unwrap()
.name(dbus_name.as_str())
.unwrap()
+1 -1
View File
@@ -24,6 +24,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -24,6 +24,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -24,6 +24,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -23,6 +23,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -24,6 +24,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
@@ -9,7 +9,7 @@
"preview": "vite preview"
},
"devDependencies": {
"@tauri-apps/cli": "2.0.0-beta.2",
"@tauri-apps/cli": "2.0.0-beta.3",
"typescript": "^5.3.3",
"vite": "^5.0.12"
},
+1 -1
View File
@@ -23,6 +23,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}
+1 -1
View File
@@ -24,6 +24,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "2.0.0-beta.1"
"@tauri-apps/api": "2.0.0-beta.2"
}
}