-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefs.py
33 lines (26 loc) · 959 Bytes
/
prefs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import pathlib
import json
PREF_KEYS = ["shorten_utun", "shorten_en"]
class Prefs:
_pref_file = pathlib.Path.home() / ".netivity"
def write_pref(self, key, value):
self.prefs[key] = value
self._pref_file.write_text(json.dumps(self.prefs))
def apply_prefs(self, app):
app.menu["Settings"]["Shorten `utun` to `t` in the menu bar"].state = (
self.prefs["shorten_utun"]
)
app.menu["Settings"]["Shorten `en` to `e` in the menu bar"].state = self.prefs[
"shorten_en"
]
def load_prefs(self):
if not self._pref_file.exists():
self._pref_file.write_text(
json.dumps({"shorten_utun": False, "shorten_en": False})
)
prefs_raw = self._pref_file.read_text()
prefs = json.loads(prefs_raw)
for key in PREF_KEYS:
if key not in prefs:
prefs[key] = False
self.prefs = prefs