improved autosave + added last opened file
This commit is contained in:
27
src/config.py
Normal file
27
src/config.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import json
|
||||
import os.path
|
||||
|
||||
|
||||
class Config:
|
||||
LAST_OPENED_FILE = ""
|
||||
AUTOSAVE_INTERVAL = 5 * 60 * 1000
|
||||
|
||||
def __init__(self, path: str):
|
||||
self._path: str = path
|
||||
|
||||
self.load()
|
||||
|
||||
def load(self) -> None:
|
||||
if os.path.exists(self._path):
|
||||
with open(self._path, "r") as f:
|
||||
config = json.load(f)
|
||||
|
||||
self.LAST_OPENED_FILE = config["last_opened_file"]
|
||||
self.AUTOSAVE_INTERVAL = config["autosave_interval"]
|
||||
|
||||
def save(self) -> None:
|
||||
with open(self._path, "w") as f:
|
||||
json.dump({
|
||||
"last_opened_file": self.LAST_OPENED_FILE,
|
||||
"autosave_interval": self.AUTOSAVE_INTERVAL
|
||||
}, f, indent=4)
|
||||
Reference in New Issue
Block a user