Skip to content

Commit

Permalink
Remove the logic of deleting cache.
Browse files Browse the repository at this point in the history
Now, the cache hash will be regenerated by the mirror server API endpoint, which is the most recommended approach.
  • Loading branch information
cary-rowen committed Feb 12, 2025
1 parent 7ef72dc commit ce459ac
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 30 deletions.
30 changes: 1 addition & 29 deletions addon/globalPlugins/updateMirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
# Copyright 2022-2023 Cary-Rowen <[email protected]>, zh-yx <[email protected]>
# released under GPL.

import json
import os.path
import shutil

import globalPluginHandler
import NVDAState
import updateCheck
import versionInfo
from logHandler import log
Expand All @@ -16,28 +11,8 @@
MIRROR_STORE_URL: str = "https://addonstore.nvaccess.mirror.nvdadr.com"
REQUIRED_PRIVATE_API_VERSION: tuple = (2023, 2)
REQUIRED_API_VERSION: tuple = (2024, 1)

CURRENT_API_VERSION: tuple = (versionInfo.version_year, versionInfo.version_major)
JSON_FILE_PATH: str = os.path.join(NVDAState.WritePaths.addonStoreDir, "_cachedCompatibleAddons.json")


def deleteAddonStoreCache(check_mirror: bool = True) -> None:
if os.path.exists(JSON_FILE_PATH):
try:
if check_mirror:
with open(JSON_FILE_PATH, 'r') as json_file:
data = json.load(json_file)
if "data" in data:
data = json.loads(data["data"])
url = data[0]["URL"]
if isinstance(url, str) and "https://github.mirror.nvdadr.com" in url:
return
log.info("Delete old add-on store cache.")
shutil.rmtree(NVDAState.WritePaths.addonStoreDir)
except Exception as e:
log.error(f"Add-on store cache deletion failed: {e}")



class GlobalPlugin(globalPluginHandler.GlobalPlugin):
def __init__(self):
super().__init__()
Expand All @@ -60,7 +35,6 @@ def swapNetworkBaseURL(self, URL: str) -> str:
from _addonStore import dataManager, network
originalURL = network._BASE_URL
network._BASE_URL = URL
deleteAddonStoreCache()
dataManager.initialize()
return originalURL

Expand All @@ -70,5 +44,3 @@ def terminate(self):
if CURRENT_API_VERSION >= REQUIRED_PRIVATE_API_VERSION:
log.info(f"Restore the Add-on store URL to: {self.original_BASE_URL}")
self.swapNetworkBaseURL(self.original_BASE_URL)
# Delete mirror cache
deleteAddonStoreCache(check_mirror=False)
2 changes: 1 addition & 1 deletion buildVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _(arg):
"addon_description": _("""This update mirror source is provided for NVDA Chinese community users.
It can enhance the update speed of NVDA, improve the search and download speed of the add-on store, and resolve issues where certain network operators are unable to download add-ons from the add-on store, thus effectively improving user experience."""),
# version
"addon_version": "0.7.0",
"addon_version": "0.7.1",
# Author(s)
"addon_author": "zh-yx, Cary-rowen, hwf1324 <[email protected]>",
# URL for the add-on documentation support
Expand Down

0 comments on commit ce459ac

Please sign in to comment.