init
This commit is contained in:
19
windows_py_client/synctv_client/device_store.py
Normal file
19
windows_py_client/synctv_client/device_store.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import secrets
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class DeviceStore:
|
||||
def __init__(self) -> None:
|
||||
self.path = Path.home() / "AppData" / "Roaming" / "SyncTV" / "device.id"
|
||||
|
||||
def get_or_create(self) -> str:
|
||||
if self.path.exists():
|
||||
current = self.path.read_text(encoding="utf-8").strip()
|
||||
if current:
|
||||
return current
|
||||
self.path.parent.mkdir(parents=True, exist_ok=True)
|
||||
device_id = "dev_" + secrets.token_hex(12)
|
||||
self.path.write_text(device_id, encoding="utf-8")
|
||||
return device_id
|
||||
Reference in New Issue
Block a user