Files
jellytau/src/lib/services/deviceId.ts
T
dtourolle 6b90582e3e chore(tooling): add lint/format gates, pin the toolchain, enforce commit checks
Adds the frontend's first linter and formatter — the Rust half has had
cargo fmt --check and clippy in CI for a while, while 274 TS/Svelte files had
only svelte-check. ESLint runs clean; 159 findings are recorded as warnings
rather than suppressed, so the backlog is visible without painting CI red.

Also: `bun run test` no longer drops into watch mode (the "Before Committing"
list told people to run a command that never returns), the traceability ratchet
moves 82% -> 88%, a pre-commit hook enforces the fast half of that list instead
of relying on memory, the dead webdriverio e2e suite and its five devDeps are
removed, and the Rust toolchain is pinned to 1.97.1 so the developer machine and
the CI builder image stop being five releases apart.

TRACES: | DR-205, DR-206, DR-207
2026-08-20 19:53:13 +02:00

61 lines
1.6 KiB
TypeScript

/**
* Device ID Management Service
*
* Manages device identification for Jellyfin server communication.
* The Rust backend handles UUID generation and persistent storage in the database.
* This service provides a simple interface with in-memory caching.
*
* TRACES: UR-009 | DR-011
*/
import { commands } from "$lib/api/bindings";
import { createLogger } from "$lib/utils/logger";
const log = createLogger("deviceId");
let cachedDeviceId: string | null = null;
/**
* Get or create the device ID.
* Device ID is a UUID v4 that persists across app restarts.
* On first call, the Rust backend generates and stores a new UUID.
* On subsequent calls, the stored UUID is retrieved.
*
* @returns The device ID string (UUID v4)
*
* TRACES: UR-009 | DR-011
*/
export async function getDeviceId(): Promise<string> {
// Return cached value if available
if (cachedDeviceId) {
return cachedDeviceId;
}
try {
// Rust backend handles generation and storage atomically
const deviceId = await commands.deviceGetId();
cachedDeviceId = deviceId;
return deviceId;
} catch (e) {
log.error("Failed to get device ID from backend:", e);
throw new Error("Failed to initialize device ID: " + String(e), { cause: e });
}
}
/**
* Get cached device ID synchronously (if available)
* This should only be used after initial getDeviceId() call
*
* @returns The cached device ID, or empty string if not yet initialized
*/
export function getDeviceIdSync(): string {
return cachedDeviceId || "";
}
/**
* Clear cached device ID (for testing or logout scenarios)
*/
export function clearCache(): void {
cachedDeviceId = null;
}