Merge pull request #1247 from Raven95676/shared_preferences

perf: shared_preferences加载失败时自动删除无效文件
This commit is contained in:
Soulter authored and GitHub committed 2025-04-12 20:04:19 +08:00
commit 011542dc2b
1 file changed
+3 -1
+3 -1
View File
@@ -8,9 +8,11 @@ class SharedPreferences:
self._data = self._load_preferences()
def _load_preferences(self):
if os.path.exists(self.path):
try:
with open(self.path, "r") as f:
return json.load(f)
except json.JSONDecodeError:
os.remove(self.path)
return {}
def _save_preferences(self):