Create more oppurtinities for state saving;
for image cache and settings
This commit is contained in:
1 parent
903b299bfe
commit
f3fd0fa5d9
3 files changed
+20
-3
No files matched your search
+4
-1
@@ -50,6 +50,7 @@ class Settings:
|
||||
def __init__(self, args: ParsedArgs):
|
||||
self._settings: SettingsFile = json_load(SETTINGS_PATH, default_settings)
|
||||
self._args: ParsedArgs = args
|
||||
self._altered: bool = False
|
||||
|
||||
# default logic of reading settings is to check args first, then the settings file
|
||||
def __getattr__(self, name: str, /) -> Any:
|
||||
@@ -65,6 +66,7 @@ class Settings:
|
||||
return super().__setattr__(name, value)
|
||||
elif name in self._settings:
|
||||
self._settings[name] = value # type: ignore[literal-required]
|
||||
self._altered = True
|
||||
return
|
||||
raise TypeError(f"{name} is missing a custom setter")
|
||||
|
||||
@@ -72,4 +74,5 @@ class Settings:
|
||||
raise RuntimeError("settings can't be deleted")
|
||||
|
||||
def save(self) -> None:
|
||||
json_save(SETTINGS_PATH, self._settings)
|
||||
if self._altered:
|
||||
json_save(SETTINGS_PATH, self._settings)
|
||||
Reference in new issue
Block a user