Skip to content

Commit

Permalink
Finally fixed the UI lockup when adding magazine
Browse files Browse the repository at this point in the history
  • Loading branch information
ping committed Aug 3, 2023
1 parent 15042cd commit 4082c4a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions calibre-plugin/dialog/magazines.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def found_media(self, media, card):
self,
_("Add Magazine"),
_(
"Added {magazine} for monitoring.\nClick OK to refresh.".format(
"Added {magazine} for monitoring.\nClick OK to refresh, or the ESC key to continue without.".format(
magazine=media["title"]
)
),
Expand All @@ -429,9 +429,10 @@ def _get_fetch_library_media_thread(
):
thread = QThread()
worker = OverDriveLibraryMediaWorker()
worker.setup(overdrive_client, card, title_id)
worker.moveToThread(thread)
thread.worker = worker
thread.started.connect(lambda: worker.run(overdrive_client, card, title_id))
thread.started.connect(worker.run)

def loaded(media):
self.found_media(media, card)
Expand Down
10 changes: 6 additions & 4 deletions calibre-plugin/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ class OverDriveLibraryMediaWorker(QObject):
finished = pyqtSignal(dict)
errored = pyqtSignal(Exception)

def __int__(self):
super().__init__()
def setup(self, overdrive_client: OverDriveClient, card: Dict, title_id: str):
self.client = overdrive_client
self.card = card
self.title_id = title_id

def run(self, overdrive_client: OverDriveClient, card: Dict, title_id: str):
def run(self):
total_start = timer()
try:
media = overdrive_client.library_media(card["advantageKey"], title_id)
media = self.client.library_media(self.card["advantageKey"], self.title_id)
logger.info(
"Total OverDrive Library Media Fetch took %f seconds"
% (timer() - total_start)
Expand Down

0 comments on commit 4082c4a

Please sign in to comment.