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:
@@ -167,12 +167,32 @@ function getOrCreateClientRegistrationID(user: UserInfo): string {
|
||||
return generated;
|
||||
}
|
||||
|
||||
function registerPayload(user: UserInfo): DesktopClientRegisterRequest {
|
||||
return {
|
||||
client_id: getOrCreateClientRegistrationID(user),
|
||||
async function resolveDeviceInfo(): Promise<{ device_name: string; os: string; cpu_arch: string }> {
|
||||
const fallback = {
|
||||
device_name: `Desktop ${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",
|
||||
channel: "dev",
|
||||
};
|
||||
@@ -193,16 +213,17 @@ function createPreviewUser(): UserInfo {
|
||||
};
|
||||
}
|
||||
|
||||
function createPreviewClient(): DesktopClientInfo {
|
||||
async function createPreviewClient(): Promise<DesktopClientInfo> {
|
||||
const now = new Date().toISOString();
|
||||
const device = await resolveDeviceInfo();
|
||||
return {
|
||||
id: "preview-client",
|
||||
tenant_id: 0,
|
||||
workspace_id: 0,
|
||||
user_id: 0,
|
||||
device_name: `Preview ${navigator.platform || "Desktop"}`,
|
||||
os: navigator.platform || "browser",
|
||||
cpu_arch: "renderer-preview",
|
||||
device_name: `Preview ${device.device_name}`,
|
||||
os: device.os,
|
||||
cpu_arch: device.cpu_arch,
|
||||
client_version: "0.1.0-preview",
|
||||
channel: "dev",
|
||||
created_at: now,
|
||||
@@ -260,7 +281,7 @@ async function login(payload: LoginRequest): Promise<void> {
|
||||
const registered = await createAuthenticatedClient().post<
|
||||
DesktopClientRegisterResponse,
|
||||
DesktopClientRegisterRequest
|
||||
>("/api/desktop/clients/register", registerPayload(authData.user));
|
||||
>("/api/desktop/clients/register", await registerPayload(authData.user));
|
||||
|
||||
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;
|
||||
persistSession({
|
||||
mode: "preview",
|
||||
@@ -291,7 +312,7 @@ function enterPreview(): void {
|
||||
user: createPreviewUser(),
|
||||
clientToken: "preview-client-token",
|
||||
clientTokenExpiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000,
|
||||
desktopClient: createPreviewClient(),
|
||||
desktopClient: await createPreviewClient(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user