Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
08ac40ae85 | |||
f25f2ce2ca | |||
2d42401b52 | |||
28c808f07f | |||
e71891343c | |||
58aed0897d | |||
21002f6521 | |||
1e51c83067 | |||
45bf3a87b9 |
@ -1,8 +1,14 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "snot"
|
name = "snot"
|
||||||
version = "0.1.1"
|
version = "0.1.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["candifloss <candifloss.cc>"]
|
authors = ["candifloss <candifloss.cc>"]
|
||||||
|
description = "Simple NOTification"
|
||||||
|
license = "GPL-3.0-or-later"
|
||||||
|
repository = "https://git.candifloss.cc/candifloss/SNot"
|
||||||
|
homepage = "https://git.candifloss.cc/candifloss/SNot"
|
||||||
|
documentation = "https://git.candifloss.cc/candifloss/SNot"
|
||||||
|
readme = "README.md"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
zbus = "4.4.0"
|
zbus = "4.4.0"
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
// This module deals with converting the notification object into rson format, which can be used instead of json if preferred
|
// This module deals with converting the notification object into rson format, which can be used instead of json if preferred
|
||||||
use crate::notification::Notification;
|
use crate::notification::Notification;
|
||||||
use rson_rs::ser::to_string as rson_string;
|
|
||||||
use rson_rs::de::Error as RsonError;
|
use rson_rs::de::Error as RsonError;
|
||||||
|
use rson_rs::ser::to_string as rson_string;
|
||||||
|
|
||||||
impl Notification {
|
impl Notification {
|
||||||
pub fn rson(&self) -> Result<String, RsonError> {
|
pub fn rson(&self) -> Result<String, RsonError> {
|
||||||
rson_string(self).map_err(|e| RsonError::Message(format!("RSON serialization error: {}", e)))
|
rson_string(self)
|
||||||
|
.map_err(|e| RsonError::Message(format!("RSON serialization error: {}", e)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
use serde::{Serialize, Serializer};
|
use serde::ser::{Serialize, Serializer, SerializeMap};
|
||||||
/*
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::hash::BuildHasher;
|
use zvariant::OwnedValue;
|
||||||
use zvariant::OwnedValue; */
|
//use std::hash::BuildHasher;
|
||||||
|
//use serde::ser::SerializeMap;
|
||||||
|
use serde_json::{Map,Value};
|
||||||
|
use zvariant::SerializeValue;
|
||||||
|
|
||||||
pub fn serialize_actions<S>(actions: &[String], serializer: S) -> Result<S::Ok, S::Error>
|
pub fn serialize_actions<S>(actions: &[String], serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
@ -10,9 +12,9 @@ where
|
|||||||
{
|
{
|
||||||
let mut map = serde_json::Map::new();
|
let mut map = serde_json::Map::new();
|
||||||
|
|
||||||
// Assuming actions are in pairs: [id, label, id, label, ...]
|
// Actions are in pairs: [id, label, id, label, ...]
|
||||||
for chunk in actions.chunks(2) {
|
for pair in actions.chunks(2) {
|
||||||
if let [id, label] = chunk {
|
if let [id, label] = pair {
|
||||||
map.insert(id.clone(), serde_json::Value::String(label.clone()));
|
map.insert(id.clone(), serde_json::Value::String(label.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -20,22 +22,38 @@ where
|
|||||||
map.serialize(serializer)
|
map.serialize(serializer)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
pub fn serialize_hints<S>(
|
||||||
pub fn serialize_hints<S, H>(
|
hints: &HashMap<String, OwnedValue>,
|
||||||
hints: &HashMap<String, OwnedValue, H>,
|
|
||||||
serializer: S,
|
serializer: S,
|
||||||
) -> Result<S::Ok, S::Error>
|
) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
H: BuildHasher,
|
|
||||||
{
|
{
|
||||||
let mut map = serde_json::Map::new();
|
// Start serializing the map
|
||||||
|
let mut map = serializer.serialize_map(Some(hints.len()))?;
|
||||||
for (key, value) in hints {
|
for (key, value) in hints {
|
||||||
// Customize OwnedValue serialization as needed
|
// Serialize each entry as desired
|
||||||
map.insert(key.clone(), serde_json::Value::String(value.to_string()));
|
map.serialize_entry(key, &HintValueSerializer(value))?;
|
||||||
}
|
}
|
||||||
|
map.end()
|
||||||
map.serialize(serializer)
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
// A custom struct to handle serialization of OwnedValue
|
||||||
|
struct HintValueSerializer<'a>(&'a OwnedValue);
|
||||||
|
|
||||||
|
impl<'a> Serialize for HintValueSerializer<'a> {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
// Access the signature and value parts of the OwnedValue
|
||||||
|
let signature = self.0.value_signature().to_string();
|
||||||
|
let value = &self.0;
|
||||||
|
|
||||||
|
// Serialize them as a map with "signature" and "value" fields
|
||||||
|
let mut map = serializer.serialize_map(Some(2))?;
|
||||||
|
map.serialize_entry("signature", &signature)?;
|
||||||
|
map.serialize_entry("value", value)?;
|
||||||
|
map.end()
|
||||||
|
}
|
||||||
|
}
|
@ -13,8 +13,8 @@ use futures_util::stream::TryStreamExt;
|
|||||||
use zbus::{message::Body, Connection, Result};
|
use zbus::{message::Body, Connection, Result};
|
||||||
|
|
||||||
const SERVER_NAME: &str = "SNot"; // Server software name
|
const SERVER_NAME: &str = "SNot"; // Server software name
|
||||||
const VENDOR: &str = "candifloss.cc"; // Server software vendor
|
const VENDOR: &str = env!("CARGO_PKG_AUTHORS"); // Server software vendor
|
||||||
const VERSION: &str = "0.1.2"; // Server software version
|
const VERSION: &str = env!("CARGO_PKG_VERSION"); // Server software version, from Cargo.toml
|
||||||
const SPEC_VERSION: &str = "0.42"; // DBus specification version
|
const SPEC_VERSION: &str = "0.42"; // DBus specification version
|
||||||
const NOTIF_INTERFACE: &str = "org.freedesktop.Notifications"; // DBus interface name
|
const NOTIF_INTERFACE: &str = "org.freedesktop.Notifications"; // DBus interface name
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ async fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
"GetCapabilities" => {
|
"GetCapabilities" => {
|
||||||
// Client requested server capabilities. Respond with the supported capabilities
|
// Client requested server capabilities. Respond with the supported capabilities
|
||||||
let capabilities = vec!["actions", "body", "body-hyperlinks"]; // Add more LATER
|
let capabilities = vec![/*"actions",*/ "body", "body-hyperlinks"]; // Add more LATER
|
||||||
connection.reply(&msg, &capabilities).await?;
|
connection.reply(&msg, &capabilities).await?;
|
||||||
if verbose {
|
if verbose {
|
||||||
println!("Request received: {member}\n\tCapabilities: {capabilities:?}");
|
println!("Request received: {member}\n\tCapabilities: {capabilities:?}");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::formats::serde::serialize_actions;
|
use crate::formats::serde::{serialize_actions, serialize_hints};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use zbus::{message::Body, Result};
|
use zbus::{message::Body, Result};
|
||||||
@ -21,7 +21,7 @@ pub struct Notification {
|
|||||||
#[serde(serialize_with = "serialize_actions")]
|
#[serde(serialize_with = "serialize_actions")]
|
||||||
actions: Vec<String>,
|
actions: Vec<String>,
|
||||||
// Useful extra data - notif type, urgency, notif sound, icon data, etc.
|
// Useful extra data - notif type, urgency, notif sound, icon data, etc.
|
||||||
//#[serde(serialize_with = "serialize_hints")]
|
#[serde(serialize_with = "serialize_hints")]
|
||||||
hints: HashMap<String, OwnedValue>,
|
hints: HashMap<String, OwnedValue>,
|
||||||
// Seconds till this notif expires. Optional
|
// Seconds till this notif expires. Optional
|
||||||
expir_timeout: i32,
|
expir_timeout: i32,
|
||||||
|
Loading…
Reference in New Issue
Block a user