mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
Fix lack of progress/error when importing a .colpkg
We should be accessing the backend progress state, instead of the collection's state.
This commit is contained in:
parent
b37063e20a
commit
0173ebf384
4 changed files with 59 additions and 39 deletions
|
@ -33,6 +33,8 @@ service BackendCollectionService {
|
||||||
// If a backup is running, wait for it to complete. Will return an error
|
// If a backup is running, wait for it to complete. Will return an error
|
||||||
// if the backup encountered an error.
|
// if the backup encountered an error.
|
||||||
rpc AwaitBackupCompletion(generic.Empty) returns (generic.Empty);
|
rpc AwaitBackupCompletion(generic.Empty) returns (generic.Empty);
|
||||||
|
rpc LatestProgress(generic.Empty) returns (Progress);
|
||||||
|
rpc SetWantsAbort(generic.Empty) returns (generic.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
message OpenCollectionRequest {
|
message OpenCollectionRequest {
|
||||||
|
|
|
@ -82,49 +82,14 @@ impl BackendCollectionService for Backend {
|
||||||
self.await_backup_completion()?;
|
self.await_backup_completion()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl crate::services::CollectionService for Collection {
|
fn latest_progress(&self) -> Result<anki_proto::collection::Progress> {
|
||||||
fn check_database(&mut self) -> Result<anki_proto::collection::CheckDatabaseResponse> {
|
let progress = self.progress_state.lock().unwrap().last_progress;
|
||||||
{
|
|
||||||
self.check_database()
|
|
||||||
.map(|problems| anki_proto::collection::CheckDatabaseResponse {
|
|
||||||
problems: problems.to_i18n_strings(&self.tr),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_undo_status(&mut self) -> Result<anki_proto::collection::UndoStatus> {
|
|
||||||
Ok(self.undo_status().into_protobuf(&self.tr))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn undo(&mut self) -> Result<anki_proto::collection::OpChangesAfterUndo> {
|
|
||||||
self.undo().map(|out| out.into_protobuf(&self.tr))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn redo(&mut self) -> Result<anki_proto::collection::OpChangesAfterUndo> {
|
|
||||||
self.redo().map(|out| out.into_protobuf(&self.tr))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_custom_undo_entry(&mut self, input: generic::String) -> Result<generic::UInt32> {
|
|
||||||
Ok(self.add_custom_undo_step(input.val).into())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn merge_undo_entries(
|
|
||||||
&mut self,
|
|
||||||
input: generic::UInt32,
|
|
||||||
) -> Result<anki_proto::collection::OpChanges> {
|
|
||||||
let starting_from = input.val as usize;
|
|
||||||
self.merge_undoable_ops(starting_from).map(Into::into)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn latest_progress(&mut self) -> Result<anki_proto::collection::Progress> {
|
|
||||||
let progress = self.state.progress.lock().unwrap().last_progress;
|
|
||||||
Ok(progress_to_proto(progress, &self.tr))
|
Ok(progress_to_proto(progress, &self.tr))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_wants_abort(&mut self) -> Result<()> {
|
fn set_wants_abort(&self) -> Result<()> {
|
||||||
self.state.progress.lock().unwrap().want_abort = true;
|
self.progress_state.lock().unwrap().want_abort = true;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
pub mod backup;
|
pub mod backup;
|
||||||
|
mod service;
|
||||||
pub(crate) mod timestamps;
|
pub(crate) mod timestamps;
|
||||||
mod transact;
|
mod transact;
|
||||||
pub(crate) mod undo;
|
pub(crate) mod undo;
|
||||||
|
|
52
rslib/src/collection/service.rs
Normal file
52
rslib/src/collection/service.rs
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
use anki_proto::generic;
|
||||||
|
|
||||||
|
use crate::collection::Collection;
|
||||||
|
use crate::error;
|
||||||
|
use crate::progress::progress_to_proto;
|
||||||
|
|
||||||
|
impl crate::services::CollectionService for Collection {
|
||||||
|
fn check_database(&mut self) -> error::Result<anki_proto::collection::CheckDatabaseResponse> {
|
||||||
|
{
|
||||||
|
self.check_database()
|
||||||
|
.map(|problems| anki_proto::collection::CheckDatabaseResponse {
|
||||||
|
problems: problems.to_i18n_strings(&self.tr),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_undo_status(&mut self) -> error::Result<anki_proto::collection::UndoStatus> {
|
||||||
|
Ok(self.undo_status().into_protobuf(&self.tr))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn undo(&mut self) -> error::Result<anki_proto::collection::OpChangesAfterUndo> {
|
||||||
|
self.undo().map(|out| out.into_protobuf(&self.tr))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn redo(&mut self) -> error::Result<anki_proto::collection::OpChangesAfterUndo> {
|
||||||
|
self.redo().map(|out| out.into_protobuf(&self.tr))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_custom_undo_entry(&mut self, input: generic::String) -> error::Result<generic::UInt32> {
|
||||||
|
Ok(self.add_custom_undo_step(input.val).into())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn merge_undo_entries(
|
||||||
|
&mut self,
|
||||||
|
input: generic::UInt32,
|
||||||
|
) -> error::Result<anki_proto::collection::OpChanges> {
|
||||||
|
let starting_from = input.val as usize;
|
||||||
|
self.merge_undoable_ops(starting_from).map(Into::into)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn latest_progress(&mut self) -> error::Result<anki_proto::collection::Progress> {
|
||||||
|
let progress = self.state.progress.lock().unwrap().last_progress;
|
||||||
|
Ok(progress_to_proto(progress, &self.tr))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_wants_abort(&mut self) -> error::Result<()> {
|
||||||
|
self.state.progress.lock().unwrap().want_abort = true;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue