From 4d2ab991c225b2e47dc06a838f191b2303808b42 Mon Sep 17 00:00:00 2001 From: Kirill Salnikov Date: Mon, 8 Feb 2021 04:40:44 +0300 Subject: [PATCH] Fix bug in loadProfile method (#229) Bug: if sync is enabled for profile, then we have alot of recursive calls to loadProfile method because main window is still active until sync is ended. And this freezes Anki app. --- plugin/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugin/__init__.py b/plugin/__init__.py index f2d8c51..4eef76b 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -304,7 +304,17 @@ class AnkiConnect: cur_profile = self.window().pm.name if cur_profile != name: self.window().unloadProfileAndShowProfileManager() - self.loadProfile(name) + + def waiter(): + # This function waits until main window is closed + # It's needed cause sync can take quite some time + # And if we call loadProfile until sync is ended things will go wrong + if self.window().isVisible(): + QTimer.singleShot(1000, waiter) + else: + self.loadProfile(name) + + waiter() else: self.window().pm.load(name) self.window().loadProfile()