From 6e383a42eac1289e54ee5bf96f950d9f547c48a2 Mon Sep 17 00:00:00 2001 From: Lemmy Date: Sat, 17 Jan 2026 15:52:41 -0500 Subject: [PATCH] Telemetry: instanceId is now fully random. --- Commons/ShellState.qml | 27 +++++++++++++ Services/Noctalia/TelemetryService.qml | 55 +++++--------------------- 2 files changed, 37 insertions(+), 45 deletions(-) diff --git a/Commons/ShellState.qml b/Commons/ShellState.qml index fab2400b7..f2826a7b2 100644 --- a/Commons/ShellState.qml +++ b/Commons/ShellState.qml @@ -66,6 +66,11 @@ Singleton { property var ui: ({ settingsSidebarExpanded: true }) + + // Telemetry state + property var telemetry: ({ + instanceId: "" + }) } onLoaded: { @@ -198,6 +203,28 @@ Singleton { return getUiState().settingsSidebarExpanded !== false; // default to true } + // Telemetry state + function setTelemetryState(stateData) { + adapter.telemetry = stateData; + save(); + } + + function getTelemetryState() { + return adapter.telemetry || { + instanceId: "" + }; + } + + function getTelemetryInstanceId() { + return getTelemetryState().instanceId || ""; + } + + function setTelemetryInstanceId(instanceId) { + let state = getTelemetryState(); + state.instanceId = instanceId; + setTelemetryState(state); + } + // ----------------------------------------------------- function buildStateSnapshot() { try { diff --git a/Services/Noctalia/TelemetryService.qml b/Services/Noctalia/TelemetryService.qml index e0edc1382..e2c65235d 100644 --- a/Services/Noctalia/TelemetryService.qml +++ b/Services/Noctalia/TelemetryService.qml @@ -17,7 +17,6 @@ Singleton { property string instanceId: "" readonly property string telemetryEndpoint: Quickshell.env("NOCTALIA_TELEMETRY_ENDPOINT") || "https://noctalia.dev:7777/ping" - readonly property string instanceIdSalt: "noctalia-telemetry-2025" function init() { if (initialized) @@ -30,52 +29,18 @@ Singleton { return; } - // Read machine-id to generate instance ID, then read RAM, then send ping - machineIdProcess.running = true; - } - - Process { - id: machineIdProcess - command: ["cat", "/etc/machine-id"] - running: false - - stdout: StdioCollector { - onStreamFinished: { - const machineId = text.trim(); - if (machineId && machineId.length > 0) { - root.instanceId = root.hashString(machineId + root.instanceIdSalt); - Logger.d("Telemetry", "Generated instance ID from machine-id"); - } else { - root.instanceId = root.generateRandomId(); - Logger.d("Telemetry", "Using random instance ID (machine-id unavailable)"); - } - memInfoProcess.running = true; - } + // Get or generate instance ID from ShellState + instanceId = ShellState.getTelemetryInstanceId(); + if (!instanceId) { + instanceId = generateRandomId(); + ShellState.setTelemetryInstanceId(instanceId); + Logger.d("Telemetry", "Generated new random instance ID"); + } else { + Logger.d("Telemetry", "Using stored instance ID"); } - onExited: function (exitCode) { - if (exitCode !== 0) { - root.instanceId = root.generateRandomId(); - Logger.d("Telemetry", "Using random instance ID (machine-id read failed)"); - memInfoProcess.running = true; - } - } - } - - function hashString(str) { - // Simple hash function that produces a UUID-like string - let hash = 0; - for (let i = 0; i < str.length; i++) { - const c = str.charCodeAt(i); - hash = ((hash << 5) - hash) + c; - hash = hash & hash; - } - // Convert to hex and pad to create UUID-like format - const hex = Math.abs(hash).toString(16).padStart(8, '0'); - const hex2 = Math.abs(hash * 31).toString(16).padStart(8, '0'); - const hex3 = Math.abs(hash * 37).toString(16).padStart(8, '0'); - const hex4 = Math.abs(hash * 41).toString(16).padStart(8, '0'); - return `${hex.slice(0, 8)}-${hex2.slice(0, 4)}-${hex2.slice(4, 8)}-${hex3.slice(0, 4)}-${hex3.slice(4, 8)}${hex4.slice(0, 4)}`; + // Read RAM info, then send ping + memInfoProcess.running = true; } function generateRandomId() {