-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain_pins.py
More file actions
50 lines (37 loc) · 1.06 KB
/
Copy pathmain_pins.py
File metadata and controls
50 lines (37 loc) · 1.06 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# main_pins.py — Manage skills pinned to the top of the main bar (Ctrl+Alt)
import json
import os
MAX_MAIN_PINS = 5
def _pins_file():
from config import BASE_DIR
return os.path.join(BASE_DIR, "main_pinned.json")
def load() -> set:
try:
with open(_pins_file(), "r") as f:
return set(json.load(f))
except Exception:
return set()
def _save(pins: set):
try:
path = _pins_file()
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "w") as f:
json.dump(list(pins), f)
except Exception:
pass
def toggle(title: str) -> set:
pins = load()
if title in pins:
pins.discard(title)
elif len(pins) < MAX_MAIN_PINS:
pins.add(title)
_save(pins)
return pins
def is_pinned(title: str) -> bool:
return title in load()
def get_pinned_skills(skills: list) -> list:
"""Return skills filtered to pinned ones (in original order)."""
pins = load()
if not pins:
return []
return [s for s in skills if s["title"] in pins]