@@ -4,7 +4,6 @@ use std::{iter::once, ops::Deref, sync::Arc};
4
4
5
5
use anyhow:: Result ;
6
6
use humansize:: { BINARY , format_size} ;
7
- use tokio:: sync:: Mutex ;
8
7
9
8
use crate :: events:: EventType ;
10
9
use crate :: imap:: { FolderMeaning , scan_folders:: get_watched_folder_configs} ;
@@ -160,52 +159,51 @@ impl DetailedConnectivity {
160
159
}
161
160
162
161
#[ derive( Clone , Default ) ]
163
- pub ( crate ) struct ConnectivityStore ( Arc < Mutex < DetailedConnectivity > > ) ;
162
+ pub ( crate ) struct ConnectivityStore ( Arc < parking_lot :: Mutex < DetailedConnectivity > > ) ;
164
163
165
164
impl ConnectivityStore {
166
- async fn set ( & self , context : & Context , v : DetailedConnectivity ) {
165
+ fn set ( & self , context : & Context , v : DetailedConnectivity ) {
167
166
{
168
- * self . 0 . lock ( ) . await = v;
167
+ * self . 0 . lock ( ) = v;
169
168
}
170
169
context. emit_event ( EventType :: ConnectivityChanged ) ;
171
170
}
172
171
173
- pub ( crate ) async fn set_err ( & self , context : & Context , e : impl ToString ) {
174
- self . set ( context, DetailedConnectivity :: Error ( e. to_string ( ) ) )
175
- . await ;
172
+ pub ( crate ) fn set_err ( & self , context : & Context , e : impl ToString ) {
173
+ self . set ( context, DetailedConnectivity :: Error ( e. to_string ( ) ) ) ;
176
174
}
177
- pub ( crate ) async fn set_connecting ( & self , context : & Context ) {
178
- self . set ( context, DetailedConnectivity :: Connecting ) . await ;
175
+ pub ( crate ) fn set_connecting ( & self , context : & Context ) {
176
+ self . set ( context, DetailedConnectivity :: Connecting ) ;
179
177
}
180
- pub ( crate ) async fn set_working ( & self , context : & Context ) {
181
- self . set ( context, DetailedConnectivity :: Working ) . await ;
178
+ pub ( crate ) fn set_working ( & self , context : & Context ) {
179
+ self . set ( context, DetailedConnectivity :: Working ) ;
182
180
}
183
- pub ( crate ) async fn set_preparing ( & self , context : & Context ) {
184
- self . set ( context, DetailedConnectivity :: Preparing ) . await ;
181
+ pub ( crate ) fn set_preparing ( & self , context : & Context ) {
182
+ self . set ( context, DetailedConnectivity :: Preparing ) ;
185
183
}
186
- pub ( crate ) async fn set_not_configured ( & self , context : & Context ) {
187
- self . set ( context, DetailedConnectivity :: NotConfigured ) . await ;
184
+ pub ( crate ) fn set_not_configured ( & self , context : & Context ) {
185
+ self . set ( context, DetailedConnectivity :: NotConfigured ) ;
188
186
}
189
- pub ( crate ) async fn set_idle ( & self , context : & Context ) {
190
- self . set ( context, DetailedConnectivity :: Idle ) . await ;
187
+ pub ( crate ) fn set_idle ( & self , context : & Context ) {
188
+ self . set ( context, DetailedConnectivity :: Idle ) ;
191
189
}
192
190
193
- async fn get_detailed ( & self ) -> DetailedConnectivity {
194
- self . 0 . lock ( ) . await . deref ( ) . clone ( )
191
+ fn get_detailed ( & self ) -> DetailedConnectivity {
192
+ self . 0 . lock ( ) . deref ( ) . clone ( )
195
193
}
196
- async fn get_basic ( & self ) -> Option < Connectivity > {
197
- self . 0 . lock ( ) . await . to_basic ( )
194
+ fn get_basic ( & self ) -> Option < Connectivity > {
195
+ self . 0 . lock ( ) . to_basic ( )
198
196
}
199
- async fn get_all_work_done ( & self ) -> bool {
200
- self . 0 . lock ( ) . await . all_work_done ( )
197
+ fn get_all_work_done ( & self ) -> bool {
198
+ self . 0 . lock ( ) . all_work_done ( )
201
199
}
202
200
}
203
201
204
202
/// Set all folder states to InterruptingIdle in case they were `Idle` before.
205
203
/// Called during `dc_maybe_network()` to make sure that `all_work_done()`
206
204
/// returns false immediately after `dc_maybe_network()`.
207
- pub ( crate ) async fn idle_interrupted ( inbox : ConnectivityStore , oboxes : Vec < ConnectivityStore > ) {
208
- let mut connectivity_lock = inbox. 0 . lock ( ) . await ;
205
+ pub ( crate ) fn idle_interrupted ( inbox : ConnectivityStore , oboxes : Vec < ConnectivityStore > ) {
206
+ let mut connectivity_lock = inbox. 0 . lock ( ) ;
209
207
// For the inbox, we also have to set the connectivity to InterruptingIdle if it was
210
208
// NotConfigured before: If all folders are NotConfigured, dc_get_connectivity()
211
209
// returns Connected. But after dc_maybe_network(), dc_get_connectivity() must not
@@ -219,7 +217,7 @@ pub(crate) async fn idle_interrupted(inbox: ConnectivityStore, oboxes: Vec<Conne
219
217
drop ( connectivity_lock) ;
220
218
221
219
for state in oboxes {
222
- let mut connectivity_lock = state. 0 . lock ( ) . await ;
220
+ let mut connectivity_lock = state. 0 . lock ( ) ;
223
221
if * connectivity_lock == DetailedConnectivity :: Idle {
224
222
* connectivity_lock = DetailedConnectivity :: InterruptingIdle ;
225
223
}
@@ -231,9 +229,9 @@ pub(crate) async fn idle_interrupted(inbox: ConnectivityStore, oboxes: Vec<Conne
231
229
/// Set the connectivity to "Not connected" after a call to dc_maybe_network_lost().
232
230
/// If we did not do this, the connectivity would stay "Connected" for quite a long time
233
231
/// after `maybe_network_lost()` was called.
234
- pub ( crate ) async fn maybe_network_lost ( context : & Context , stores : Vec < ConnectivityStore > ) {
232
+ pub ( crate ) fn maybe_network_lost ( context : & Context , stores : Vec < ConnectivityStore > ) {
235
233
for store in & stores {
236
- let mut connectivity_lock = store. 0 . lock ( ) . await ;
234
+ let mut connectivity_lock = store. 0 . lock ( ) ;
237
235
if !matches ! (
238
236
* connectivity_lock,
239
237
DetailedConnectivity :: Uninitialized
@@ -248,7 +246,7 @@ pub(crate) async fn maybe_network_lost(context: &Context, stores: Vec<Connectivi
248
246
249
247
impl fmt:: Debug for ConnectivityStore {
250
248
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
251
- if let Ok ( guard) = self . 0 . try_lock ( ) {
249
+ if let Some ( guard) = self . 0 . try_lock ( ) {
252
250
write ! ( f, "ConnectivityStore {:?}" , & * guard)
253
251
} else {
254
252
write ! ( f, "ConnectivityStore [LOCKED]" )
@@ -271,11 +269,11 @@ impl Context {
271
269
/// e.g. in the title of the main screen.
272
270
///
273
271
/// If the connectivity changes, a DC_EVENT_CONNECTIVITY_CHANGED will be emitted.
274
- pub async fn get_connectivity ( & self ) -> Connectivity {
272
+ pub fn get_connectivity ( & self ) -> Connectivity {
275
273
let stores = self . connectivities . lock ( ) . clone ( ) ;
276
274
let mut connectivities = Vec :: new ( ) ;
277
275
for s in stores {
278
- if let Some ( connectivity) = s. get_basic ( ) . await {
276
+ if let Some ( connectivity) = s. get_basic ( ) {
279
277
connectivities. push ( connectivity) ;
280
278
}
281
279
}
@@ -393,7 +391,7 @@ impl Context {
393
391
let f = self . get_config ( config) . await . log_err ( self ) . ok ( ) . flatten ( ) ;
394
392
395
393
if let Some ( foldername) = f {
396
- let detailed = & state. get_detailed ( ) . await ;
394
+ let detailed = & state. get_detailed ( ) ;
397
395
ret += "<li>" ;
398
396
ret += & * detailed. to_icon ( ) ;
399
397
ret += " <b>" ;
@@ -407,7 +405,7 @@ impl Context {
407
405
}
408
406
409
407
if !folder_added && folder == & FolderMeaning :: Inbox {
410
- let detailed = & state. get_detailed ( ) . await ;
408
+ let detailed = & state. get_detailed ( ) ;
411
409
if let DetailedConnectivity :: Error ( _) = detailed {
412
410
// On the inbox thread, we also do some other things like scan_folders and run jobs
413
411
// so, maybe, the inbox is not watched, but something else went wrong
@@ -429,7 +427,7 @@ impl Context {
429
427
430
428
let outgoing_messages = stock_str:: outgoing_messages ( self ) . await ;
431
429
ret += & format ! ( "<h3>{outgoing_messages}</h3><ul><li>" ) ;
432
- let detailed = smtp. get_detailed ( ) . await ;
430
+ let detailed = smtp. get_detailed ( ) ;
433
431
ret += & * detailed. to_icon ( ) ;
434
432
ret += " " ;
435
433
ret += & * escaper:: encode_minimal ( & detailed. to_string_smtp ( self ) . await ) ;
@@ -553,7 +551,7 @@ impl Context {
553
551
drop ( lock) ;
554
552
555
553
for s in & stores {
556
- if !s. get_all_work_done ( ) . await {
554
+ if !s. get_all_work_done ( ) {
557
555
return false ;
558
556
}
559
557
}
0 commit comments