Skip to content

Commit

Permalink
update capnp
Browse files Browse the repository at this point in the history
  • Loading branch information
ranfdev committed Oct 27, 2023
1 parent d933569 commit fb29cd9
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 38 deletions.
33 changes: 24 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ tracing-subscriber = "0.3"
adw = { version = "0.5", package = "libadwaita", features = ["v1_4"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
capnp = "0.17.2"
capnp-rpc = "0.17.0"
capnp = "0.18.0"
capnp-rpc = "0.18.0"
anyhow = "1.0.71"
chrono = "0.4.26"
rand = "0.8.5"
Expand Down
4 changes: 2 additions & 2 deletions ntfy-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ capnpc = "0.17.2"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
capnp = "0.17.2"
capnp-rpc = "0.17.0"
capnp = "0.18.0"
capnp-rpc = "0.18.0"
futures = "0.3.0"
tokio = { version = "1.0.0", features = ["net", "rt", "macros", "parking_lot"]}
tokio-util = { version = "0.7.4", features = ["compat", "io"] }
Expand Down
24 changes: 12 additions & 12 deletions ntfy-daemon/src/system_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl output_channel::Server for NotifyForwarder {
_results: output_channel::SendMessageResults,
) -> capnp::capability::Promise<(), capnp::Error> {
let request = pry!(params.get());
let message = pry!(request.get_message());
let message = pry!(pry!(request.get_message()).to_str());

// Store in database
let already_stored: bool = {
Expand Down Expand Up @@ -104,7 +104,7 @@ impl output_channel::Server for NotifyForwarder {
let watching = watching.borrow();
let futs = watching.iter().map(|(_id, w)| {
let mut req = w.send_message_request();
req.get().set_message(message);
req.get().set_message(message.into());
async move {
if let Err(e) = req.send().promise.await {
error!(error = ?e, "Error forwarding");
Expand Down Expand Up @@ -241,7 +241,7 @@ impl subscription::Server for SubscriptionImpl {

let futs = msgs.into_iter().map(move |msg| {
let mut req = watcher.send_message_request();
req.get().set_message(&msg);
req.get().set_message(msg.as_str().into());
req.send().promise
});

Expand All @@ -268,7 +268,7 @@ impl subscription::Server for SubscriptionImpl {
params: subscription::PublishParams,
_results: subscription::PublishResults,
) -> capnp::capability::Promise<(), capnp::Error> {
let msg = pry!(pry!(params.get()).get_message());
let msg = pry!(pry!(pry!(params.get()).get_message()).to_str());
let fut = self._publish(msg);

Promise::from_future(async move {
Expand All @@ -283,9 +283,9 @@ impl subscription::Server for SubscriptionImpl {
) -> capnp::capability::Promise<(), capnp::Error> {
let mut res = results.get();
let model = self.model.borrow();
res.set_server(&model.server);
res.set_display_name(&model.display_name);
res.set_topic(&model.topic);
res.set_server(model.server.as_str().into());
res.set_display_name(model.display_name.as_str().into());
res.set_topic(model.topic.as_str().into());
res.set_muted(model.muted);
res.set_read_until(model.read_until);
Promise::ok(())
Expand All @@ -297,7 +297,7 @@ impl subscription::Server for SubscriptionImpl {
) -> capnp::capability::Promise<(), capnp::Error> {
let info = pry!(pry!(params.get()).get_value());
let mut model = self.model.borrow_mut();
model.display_name = pry!(info.get_display_name()).to_string();
model.display_name = pry!(pry!(info.get_display_name()).to_string());
model.muted = info.get_muted();
model.read_until = info.get_read_until();
pry!(self.env.db.update_subscription(model.clone()));
Expand Down Expand Up @@ -395,8 +395,8 @@ impl system_notifier::Server for SystemNotifier {
params: system_notifier::SubscribeParams,
mut results: system_notifier::SubscribeResults,
) -> capnp::capability::Promise<(), capnp::Error> {
let topic = pry!(pry!(params.get()).get_topic());
let server: &str = pry!(pry!(params.get()).get_server());
let topic = pry!(pry!(pry!(params.get()).get_topic()).to_str());
let server: &str = pry!(pry!(pry!(params.get()).get_server()).to_str());

let subscription = pry!(models::Subscription::builder(topic.to_owned())
.server(server.to_string())
Expand All @@ -419,8 +419,8 @@ impl system_notifier::Server for SystemNotifier {
params: system_notifier::UnsubscribeParams,
_results: system_notifier::UnsubscribeResults,
) -> capnp::capability::Promise<(), capnp::Error> {
let topic = pry!(pry!(params.get()).get_topic());
let server = pry!(pry!(params.get()).get_server());
let topic = pry!(pry!(pry!(params.get()).get_topic()).to_str());
let server = pry!(pry!(pry!(params.get()).get_server()).to_str());
{
self.watching.borrow_mut().remove(&WatchKey {
server: server.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion ntfy-daemon/src/topic_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl TopicListener {
Event::Message { .. } => {
debug!("message event");
let mut req = self.output_channel.send_message_request();
req.get().set_message(&msg);
req.get().set_message(msg.as_str().into());
req.send().promise.await?;
}
Event::KeepAlive { .. } => {
Expand Down
14 changes: 7 additions & 7 deletions src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ impl output_channel::Server for TopicWatcher {
) -> capnp::capability::Promise<(), capnp::Error> {
if let Some(sub) = self.sub.upgrade() {
let request = pry!(params.get());
let message = pry!(request.get_message());
let message = pry!(pry!(request.get_message()).to_str());

let msg: models::Message = serde_json::from_str(&message).unwrap();
let msg: models::Message = serde_json::from_str(message).unwrap();
sub.imp().messages.append(&glib::BoxedAnyObject::new(msg));
sub.update_unread_count();
Promise::ok(())
Expand Down Expand Up @@ -175,11 +175,11 @@ impl Subscription {
let info = req_info.send().promise.await?;
let info = info.get()?;
this.init_info(
info.get_topic()?,
info.get_server()?,
info.get_topic()?.to_str()?,
info.get_server()?.to_str()?,
info.get_muted(),
info.get_read_until(),
info.get_display_name()?,
info.get_display_name()?.to_str()?,
);

let message_stream = req_messages.send().promise.await?;
Expand Down Expand Up @@ -214,7 +214,7 @@ impl Subscription {
let mut req = imp.client.get().unwrap().update_info_request();
let mut val = pry!(req.get().get_value());
val.set_muted(imp.muted.get());
val.set_display_name(&*imp.display_name.borrow());
val.set_display_name(imp.display_name.borrow().as_str().into());
val.set_read_until(imp.read_until.get());
Promise::from_future(async move {
debug!("sending update_info");
Expand Down Expand Up @@ -275,7 +275,7 @@ impl Subscription {
serde_json::to_string(&msg).map_err(|e| capnp::Error::failed(e.to_string()))
};
let mut req = imp.client.get().unwrap().publish_request();
req.get().set_message(&pry!(json));
req.get().set_message(pry!(json).as_str().into());

Promise::from_future(async move {
debug!("sending publish");
Expand Down
9 changes: 4 additions & 5 deletions src/widgets/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ impl NotifyWindow {
fn add_subscription(&self, sub: models::Subscription) {
let mut req = self.notifier().subscribe_request();

req.get().set_server(&sub.server);
req.get().set_topic(&sub.topic);
req.get().set_server(sub.server.as_str().into());
req.get().set_topic(sub.topic.as_str().into());
let res = req.send();
let this = self.clone();
self.spawn_with_near_toast(async move {
Expand All @@ -310,11 +310,10 @@ impl NotifyWindow {

fn unsubscribe(&self) {
let mut req = self.notifier().unsubscribe_request();

let sub = self.selected_subscription().unwrap();

req.get().set_server(&sub.server());
req.get().set_topic(&sub.topic());
req.get().set_server(sub.server().as_str().into());
req.get().set_topic(sub.topic().as_str().into());

let res = req.send();
let this = self.clone();
Expand Down

0 comments on commit fb29cd9

Please sign in to comment.