mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 10:56:29 +03:00
ref(jsonrpc): Getting backup provider QR code now blocks (#4198)
This changes the JSON-RPC APIs to get a QR code from the backup provider to block. It means once you have a (blocking) call to provide_backup() you can call get_backup_qr() or get_backup_qr_svg() and they will block until the QR code is available. Calling get_backup_qr() or get_backup_qr_svg() when there is no backup provider will immediately error.
This commit is contained in:
committed by
GitHub
parent
7ec3a1a9a2
commit
e985588c6c
@@ -23,7 +23,6 @@ use crate::events::{Event, EventEmitter, EventType, Events};
|
||||
use crate::key::{DcKey, SignedPublicKey};
|
||||
use crate::login_param::LoginParam;
|
||||
use crate::message::{self, MessageState, MsgId};
|
||||
use crate::qr::Qr;
|
||||
use crate::quota::QuotaInfo;
|
||||
use crate::scheduler::SchedulerState;
|
||||
use crate::sql::Sql;
|
||||
@@ -241,14 +240,6 @@ pub struct InnerContext {
|
||||
|
||||
/// If debug logging is enabled, this contains all necessary information
|
||||
pub(crate) debug_logging: RwLock<Option<DebugLogging>>,
|
||||
|
||||
/// QR code for currently running [`BackupProvider`].
|
||||
///
|
||||
/// This is only available if a backup export is currently running, it will also be
|
||||
/// holding the ongoing process while running.
|
||||
///
|
||||
/// [`BackupProvider`]: crate::imex::BackupProvider
|
||||
pub(crate) export_provider: std::sync::Mutex<Option<Qr>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -393,7 +384,6 @@ impl Context {
|
||||
last_full_folder_scan: Mutex::new(None),
|
||||
last_error: std::sync::RwLock::new("".to_string()),
|
||||
debug_logging: RwLock::new(None),
|
||||
export_provider: std::sync::Mutex::new(None),
|
||||
};
|
||||
|
||||
let ctx = Context {
|
||||
@@ -568,17 +558,6 @@ impl Context {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the QR-code of the currently running [`BackupProvider`].
|
||||
///
|
||||
/// [`BackupProvider`]: crate::imex::BackupProvider
|
||||
pub fn backup_export_qr(&self) -> Option<Qr> {
|
||||
self.export_provider
|
||||
.lock()
|
||||
.expect("poisoned lock")
|
||||
.as_ref()
|
||||
.cloned()
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* UI chat/message related API
|
||||
******************************************************************************/
|
||||
|
||||
@@ -126,16 +126,14 @@ impl BackupProvider {
|
||||
let handle = {
|
||||
let context = context.clone();
|
||||
tokio::spawn(async move {
|
||||
let res = Self::watch_provider(&context, provider, cancel_token, dbfile).await;
|
||||
let res = Self::watch_provider(&context, provider, cancel_token).await;
|
||||
context.free_ongoing().await;
|
||||
paused_guard.resume().await;
|
||||
drop(dbfile);
|
||||
res
|
||||
})
|
||||
};
|
||||
let slf = Self { handle, ticket };
|
||||
let qr = slf.qr();
|
||||
*context.export_provider.lock().expect("poisoned lock") = Some(qr);
|
||||
Ok(slf)
|
||||
Ok(Self { handle, ticket })
|
||||
}
|
||||
|
||||
/// Creates the provider task.
|
||||
@@ -189,7 +187,6 @@ impl BackupProvider {
|
||||
context: &Context,
|
||||
mut provider: Provider,
|
||||
cancel_token: Receiver<()>,
|
||||
_dbfile: TempPathGuard,
|
||||
) -> Result<()> {
|
||||
// _dbfile exists so we can clean up the file once it is no longer needed
|
||||
let mut events = provider.subscribe();
|
||||
@@ -255,11 +252,6 @@ impl BackupProvider {
|
||||
},
|
||||
}
|
||||
};
|
||||
context
|
||||
.export_provider
|
||||
.lock()
|
||||
.expect("poisoned lock")
|
||||
.take();
|
||||
match &res {
|
||||
Ok(_) => context.emit_event(SendProgress::Completed.into()),
|
||||
Err(err) => {
|
||||
|
||||
Reference in New Issue
Block a user