Add missing calls
This commit is contained in:
@ -42,6 +42,16 @@ pub enum NtfyMessage {
|
|||||||
WatchSubscribed {
|
WatchSubscribed {
|
||||||
respond_to: oneshot::Sender<anyhow::Result<()>>,
|
respond_to: oneshot::Sender<anyhow::Result<()>>,
|
||||||
},
|
},
|
||||||
|
AddAccount {
|
||||||
|
server: String,
|
||||||
|
username: String,
|
||||||
|
password: String,
|
||||||
|
respond_to: oneshot::Sender<anyhow::Result<()>>,
|
||||||
|
},
|
||||||
|
RemoveAccount {
|
||||||
|
server: String,
|
||||||
|
respond_to: oneshot::Sender<anyhow::Result<()>>,
|
||||||
|
},
|
||||||
Shutdown,
|
Shutdown,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,6 +183,21 @@ impl NtfyActor {
|
|||||||
let _ = respond_to.send(result);
|
let _ = respond_to.send(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NtfyMessage::AddAccount {
|
||||||
|
server,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
respond_to,
|
||||||
|
} => {
|
||||||
|
let result = self.env.credentials.insert(&server, &username, &password).await;
|
||||||
|
let _ = respond_to.send(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
NtfyMessage::RemoveAccount { server, respond_to } => {
|
||||||
|
let result = self.env.credentials.delete(&server).await;
|
||||||
|
let _ = respond_to.send(result);
|
||||||
|
}
|
||||||
|
|
||||||
NtfyMessage::Shutdown => break,
|
NtfyMessage::Shutdown => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -296,6 +321,34 @@ impl NtfyHandle {
|
|||||||
|
|
||||||
rx.await.map_err(|_| anyhow!("Actor response error"))?
|
rx.await.map_err(|_| anyhow!("Actor response error"))?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn add_account(&self, server: &str, username: &str, password: &str) -> anyhow::Result<()> {
|
||||||
|
let (tx, rx) = oneshot::channel();
|
||||||
|
self.command_tx
|
||||||
|
.send(NtfyMessage::AddAccount {
|
||||||
|
server: server.to_string(),
|
||||||
|
username: username.to_string(),
|
||||||
|
password: password.to_string(),
|
||||||
|
respond_to: tx,
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.map_err(|_| anyhow!("Actor mailbox error"))?;
|
||||||
|
|
||||||
|
rx.await.map_err(|_| anyhow!("Actor response error"))?
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn remove_account(&self, server: &str) -> anyhow::Result<()> {
|
||||||
|
let (tx, rx) = oneshot::channel();
|
||||||
|
self.command_tx
|
||||||
|
.send(NtfyMessage::RemoveAccount {
|
||||||
|
server: server.to_string(),
|
||||||
|
respond_to: tx,
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.map_err(|_| anyhow!("Actor mailbox error"))?;
|
||||||
|
|
||||||
|
rx.await.map_err(|_| anyhow!("Actor response error"))?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(
|
pub fn start(
|
||||||
|
|||||||
@ -229,10 +229,10 @@ impl NotifyApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show_preferences(&self) {
|
fn show_preferences(&self) {
|
||||||
// let win = crate::widgets::NotifyPreferences::new(
|
let win = crate::widgets::NotifyPreferences::new(
|
||||||
// self.main_window().imp().notifier.get().unwrap().clone(),
|
self.main_window().imp().notifier.get().unwrap().clone(),
|
||||||
// );
|
);
|
||||||
// win.present(Some(&self.main_window()));
|
win.present(Some(&self.main_window()));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(&self) -> glib::ExitCode {
|
pub fn run(&self) -> glib::ExitCode {
|
||||||
|
|||||||
@ -3,11 +3,12 @@ use std::cell::OnceCell;
|
|||||||
use adw::prelude::*;
|
use adw::prelude::*;
|
||||||
use adw::subclass::prelude::*;
|
use adw::subclass::prelude::*;
|
||||||
use gtk::{gio, glib};
|
use gtk::{gio, glib};
|
||||||
use ntfy_daemon::ntfy_capnp::system_notifier;
|
|
||||||
|
|
||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
|
|
||||||
mod imp {
|
mod imp {
|
||||||
|
use ntfy_daemon::NtfyHandle;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[derive(gtk::CompositeTemplate)]
|
#[derive(gtk::CompositeTemplate)]
|
||||||
@ -25,7 +26,7 @@ mod imp {
|
|||||||
pub added_accounts: TemplateChild<gtk::ListBox>,
|
pub added_accounts: TemplateChild<gtk::ListBox>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub added_accounts_group: TemplateChild<adw::PreferencesGroup>,
|
pub added_accounts_group: TemplateChild<adw::PreferencesGroup>,
|
||||||
pub notifier: OnceCell<system_notifier::Client>,
|
pub notifier: OnceCell<NtfyHandle>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for NotifyPreferences {
|
impl Default for NotifyPreferences {
|
||||||
@ -77,7 +78,7 @@ glib::wrapper! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NotifyPreferences {
|
impl NotifyPreferences {
|
||||||
pub fn new(notifier: system_notifier::Client) -> Self {
|
pub fn new(notifier: ntfy_daemon::NtfyHandle ) -> Self {
|
||||||
let obj: Self = glib::Object::builder().build();
|
let obj: Self = glib::Object::builder().build();
|
||||||
obj.imp()
|
obj.imp()
|
||||||
.notifier
|
.notifier
|
||||||
@ -100,21 +101,16 @@ impl NotifyPreferences {
|
|||||||
|
|
||||||
pub async fn show_accounts(&self) -> anyhow::Result<()> {
|
pub async fn show_accounts(&self) -> anyhow::Result<()> {
|
||||||
let imp = self.imp();
|
let imp = self.imp();
|
||||||
let req = imp.notifier.get().unwrap().list_accounts_request();
|
let accounts = imp.notifier.get().unwrap().list_accounts().await?;
|
||||||
let res = req.send().promise.await?;
|
|
||||||
|
|
||||||
let accounts = res.get()?.get_list()?;
|
|
||||||
|
|
||||||
imp.added_accounts_group.set_visible(!accounts.is_empty());
|
imp.added_accounts_group.set_visible(!accounts.is_empty());
|
||||||
|
|
||||||
imp.added_accounts.remove_all();
|
imp.added_accounts.remove_all();
|
||||||
for a in accounts {
|
for a in accounts {
|
||||||
let server = a.get_server()?.to_string()?;
|
|
||||||
let username = a.get_username()?.to_string()?;
|
|
||||||
|
|
||||||
let row = adw::ActionRow::builder()
|
let row = adw::ActionRow::builder()
|
||||||
.title(&server)
|
.title(&a.server)
|
||||||
.subtitle(&username)
|
.subtitle(&a.username)
|
||||||
.build();
|
.build();
|
||||||
row.add_css_class("property");
|
row.add_css_class("property");
|
||||||
row.add_suffix(&{
|
row.add_suffix(&{
|
||||||
@ -125,10 +121,9 @@ impl NotifyPreferences {
|
|||||||
let this = self.clone();
|
let this = self.clone();
|
||||||
btn.connect_clicked(move |btn| {
|
btn.connect_clicked(move |btn| {
|
||||||
let this = this.clone();
|
let this = this.clone();
|
||||||
let username = username.clone();
|
let a = a.clone();
|
||||||
let server = server.clone();
|
|
||||||
btn.error_boundary()
|
btn.error_boundary()
|
||||||
.spawn(async move { this.remove_account(&server, &username).await });
|
.spawn(async move { this.remove_account(&a.server).await });
|
||||||
});
|
});
|
||||||
btn
|
btn
|
||||||
});
|
});
|
||||||
@ -142,29 +137,14 @@ impl NotifyPreferences {
|
|||||||
let server = imp.server_entry.text();
|
let server = imp.server_entry.text();
|
||||||
let username = imp.username_entry.text();
|
let username = imp.username_entry.text();
|
||||||
|
|
||||||
let mut req = imp.notifier.get().unwrap().add_account_request();
|
imp.notifier.get().unwrap().add_account(&server, &username, &password).await?;
|
||||||
let mut acc = req.get().get_account()?;
|
|
||||||
acc.set_username(username[..].into());
|
|
||||||
acc.set_server(server[..].into());
|
|
||||||
req.get().set_password(password[..].into());
|
|
||||||
|
|
||||||
req.send().promise.await?;
|
|
||||||
|
|
||||||
self.show_accounts().await?;
|
self.show_accounts().await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub async fn remove_account(&self, server: &str, username: &str) -> anyhow::Result<()> {
|
pub async fn remove_account(&self, server: &str) -> anyhow::Result<()> {
|
||||||
let mut req = self.imp().notifier.get().unwrap().remove_account_request();
|
self.imp().notifier.get().unwrap().remove_account(server).await?;
|
||||||
let mut acc = req.get().get_account()?;
|
|
||||||
|
|
||||||
acc.set_username(username[..].into());
|
|
||||||
acc.set_server(server[..].into());
|
|
||||||
|
|
||||||
req.send().promise.await?;
|
|
||||||
|
|
||||||
self.show_accounts().await?;
|
self.show_accounts().await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -141,7 +141,8 @@ mod imp {
|
|||||||
});
|
});
|
||||||
klass.install_action("win.clear-notifications", None, |this, _, _| {
|
klass.install_action("win.clear-notifications", None, |this, _, _| {
|
||||||
this.selected_subscription().map(|sub| {
|
this.selected_subscription().map(|sub| {
|
||||||
this.error_boundary().spawn(async move {sub.clear_notifications().await});
|
this.error_boundary()
|
||||||
|
.spawn(async move { sub.clear_notifications().await });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
//klass.bind_template_instance_callbacks();
|
//klass.bind_template_instance_callbacks();
|
||||||
@ -288,24 +289,20 @@ impl NotifyWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn unsubscribe(&self) {
|
fn unsubscribe(&self) {
|
||||||
// let mut req = self.notifier().unsubscribe_request();
|
let sub = self.selected_subscription().unwrap();
|
||||||
// let sub = self.selected_subscription().unwrap();
|
|
||||||
|
|
||||||
// req.get().set_server(sub.server().as_str().into());
|
let this = self.clone();
|
||||||
// req.get().set_topic(sub.topic().as_str().into());
|
self.error_boundary().spawn(async move {
|
||||||
|
this.notifier()
|
||||||
|
.unsubscribe(sub.server().as_str(), sub.topic().as_str())
|
||||||
|
.await?;
|
||||||
|
|
||||||
// let res = req.send();
|
let imp = this.imp();
|
||||||
// let this = self.clone();
|
if let Some(i) = imp.subscription_list_model.find(&sub) {
|
||||||
|
imp.subscription_list_model.remove(i);
|
||||||
// self.error_boundary().spawn(async move {
|
}
|
||||||
// let imp = this.imp();
|
Ok(())
|
||||||
// res.promise.await?;
|
});
|
||||||
|
|
||||||
// if let Some(i) = imp.subscription_list_model.find(&sub) {
|
|
||||||
// imp.subscription_list_model.remove(i);
|
|
||||||
// }
|
|
||||||
// Ok(())
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
fn notifier(&self) -> &NtfyHandle {
|
fn notifier(&self) -> &NtfyHandle {
|
||||||
self.imp().notifier.get().unwrap()
|
self.imp().notifier.get().unwrap()
|
||||||
@ -406,7 +403,7 @@ impl NotifyWindow {
|
|||||||
{
|
{
|
||||||
self.selected_subscription().map(|sub| {
|
self.selected_subscription().map(|sub| {
|
||||||
self.error_boundary()
|
self.error_boundary()
|
||||||
.spawn(async move {sub.flag_all_as_read().await});
|
.spawn(async move { sub.flag_all_as_read().await });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user