20 lines
595 B
Python
20 lines
595 B
Python
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
|