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
This commit is contained in:
RumovZ 2023-07-18 14:26:59 +02:00 committed by GitHub
parent ca41dfeb3d
commit 9430e3ddf2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 16 deletions

1
.gitignore vendored
View file

@ -12,3 +12,4 @@ target
node_modules
.n2_db
.ninja_log
.ninja_deps

View file

@ -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="{}" {}>{}</button>""".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="{}" {}>{}</button>""".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="{}" {}>{}</button>""".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

View file

@ -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)