Skip to content

Commit

Permalink
Refresh ankihub menu when about to show
Browse files Browse the repository at this point in the history
  • Loading branch information
RisingOrange committed Jan 14, 2025
1 parent e481c07 commit 64be045
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
10 changes: 3 additions & 7 deletions ankihub/gui/menu.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""AnkiHub menu on Anki's main window."""

import re
from concurrent.futures import Future
from dataclasses import dataclass
Expand Down Expand Up @@ -49,13 +50,8 @@ class _MenuState:
def setup_ankihub_menu() -> None:
menu_state.ankihub_menu = QMenu("&AnkiHub", parent=aqt.mw)
aqt.mw.form.menubar.addMenu(menu_state.ankihub_menu)
config.token_change_hook.append(
lambda: aqt.mw.taskman.run_on_main(refresh_ankihub_menu)
)
config.subscriptions_change_hook = lambda: aqt.mw.taskman.run_on_main(
refresh_ankihub_menu
)
refresh_ankihub_menu()

menu_state.ankihub_menu.aboutToShow.connect(refresh_ankihub_menu)


def refresh_ankihub_menu() -> None:
Expand Down
6 changes: 0 additions & 6 deletions ankihub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def __init__(self):
self._private_config: Optional[PrivateConfig] = None
self._private_config_path: Optional[Path] = None
self.token_change_hook: List[Callable[[], None]] = []
self.subscriptions_change_hook: Optional[Callable[[], None]] = None
self.app_url: Optional[str] = None
self.s3_bucket_url: Optional[str] = None
self.anking_deck_id: Optional[uuid.UUID] = None
Expand Down Expand Up @@ -340,9 +339,6 @@ def add_deck(
self.save_latest_deck_update(ankihub_did, latest_udpate)
self._update_private_config()

if self.subscriptions_change_hook:
self.subscriptions_change_hook()

def update_deck(self, deck: Deck):
"""Update the deck config with the values from the Deck object."""
deck_config = self.deck_config(deck.ah_did)
Expand All @@ -363,8 +359,6 @@ def remove_deck_and_its_extensions(self, ankihub_did: uuid.UUID) -> None:
if self._private_config.decks.get(ankihub_did):
self._private_config.decks.pop(ankihub_did)
self._update_private_config()
if self.subscriptions_change_hook:
self.subscriptions_change_hook()

def log_private_config(self, log_level=logging.INFO):
config_copy = deepcopy(self._private_config)
Expand Down

0 comments on commit 64be045

Please sign in to comment.