import type { Build, IntrospectBreakpointStatus, IntrospectShellStatus, } from '../desktopify'; export type IntrospectPlatformName = 'linux' | 'mac' | 'windows'; const PLATFORM_LABELS: Record = { linux: 'Linux', mac: 'Mac', windows: 'Windows', }; /** * Check if a build was introspected (has connectedAt or disconnectedAt on any platform). * Builds that were introspected cannot be released. */ export function wasIntrospected(build: Build): boolean { const { introspect } = build; if (!introspect) return false; const platforms: IntrospectPlatformName[] = ['mac', 'windows', 'linux']; for (const platform of platforms) { const data = introspect[platform]; if (data?.connectedAt || data?.disconnectedAt) { return true; } } return false; } /** * Get list of platform names that were introspected (have connectedAt or disconnectedAt). * Returns capitalized platform names (e.g., ['Mac', 'Windows']). */ export function getIntrospectedPlatformNames(build: Build): string[] { const { introspect } = build; if (!introspect) return []; const platforms: IntrospectPlatformName[] = ['mac', 'windows', 'linux']; const result: string[] = []; for (const platform of platforms) { const data = introspect[platform]; if (data?.connectedAt || data?.disconnectedAt) { result.push(PLATFORM_LABELS[platform]); } } return result; } /** * Format introspection status as a human-readable string. * Combines breakpoint status and shell status into a single label. */ export function formatIntrospectionStatus( breakpointStatus?: IntrospectBreakpointStatus, shellStatus?: IntrospectShellStatus, ): string { if (breakpointStatus === 'paused') { if (shellStatus === 'connected') { return 'paused (shell connected)'; } if (shellStatus === 'disconnected') { return 'paused (shell disconnected)'; } return 'paused'; } if (breakpointStatus === 'ready') { if (shellStatus === 'connected') { return 'ready (shell connected)'; } if (shellStatus === 'disconnected') { return 'ready (shell disconnected)'; } return 'ready'; } if (breakpointStatus === 'resuming') { return 'resuming'; } if (breakpointStatus === 'initializing') { return 'initializing'; } if (breakpointStatus === 'finished') { return 'finished'; } if (breakpointStatus === 'error' || shellStatus === 'error') { return 'error'; } return 'status unknown'; }