fix(desktop): report real hostname/platform/arch in heartbeat
Renderer was registering clients with navigator.platform ("MacIntel") and
a hardcoded "renderer-preview" cpu_arch. Source device info from the main
process (os.hostname + process.platform/arch) via a new device-info IPC,
and let heartbeats always send the authoritative runtime values so stale
registrations self-heal.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { hostname } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
|
|
||||||
import { BrowserWindow, WebContentsView, app, ipcMain, nativeTheme } from "electron/main";
|
import { BrowserWindow, WebContentsView, app, ipcMain, nativeTheme } from "electron/main";
|
||||||
@@ -125,6 +126,11 @@ function safeHandle<Args extends unknown[], Result>(
|
|||||||
|
|
||||||
function registerBridgeHandlers(): void {
|
function registerBridgeHandlers(): void {
|
||||||
ipcMain.handle("desktop:ping", () => "pong");
|
ipcMain.handle("desktop:ping", () => "pong");
|
||||||
|
ipcMain.handle("desktop:device-info", () => ({
|
||||||
|
device_name: hostname() || `Desktop ${process.platform}`,
|
||||||
|
os: process.platform,
|
||||||
|
cpu_arch: process.arch,
|
||||||
|
}));
|
||||||
ipcMain.handle("desktop:runtime-snapshot", () => createRuntimeSnapshot());
|
ipcMain.handle("desktop:runtime-snapshot", () => createRuntimeSnapshot());
|
||||||
safeHandle("desktop:bind-publish-account", async (_event, platformId: string) => {
|
safeHandle("desktop:bind-publish-account", async (_event, platformId: string) => {
|
||||||
const account = (await bindPublishAccount(platformId)) as DesktopAccountInfo;
|
const account = (await bindPublishAccount(platformId)) as DesktopAccountInfo;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { hostname } from "node:os";
|
||||||
|
|
||||||
import { ApiClientError } from "@geo/http-client";
|
import { ApiClientError } from "@geo/http-client";
|
||||||
import type {
|
import type {
|
||||||
DesktopArticleContent,
|
DesktopArticleContent,
|
||||||
@@ -489,9 +491,9 @@ async function sendHeartbeat(source: "startup" | "timer"): Promise<void> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await heartbeatDesktopClient({
|
const response = await heartbeatDesktopClient({
|
||||||
device_name: state.client?.device_name ?? `Desktop ${process.platform}`,
|
device_name: hostname() || state.client?.device_name || `Desktop ${process.platform}`,
|
||||||
os: state.client?.os ?? process.platform,
|
os: process.platform,
|
||||||
cpu_arch: state.client?.cpu_arch ?? process.arch,
|
cpu_arch: process.arch,
|
||||||
client_version: state.client?.client_version ?? "0.1.0-dev",
|
client_version: state.client?.client_version ?? "0.1.0-dev",
|
||||||
channel: state.client?.channel ?? "dev",
|
channel: state.client?.channel ?? "dev",
|
||||||
account_ids: state.accounts.filter((account) => account.health === "live").map((account) => account.id),
|
account_ids: state.accounts.filter((account) => account.health === "live").map((account) => account.id),
|
||||||
|
|||||||
@@ -8,9 +8,16 @@ import type {
|
|||||||
} from "@geo/shared-types";
|
} from "@geo/shared-types";
|
||||||
import type { DesktopRuntimeSnapshot } from "../renderer/types";
|
import type { DesktopRuntimeSnapshot } from "../renderer/types";
|
||||||
|
|
||||||
|
interface DesktopDeviceInfo {
|
||||||
|
device_name: string;
|
||||||
|
os: string;
|
||||||
|
cpu_arch: string;
|
||||||
|
}
|
||||||
|
|
||||||
const desktopBridge = {
|
const desktopBridge = {
|
||||||
app: {
|
app: {
|
||||||
ping: () => ipcRenderer.invoke("desktop:ping") as Promise<string>,
|
ping: () => ipcRenderer.invoke("desktop:ping") as Promise<string>,
|
||||||
|
deviceInfo: () => ipcRenderer.invoke("desktop:device-info") as Promise<DesktopDeviceInfo>,
|
||||||
runtimeSnapshot: () =>
|
runtimeSnapshot: () =>
|
||||||
ipcRenderer.invoke("desktop:runtime-snapshot") as Promise<DesktopRuntimeSnapshot>,
|
ipcRenderer.invoke("desktop:runtime-snapshot") as Promise<DesktopRuntimeSnapshot>,
|
||||||
bindPublishAccount: (platformId: string) =>
|
bindPublishAccount: (platformId: string) =>
|
||||||
|
|||||||
@@ -167,12 +167,32 @@ function getOrCreateClientRegistrationID(user: UserInfo): string {
|
|||||||
return generated;
|
return generated;
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerPayload(user: UserInfo): DesktopClientRegisterRequest {
|
async function resolveDeviceInfo(): Promise<{ device_name: string; os: string; cpu_arch: string }> {
|
||||||
return {
|
const fallback = {
|
||||||
client_id: getOrCreateClientRegistrationID(user),
|
|
||||||
device_name: `Desktop ${navigator.platform || "unknown"}`,
|
device_name: `Desktop ${navigator.platform || "unknown"}`,
|
||||||
os: navigator.platform || "unknown",
|
os: navigator.platform || "unknown",
|
||||||
cpu_arch: "renderer-preview",
|
cpu_arch: "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const info = await window.desktopBridge?.app?.deviceInfo?.();
|
||||||
|
if (info?.device_name && info.os && info.cpu_arch) {
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.warn("[desktop-session] deviceInfo bridge failed", err);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function registerPayload(user: UserInfo): Promise<DesktopClientRegisterRequest> {
|
||||||
|
const device = await resolveDeviceInfo();
|
||||||
|
return {
|
||||||
|
client_id: getOrCreateClientRegistrationID(user),
|
||||||
|
device_name: device.device_name,
|
||||||
|
os: device.os,
|
||||||
|
cpu_arch: device.cpu_arch,
|
||||||
client_version: "0.1.0-dev",
|
client_version: "0.1.0-dev",
|
||||||
channel: "dev",
|
channel: "dev",
|
||||||
};
|
};
|
||||||
@@ -193,16 +213,17 @@ function createPreviewUser(): UserInfo {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function createPreviewClient(): DesktopClientInfo {
|
async function createPreviewClient(): Promise<DesktopClientInfo> {
|
||||||
const now = new Date().toISOString();
|
const now = new Date().toISOString();
|
||||||
|
const device = await resolveDeviceInfo();
|
||||||
return {
|
return {
|
||||||
id: "preview-client",
|
id: "preview-client",
|
||||||
tenant_id: 0,
|
tenant_id: 0,
|
||||||
workspace_id: 0,
|
workspace_id: 0,
|
||||||
user_id: 0,
|
user_id: 0,
|
||||||
device_name: `Preview ${navigator.platform || "Desktop"}`,
|
device_name: `Preview ${device.device_name}`,
|
||||||
os: navigator.platform || "browser",
|
os: device.os,
|
||||||
cpu_arch: "renderer-preview",
|
cpu_arch: device.cpu_arch,
|
||||||
client_version: "0.1.0-preview",
|
client_version: "0.1.0-preview",
|
||||||
channel: "dev",
|
channel: "dev",
|
||||||
created_at: now,
|
created_at: now,
|
||||||
@@ -260,7 +281,7 @@ async function login(payload: LoginRequest): Promise<void> {
|
|||||||
const registered = await createAuthenticatedClient().post<
|
const registered = await createAuthenticatedClient().post<
|
||||||
DesktopClientRegisterResponse,
|
DesktopClientRegisterResponse,
|
||||||
DesktopClientRegisterRequest
|
DesktopClientRegisterRequest
|
||||||
>("/api/desktop/clients/register", registerPayload(authData.user));
|
>("/api/desktop/clients/register", await registerPayload(authData.user));
|
||||||
|
|
||||||
persistClientRegistrationID(authData.user, registered.client.id);
|
persistClientRegistrationID(authData.user, registered.client.id);
|
||||||
|
|
||||||
@@ -282,7 +303,7 @@ async function login(payload: LoginRequest): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function enterPreview(): void {
|
async function enterPreview(): Promise<void> {
|
||||||
error.value = null;
|
error.value = null;
|
||||||
persistSession({
|
persistSession({
|
||||||
mode: "preview",
|
mode: "preview",
|
||||||
@@ -291,7 +312,7 @@ function enterPreview(): void {
|
|||||||
user: createPreviewUser(),
|
user: createPreviewUser(),
|
||||||
clientToken: "preview-client-token",
|
clientToken: "preview-client-token",
|
||||||
clientTokenExpiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000,
|
clientTokenExpiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000,
|
||||||
desktopClient: createPreviewClient(),
|
desktopClient: await createPreviewClient(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
@@ -14,6 +14,7 @@ declare global {
|
|||||||
desktopBridge: {
|
desktopBridge: {
|
||||||
app: {
|
app: {
|
||||||
ping(): Promise<string>;
|
ping(): Promise<string>;
|
||||||
|
deviceInfo(): Promise<{ device_name: string; os: string; cpu_arch: string }>;
|
||||||
runtimeSnapshot(): Promise<DesktopRuntimeSnapshot>;
|
runtimeSnapshot(): Promise<DesktopRuntimeSnapshot>;
|
||||||
bindPublishAccount(platformId: string): Promise<DesktopAccountInfo>;
|
bindPublishAccount(platformId: string): Promise<DesktopAccountInfo>;
|
||||||
refreshRuntimeAccounts(): Promise<null>;
|
refreshRuntimeAccounts(): Promise<null>;
|
||||||
|
|||||||
Reference in New Issue
Block a user