Fixed popping inside iteration & fixed themes folder not getting created

This commit is contained in:
anne 2023-09-01 23:15:50 +02:00
parent d3ee9d07e0
commit ea4ffe2c93
2 changed files with 11 additions and 3 deletions

View file

@ -52,14 +52,14 @@ def validateDataDir():
errorlogs = os.path.join(datadir, "errorlogs") errorlogs = os.path.join(datadir, "errorlogs")
backup = os.path.join(datadir, "backup") backup = os.path.join(datadir, "backup")
themes = os.path.join(datadir, "themes") themes = os.path.join(datadir, "themes")
# ~lisanne Datadir/themes for repository themes # ~lisanne `datadir/themes` is for repository installed themes
# Apparently everything checks this folder for themes already # Apparently everything checks this folder for themes already
# So hopefully im not plugging into an existng system on accident # So hopefully im not plugging into an existng system on accident
js_pchum = os.path.join(datadir, "pesterchum.js") js_pchum = os.path.join(datadir, "pesterchum.js")
js_manifest = os.path.join(datadir, "manifest.js") js_manifest = os.path.join(datadir, "manifest.js")
dirs = [datadir, profile, quirks, logs, errorlogs, backup] dirs = [datadir, profile, quirks, logs, themes, errorlogs, backup]
for d in dirs: for d in dirs:
if not os.path.isdir(d) or not os.path.exists(d): if not os.path.isdir(d) or not os.path.exists(d):
os.makedirs(d, exist_ok=True) os.makedirs(d, exist_ok=True)

View file

@ -63,6 +63,9 @@ class ThemeManager(QtCore.QObject):
self.manifest = json.load(f) self.manifest = json.load(f)
PchumLog.debug("Manifest.js loaded with: %s", self.manifest) PchumLog.debug("Manifest.js loaded with: %s", self.manifest)
self.config = config self.config = config
# TODO: maybe make seperate QNetworkAccessManagers for theme downloads, database fetches, and integrity checkfile
# OR figure out how to connect the signal to tasks instead of the whole object
# That way we dont have to figure out what got downloaded afterwards, and can just have a _on_reply_theme & _on_reply_database or something
self.NAManager = QtNetwork.QNetworkAccessManager() self.NAManager = QtNetwork.QNetworkAccessManager()
self.NAManager.finished[QtNetwork.QNetworkReply].connect(self._on_reply) self.NAManager.finished[QtNetwork.QNetworkReply].connect(self._on_reply)
self.validate_manifest() self.validate_manifest()
@ -99,6 +102,7 @@ class ThemeManager(QtCore.QObject):
def validate_manifest(self): def validate_manifest(self):
# Checks if the themes the manifest claims are installed actually exists # Checks if the themes the manifest claims are installed actually exists
# Removes them from the manifest if they dont # Removes them from the manifest if they dont
to_pop = set()
all_themes = self.config.availableThemes() all_themes = self.config.availableThemes()
for theme_name in self.manifest: for theme_name in self.manifest:
if not theme_name in all_themes: if not theme_name in all_themes:
@ -106,7 +110,11 @@ class ThemeManager(QtCore.QObject):
"Supposedly installed theme %s from the manifest seems to have been deleted, removing from manifest now", "Supposedly installed theme %s from the manifest seems to have been deleted, removing from manifest now",
theme_name, theme_name,
) )
self.manifest.pop(theme_name) # Cannot be popped while iterating!
to_pop.add(theme_name)
for theme_name in to_pop:
self.manifest.pop(theme_name)
def download_theme(self, theme_name): def download_theme(self, theme_name):
# Downloads the theme .zip # Downloads the theme .zip