Add last version check for add-on updates (#1608)

* Add last version check for add-on updates

* Remove second add-on update check

* Show tooltip after toggling/deleting add-on
This commit is contained in:
RumovZ 2022-01-21 12:43:54 +01:00 committed by GitHub
parent a8d4774cdb
commit f6546c9f35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 4 deletions

View File

@ -726,6 +726,7 @@ class AddonsDialog(QDialog):
def __init__(self, addonsManager: AddonManager) -> None:
self.mgr = addonsManager
self.mw = addonsManager.mw
self._require_restart = False
super().__init__(self.mw)
@ -768,6 +769,8 @@ class AddonsDialog(QDialog):
self.onInstallFiles(paths)
def reject(self) -> None:
if self._require_restart:
tooltip(tr.addons_changes_will_take_effect_when_anki(), parent=self.mw)
saveGeom(self, "addons")
aqt.dialogs.markClosed("AddonsDialog")
@ -854,6 +857,7 @@ class AddonsDialog(QDialog):
def onToggleEnabled(self) -> None:
for module in self.selectedAddons():
self.mgr.toggleEnabled(module)
self._require_restart = True
self.redrawAddons()
def onViewPage(self) -> None:
@ -885,6 +889,9 @@ class AddonsDialog(QDialog):
return
gui_hooks.addons_dialog_will_delete_addons(self, selected)
for module in selected:
# doing this before deleting, as `enabled` is always True afterwards
if self.mgr.addon_meta(module).enabled:
self._require_restart = True
if not self.mgr.deleteAddon(module):
break
self.form.addonList.clearSelection()

View File

@ -31,7 +31,16 @@ from anki.decks import DeckDict, DeckId
from anki.hooks import runHook
from anki.notes import NoteId
from anki.sound import AVTag, SoundOrVideoTag
from anki.utils import dev_mode, ids2str, int_time, is_lin, is_mac, is_win, split_fields
from anki.utils import (
dev_mode,
ids2str,
int_time,
is_lin,
is_mac,
is_win,
point_version,
split_fields,
)
from aqt import gui_hooks
from aqt.addons import DownloadLogEntry, check_and_prompt_for_updates, show_log_to_user
from aqt.dbcheck import check_db
@ -713,7 +722,6 @@ class AnkiQt(QMainWindow):
gui_hooks.state_did_change(state, oldState)
def _deckBrowserState(self, oldState: str) -> None:
self.maybe_check_for_addon_updates()
self.deckBrowser.show()
def _selectedDeck(self) -> DeckDict | None:
@ -933,7 +941,7 @@ title="{}" {}>{}</button>""".format(
last_check = self.pm.last_addon_update_check()
elap = int_time() - last_check
if elap > 86_400:
if elap > 86_400 or self.pm.last_run_version() != point_version():
check_and_prompt_for_updates(
self,
self.addonManager,
@ -1112,6 +1120,7 @@ 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

@ -20,7 +20,7 @@ from anki.collection import Collection
from anki.db import DB
from anki.lang import without_unicode_isolation
from anki.sync import SyncAuth
from anki.utils import int_time, is_mac, is_win
from anki.utils import int_time, is_mac, is_win, point_version
from aqt import appHelpSite
from aqt.qt import *
from aqt.theme import Theme
@ -499,6 +499,12 @@ 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)