working_init
This commit is contained in:
@ -23,6 +23,7 @@ mod imp {
|
||||
use std::cell::RefCell;
|
||||
|
||||
use glib::WeakRef;
|
||||
use ntfy_daemon::Ntfy;
|
||||
use once_cell::sync::OnceCell;
|
||||
|
||||
use super::*;
|
||||
@ -32,6 +33,7 @@ mod imp {
|
||||
pub window: RefCell<WeakRef<NotifyWindow>>,
|
||||
pub socket_path: RefCell<PathBuf>,
|
||||
pub hold_guard: OnceCell<gio::ApplicationHoldGuard>,
|
||||
pub ntfy: OnceCell<Ntfy>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
@ -227,10 +229,10 @@ impl NotifyApplication {
|
||||
}
|
||||
|
||||
fn show_preferences(&self) {
|
||||
let win = crate::widgets::NotifyPreferences::new(
|
||||
self.main_window().imp().notifier.get().unwrap().clone(),
|
||||
);
|
||||
win.present(Some(&self.main_window()));
|
||||
// let win = crate::widgets::NotifyPreferences::new(
|
||||
// self.main_window().imp().notifier.get().unwrap().clone(),
|
||||
// );
|
||||
// win.present(Some(&self.main_window()));
|
||||
}
|
||||
|
||||
pub fn run(&self) -> glib::ExitCode {
|
||||
@ -317,42 +319,25 @@ impl NotifyApplication {
|
||||
}
|
||||
}
|
||||
let proxies = std::sync::Arc::new(Proxies { notification: s });
|
||||
ntfy_daemon::system_client::start(
|
||||
let ntfy = ntfy_daemon::Ntfy::start(
|
||||
socket_path.to_owned(),
|
||||
dbpath.to_str().unwrap(),
|
||||
proxies.clone(),
|
||||
proxies,
|
||||
)
|
||||
.unwrap();
|
||||
self.imp()
|
||||
.ntfy
|
||||
.set(ntfy)
|
||||
.or(Err(anyhow::anyhow!("failed setting ntfy")))
|
||||
.unwrap();
|
||||
self.imp().hold_guard.set(self.hold()).unwrap();
|
||||
}
|
||||
|
||||
fn build_window(&self, socket_path: &Path) {
|
||||
let address = UnixSocketAddress::new(socket_path);
|
||||
let client = SocketClient::new();
|
||||
let connection =
|
||||
SocketClientExt::connect(&client, &address, gio::Cancellable::NONE).unwrap();
|
||||
let ntfy = self.imp().ntfy.get().unwrap();
|
||||
|
||||
let rw = connection.into_async_read_write().unwrap();
|
||||
let (reader, writer) = rw.split();
|
||||
|
||||
let rpc_network = Box::new(twoparty::VatNetwork::new(
|
||||
reader,
|
||||
writer,
|
||||
rpc_twoparty_capnp::Side::Client,
|
||||
Default::default(),
|
||||
));
|
||||
let mut rpc_system = RpcSystem::new(rpc_network, None);
|
||||
let client: system_notifier::Client =
|
||||
rpc_system.bootstrap(rpc_twoparty_capnp::Side::Server);
|
||||
|
||||
glib::MainContext::default().spawn_local(async move {
|
||||
debug!("rpc_system started");
|
||||
rpc_system.await.unwrap();
|
||||
debug!("rpc_system stopped");
|
||||
});
|
||||
|
||||
let window = NotifyWindow::new(self, client);
|
||||
let window = NotifyWindow::new(self, ntfy.clone());
|
||||
*self.imp().window.borrow_mut() = window.downgrade();
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ use futures::prelude::*;
|
||||
use gtk::{gio, glib};
|
||||
use ntfy_daemon::models;
|
||||
use ntfy_daemon::ntfy_capnp::{system_notifier, Status};
|
||||
use ntfy_daemon::Ntfy;
|
||||
use tracing::warn;
|
||||
|
||||
use crate::application::NotifyApplication;
|
||||
@ -52,7 +53,7 @@ mod imp {
|
||||
pub send_btn: TemplateChild<gtk::Button>,
|
||||
#[template_child]
|
||||
pub code_btn: TemplateChild<gtk::Button>,
|
||||
pub notifier: OnceCell<system_notifier::Client>,
|
||||
pub notifier: OnceCell<Ntfy>,
|
||||
pub conn: OnceCell<gio::SocketConnection>,
|
||||
pub settings: gio::Settings,
|
||||
pub banner_binding: Cell<Option<(Subscription, glib::SignalHandlerId)>>,
|
||||
@ -190,7 +191,7 @@ glib::wrapper! {
|
||||
}
|
||||
|
||||
impl NotifyWindow {
|
||||
pub fn new(app: &NotifyApplication, notifier: system_notifier::Client) -> Self {
|
||||
pub fn new(app: &NotifyApplication, notifier: Ntfy) -> Self {
|
||||
let obj: Self = glib::Object::builder().property("application", app).build();
|
||||
|
||||
if let Err(_) = obj.imp().notifier.set(notifier) {
|
||||
@ -260,49 +261,49 @@ impl NotifyWindow {
|
||||
}
|
||||
|
||||
fn add_subscription(&self, sub: models::Subscription) {
|
||||
let mut req = self.notifier().subscribe_request();
|
||||
// let mut req = self.notifier().subscribe_request();
|
||||
|
||||
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.error_boundary().spawn(async move {
|
||||
let imp = this.imp();
|
||||
// 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.error_boundary().spawn(async move {
|
||||
// let imp = this.imp();
|
||||
|
||||
// Subscription::new will use the pipelined client to retrieve info about the subscription
|
||||
let subscription = Subscription::new(res.pipeline.get_subscription());
|
||||
// We want to still check if there were any errors adding the subscription.
|
||||
res.promise.await?;
|
||||
// // Subscription::new will use the pipelined client to retrieve info about the subscription
|
||||
// let subscription = Subscription::new(res.pipeline.get_subscription());
|
||||
// // We want to still check if there were any errors adding the subscription.
|
||||
// res.promise.await?;
|
||||
|
||||
imp.subscription_list_model.append(&subscription);
|
||||
let i = imp.subscription_list_model.n_items() - 1;
|
||||
let row = imp.subscription_list.row_at_index(i as i32);
|
||||
imp.subscription_list.select_row(row.as_ref());
|
||||
Ok(())
|
||||
});
|
||||
// imp.subscription_list_model.append(&subscription);
|
||||
// let i = imp.subscription_list_model.n_items() - 1;
|
||||
// let row = imp.subscription_list.row_at_index(i as i32);
|
||||
// imp.subscription_list.select_row(row.as_ref());
|
||||
// Ok(())
|
||||
// });
|
||||
}
|
||||
|
||||
fn unsubscribe(&self) {
|
||||
let mut req = self.notifier().unsubscribe_request();
|
||||
let sub = self.selected_subscription().unwrap();
|
||||
// let mut req = self.notifier().unsubscribe_request();
|
||||
// let sub = self.selected_subscription().unwrap();
|
||||
|
||||
req.get().set_server(sub.server().as_str().into());
|
||||
req.get().set_topic(sub.topic().as_str().into());
|
||||
// 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();
|
||||
// let res = req.send();
|
||||
// let this = self.clone();
|
||||
|
||||
self.error_boundary().spawn(async move {
|
||||
let imp = this.imp();
|
||||
res.promise.await?;
|
||||
// self.error_boundary().spawn(async move {
|
||||
// let imp = this.imp();
|
||||
// res.promise.await?;
|
||||
|
||||
if let Some(i) = imp.subscription_list_model.find(&sub) {
|
||||
imp.subscription_list_model.remove(i);
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
// if let Some(i) = imp.subscription_list_model.find(&sub) {
|
||||
// imp.subscription_list_model.remove(i);
|
||||
// }
|
||||
// Ok(())
|
||||
// });
|
||||
}
|
||||
fn notifier(&self) -> &system_notifier::Client {
|
||||
fn notifier(&self) -> &Ntfy {
|
||||
self.imp().notifier.get().unwrap()
|
||||
}
|
||||
fn selected_subscription(&self) -> Option<Subscription> {
|
||||
@ -313,32 +314,32 @@ impl NotifyWindow {
|
||||
.and_downcast::<Subscription>()
|
||||
}
|
||||
fn bind_message_list(&self) {
|
||||
let imp = self.imp();
|
||||
// let imp = self.imp();
|
||||
|
||||
imp.subscription_list
|
||||
.bind_model(Some(&imp.subscription_list_model), |obj| {
|
||||
let sub = obj.downcast_ref::<Subscription>().unwrap();
|
||||
// imp.subscription_list
|
||||
// .bind_model(Some(&imp.subscription_list_model), |obj| {
|
||||
// let sub = obj.downcast_ref::<Subscription>().unwrap();
|
||||
|
||||
Self::build_subscription_row(&sub).upcast()
|
||||
});
|
||||
// Self::build_subscription_row(&sub).upcast()
|
||||
// });
|
||||
|
||||
let this = self.clone();
|
||||
imp.subscription_list.connect_row_selected(move |_, _row| {
|
||||
this.selected_subscription_changed(this.selected_subscription().as_ref());
|
||||
});
|
||||
// let this = self.clone();
|
||||
// imp.subscription_list.connect_row_selected(move |_, _row| {
|
||||
// this.selected_subscription_changed(this.selected_subscription().as_ref());
|
||||
// });
|
||||
|
||||
let this = self.clone();
|
||||
let req = self.notifier().list_subscriptions_request();
|
||||
let res = req.send();
|
||||
self.error_boundary().spawn(async move {
|
||||
let list = res.promise.await?;
|
||||
let list = list.get()?.get_list()?;
|
||||
let imp = this.imp();
|
||||
for sub in list {
|
||||
imp.subscription_list_model.append(&Subscription::new(sub?));
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
// let this = self.clone();
|
||||
// let req = self.notifier().list_subscriptions_request();
|
||||
// let res = req.send();
|
||||
// self.error_boundary().spawn(async move {
|
||||
// let list = res.promise.await?;
|
||||
// let list = list.get()?.get_list()?;
|
||||
// let imp = this.imp();
|
||||
// for sub in list {
|
||||
// imp.subscription_list_model.append(&Subscription::new(sub?));
|
||||
// }
|
||||
// Ok(())
|
||||
// });
|
||||
}
|
||||
fn update_banner(&self, sub: Option<&Subscription>) {
|
||||
let imp = self.imp();
|
||||
|
||||
Reference in New Issue
Block a user