From 9430e3ddf2fd5852916e26aca13b5ff71cfc6d3c Mon Sep 17 00:00:00 2001 From: RumovZ Date: Tue, 18 Jul 2023 14:26:59 +0200 Subject: [PATCH] Fix addon update dialog showing twice (#2580) * Gitignore .ninja_deps * Don't check for addon updates on profile unload This fixes two update dialogs showing up when switching profiles. * Only show addon update dialog once ... instead of once every time the profile is changed, when the version doesn't match. This is analogous to when the dialog is triggered by elapsed time. * Manage last_run_version update in ProfileManager --- .gitignore | 1 + qt/aqt/main.py | 15 +++++---------- qt/aqt/profiles.py | 9 +++------ 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 7b0c7f127..21e7a06b6 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ target node_modules .n2_db .ninja_log +.ninja_deps diff --git a/qt/aqt/main.py b/qt/aqt/main.py index 0bcbb2ea7..fba2ffd42 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -498,6 +498,8 @@ class AnkiQt(QMainWindow): self._refresh_after_sync() if onsuccess: onsuccess() + if not self.safeMode: + self.maybe_check_for_addon_updates(self.setupAutoUpdate) self.maybe_auto_sync_on_open_close(_onsuccess) @@ -952,7 +954,7 @@ title="{}" {}>{}""".format( if on_done: on_done() - if elap > 86_400 or self.pm.last_run_version() != point_version(): + if elap > 86_400 or self.pm.last_run_version != point_version(): check_and_prompt_for_updates( self, self.addonManager, @@ -1033,16 +1035,10 @@ title="{}" {}>{}""".format( def maybe_auto_sync_on_open_close(self, after_sync: Callable[[], None]) -> None: "If disabled, after_sync() is called immediately." - - def after_sync_and_call_addon_update() -> None: - after_sync() - if not self.safeMode: - self.maybe_check_for_addon_updates(self.setupAutoUpdate) - if self.can_auto_sync(): - self._sync_collection_and_media(after_sync_and_call_addon_update) + self._sync_collection_and_media(after_sync) else: - after_sync_and_call_addon_update() + after_sync() def maybe_auto_sync_media(self) -> None: if self.can_auto_sync(): @@ -1154,7 +1150,6 @@ title="{}" {}>{}""".format( ########################################################################## def closeEvent(self, event: QCloseEvent) -> None: - self.pm.set_last_run_version() if self.state == "profileManager": # if profile manager active, this event may fire via OS X menu bar's # quit option diff --git a/qt/aqt/profiles.py b/qt/aqt/profiles.py index fffca16bf..7cfc38fce 100644 --- a/qt/aqt/profiles.py +++ b/qt/aqt/profiles.py @@ -117,6 +117,7 @@ class LoadMetaResult: class ProfileManager: default_answer_keys = {ease_num: str(ease_num) for ease_num in range(1, 5)} + last_run_version: int = 0 def __init__(self, base: Path) -> None: # "base should be retrieved via ProfileMangager.get_created_base_folder" @@ -132,6 +133,8 @@ class ProfileManager: # load metadata res = self._loadMeta() self.firstRun = res.firstTime + self.last_run_version = self.meta.get("last_run_version", self.last_run_version) + self.meta["last_run_version"] = point_version() return res # -p profile provided on command line. @@ -506,12 +509,6 @@ create table if not exists profiles # Shared options ###################################################################### - def last_run_version(self) -> int: - return self.meta.get("last_run_version", 0) - - def set_last_run_version(self) -> None: - self.meta["last_run_version"] = point_version() - def uiScale(self) -> float: scale = self.meta.get("uiScale", 1.0) return max(scale, 1)