Track created instances, show only ours in UI, v1.0.36

This commit is contained in:
2026-07-24 16:51:08 +04:00
parent 20573201b9
commit 560bd62fce
3 changed files with 55 additions and 2 deletions
+43
View File
@@ -0,0 +1,43 @@
"""Трекер созданных инстансов — только те что породило приложение."""
import json
import os
import threading
_LOCK = threading.Lock()
_PATH = os.path.join(os.path.dirname(__file__), "..", "instances.json")
def _load():
try:
with open(_PATH) as f:
return json.load(f)
except (FileNotFoundError, json.JSONDecodeError):
return {}
def _save(data):
with open(_PATH, "w") as f:
json.dump(data, f, indent=2)
def add(instance_uid, svc_id, display_name):
with _LOCK:
data = _load()
data[instance_uid] = {
"svcId": svc_id,
"displayName": display_name,
"instanceUid": instance_uid,
}
_save(data)
def remove(instance_uid):
with _LOCK:
data = _load()
data.pop(instance_uid, None)
_save(data)
def list_all():
with _LOCK:
return list(_load().values())