mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 14:29:45 +00:00
create notification, intended for use at cli for testing notifications
This commit is contained in:
committed by
Aiden McClelland
parent
780d11926a
commit
4caee9a3e8
@@ -15,7 +15,7 @@ use crate::s9pk::manifest::PackageId;
|
|||||||
use crate::util::{display_none, display_serializable};
|
use crate::util::{display_none, display_serializable};
|
||||||
use crate::{Error, ErrorKind};
|
use crate::{Error, ErrorKind};
|
||||||
|
|
||||||
#[command(subcommands(list, delete, delete_before))]
|
#[command(subcommands(list, delete, delete_before, create))]
|
||||||
pub async fn notification() -> Result<(), Error> {
|
pub async fn notification() -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -133,6 +133,19 @@ pub async fn delete_before(#[context] ctx: RpcContext, #[arg] before: u32) -> Re
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[command(display(display_none))]
|
||||||
|
pub async fn create(
|
||||||
|
#[context] ctx: RpcContext,
|
||||||
|
#[arg] package: Option<PackageId>,
|
||||||
|
#[arg] level: NotificationLevel,
|
||||||
|
#[arg] title: String,
|
||||||
|
#[arg] message: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
ctx.notification_manager
|
||||||
|
.notify(package, level, title, message, NotificationSubtype::General)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
#[derive(Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum NotificationLevel {
|
pub enum NotificationLevel {
|
||||||
Success,
|
Success,
|
||||||
@@ -150,11 +163,11 @@ impl fmt::Display for NotificationLevel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub struct InvalidNotificationLevel;
|
pub struct InvalidNotificationLevel(String);
|
||||||
impl From<InvalidNotificationLevel> for crate::Error {
|
impl From<InvalidNotificationLevel> for crate::Error {
|
||||||
fn from(_val: InvalidNotificationLevel) -> Self {
|
fn from(val: InvalidNotificationLevel) -> Self {
|
||||||
Error::new(
|
Error::new(
|
||||||
anyhow!("Invalid Notification Level"),
|
anyhow!("Invalid Notification Level: {}", val.0),
|
||||||
ErrorKind::ParseDbField,
|
ErrorKind::ParseDbField,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -167,10 +180,15 @@ impl FromStr for NotificationLevel {
|
|||||||
s if s == "info" => Ok(NotificationLevel::Info),
|
s if s == "info" => Ok(NotificationLevel::Info),
|
||||||
s if s == "warning" => Ok(NotificationLevel::Warning),
|
s if s == "warning" => Ok(NotificationLevel::Warning),
|
||||||
s if s == "error" => Ok(NotificationLevel::Error),
|
s if s == "error" => Ok(NotificationLevel::Error),
|
||||||
_ => Err(InvalidNotificationLevel),
|
s => Err(InvalidNotificationLevel(s.to_string())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl fmt::Display for InvalidNotificationLevel {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "Invalid Notification Level: {}", self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
#[derive(serde::Serialize, serde::Deserialize)]
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
pub struct Notification {
|
pub struct Notification {
|
||||||
id: u32,
|
id: u32,
|
||||||
|
|||||||
Reference in New Issue
Block a user