@@ -3,11 +3,12 @@ use std::cell::OnceCell;
33use adw:: prelude:: * ;
44use adw:: subclass:: prelude:: * ;
55use gtk:: { gio, glib} ;
6- use ntfy_daemon:: ntfy_capnp:: system_notifier;
76
87use crate :: error:: * ;
98
109mod imp {
10+ use ntfy_daemon:: NtfyHandle ;
11+
1112 use super :: * ;
1213
1314 #[ derive( gtk:: CompositeTemplate ) ]
@@ -25,7 +26,7 @@ mod imp {
2526 pub added_accounts : TemplateChild < gtk:: ListBox > ,
2627 #[ template_child]
2728 pub added_accounts_group : TemplateChild < adw:: PreferencesGroup > ,
28- pub notifier : OnceCell < system_notifier :: Client > ,
29+ pub notifier : OnceCell < NtfyHandle > ,
2930 }
3031
3132 impl Default for NotifyPreferences {
@@ -77,7 +78,7 @@ glib::wrapper! {
7778}
7879
7980impl NotifyPreferences {
80- pub fn new ( notifier : system_notifier :: Client ) -> Self {
81+ pub fn new ( notifier : ntfy_daemon :: NtfyHandle ) -> Self {
8182 let obj: Self = glib:: Object :: builder ( ) . build ( ) ;
8283 obj. imp ( )
8384 . notifier
@@ -100,21 +101,16 @@ impl NotifyPreferences {
100101
101102 pub async fn show_accounts ( & self ) -> anyhow:: Result < ( ) > {
102103 let imp = self . imp ( ) ;
103- let req = imp. notifier . get ( ) . unwrap ( ) . list_accounts_request ( ) ;
104- let res = req. send ( ) . promise . await ?;
105-
106- let accounts = res. get ( ) ?. get_list ( ) ?;
104+ let accounts = imp. notifier . get ( ) . unwrap ( ) . list_accounts ( ) . await ?;
107105
108106 imp. added_accounts_group . set_visible ( !accounts. is_empty ( ) ) ;
109107
110108 imp. added_accounts . remove_all ( ) ;
111109 for a in accounts {
112- let server = a. get_server ( ) ?. to_string ( ) ?;
113- let username = a. get_username ( ) ?. to_string ( ) ?;
114110
115111 let row = adw:: ActionRow :: builder ( )
116- . title ( & server)
117- . subtitle ( & username)
112+ . title ( & a . server )
113+ . subtitle ( & a . username )
118114 . build ( ) ;
119115 row. add_css_class ( "property" ) ;
120116 row. add_suffix ( & {
@@ -125,10 +121,9 @@ impl NotifyPreferences {
125121 let this = self . clone ( ) ;
126122 btn. connect_clicked ( move |btn| {
127123 let this = this. clone ( ) ;
128- let username = username. clone ( ) ;
129- let server = server. clone ( ) ;
124+ let a = a. clone ( ) ;
130125 btn. error_boundary ( )
131- . spawn ( async move { this. remove_account ( & server, & username ) . await } ) ;
126+ . spawn ( async move { this. remove_account ( & a . server ) . await } ) ;
132127 } ) ;
133128 btn
134129 } ) ;
@@ -142,29 +137,14 @@ impl NotifyPreferences {
142137 let server = imp. server_entry . text ( ) ;
143138 let username = imp. username_entry . text ( ) ;
144139
145- let mut req = imp. notifier . get ( ) . unwrap ( ) . add_account_request ( ) ;
146- let mut acc = req. get ( ) . get_account ( ) ?;
147- acc. set_username ( username[ ..] . into ( ) ) ;
148- acc. set_server ( server[ ..] . into ( ) ) ;
149- req. get ( ) . set_password ( password[ ..] . into ( ) ) ;
150-
151- req. send ( ) . promise . await ?;
152-
140+ imp. notifier . get ( ) . unwrap ( ) . add_account ( & server, & username, & password) . await ?;
153141 self . show_accounts ( ) . await ?;
154142
155143 Ok ( ( ) )
156144 }
157- pub async fn remove_account ( & self , server : & str , username : & str ) -> anyhow:: Result < ( ) > {
158- let mut req = self . imp ( ) . notifier . get ( ) . unwrap ( ) . remove_account_request ( ) ;
159- let mut acc = req. get ( ) . get_account ( ) ?;
160-
161- acc. set_username ( username[ ..] . into ( ) ) ;
162- acc. set_server ( server[ ..] . into ( ) ) ;
163-
164- req. send ( ) . promise . await ?;
165-
145+ pub async fn remove_account ( & self , server : & str ) -> anyhow:: Result < ( ) > {
146+ self . imp ( ) . notifier . get ( ) . unwrap ( ) . remove_account ( server) . await ?;
166147 self . show_accounts ( ) . await ?;
167-
168148 Ok ( ( ) )
169149 }
170150}
0 commit comments