Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

feat: add enterprise device heartbeat to policy polling

Louis Beaumont3f41e316c4fe
diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-enterprise-policy.ts b/apps/screenpipe-app-tauri/lib/hooks/use-enterprise-policy.ts
index c9053b9ed..7f3de03e7 100644
--- a/apps/screenpipe-app-tauri/lib/hooks/use-enterprise-policy.ts
+++ b/apps/screenpipe-app-tauri/lib/hooks/use-enterprise-policy.ts
@@ -7,6 +7,8 @@ import { useIsEnterpriseBuild } from "./use-is-enterprise-build";
import { commands } from "@/lib/utils/tauri";
import { fetch as tauriFetch } from "@tauri-apps/plugin-http";
import { getStore } from "./use-settings";
+import { getVersion } from "@tauri-apps/api/app";
+import { platform as getPlatform } from "@tauri-apps/plugin-os";
interface ManagedAiPreset {
provider: string;
@@ -37,6 +39,50 @@ const POLL_INTERVAL_MS = 5 * 60 * 1000;
const CACHE_KEY = "enterprise-policy-cache";
+/**
+ * Fire-and-forget heartbeat to report device status to the enterprise API.
+ * Called after a successful policy fetch. Never throws, never blocks.
+ */
+async function sendHeartbeat(licenseKey: string): Promise<void> {
+ try {
+ const store = await getStore();
+ const settings = (await store.get<Record<string, unknown>>("settings")) || {};
+ const deviceId = (settings.deviceId as string) || "unknown";
+ const appVersion = await getVersion().catch(() => "unknown");
+ const devicePlatform = getPlatform();
+
+ let frameStatus = "unknown";
+ let audioStatus = "unknown";
+ let hostname = "unknown";
+ try {
+ const healthRes = await fetch("http://localhost:3030/health", {
+ signal: AbortSignal.timeout(2000),
+ });
+ if (healthRes.ok) {
+ const health = await healthRes.json();
+ frameStatus = health.frame_status || "unknown";
+ audioStatus = health.audio_status || "unknown";
+ hostname = health.hostname || "unknown";
+ }
+ } catch {}
+
+ await tauriFetch("https://screenpi.pe/api/enterprise/heartbeat", {
+ method: "POST",
+ headers: {
+ "X-License-Key": licenseKey,
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ device_id: deviceId,
+ hostname,
+ platform: devicePlatform,
+ app_version: appVersion,
+ recording_status: { frame_status: frameStatus, audio_status: audioStatus },
+ }),
+ });
+ } catch {}
+}
+
function cachePolicy(policy: EnterprisePolicy) {
try {
localStorage.setItem(CACHE_KEY, JSON.stringify(policy));
@@ -110,6 +156,9 @@ export function useEnterprisePolicy() {
);
cachePolicy(result);
+ // Fire-and-forget heartbeat
+ sendHeartbeat(licenseKey);
+
// Apply managed AI preset to settings store if configured
if (result.managedAiPreset) {
try {