import type { NativeAppState, NativeUpdates } from '@/types/native-app'; export function isNativeAppState(value: unknown): value is NativeAppState { if (!value || typeof value !== 'object') { return false; } const state = value as NativeAppState; if ( state.apiVersion !== 1 || !['macos', 'ios'].includes(state.platform) || typeof state.version !== 'string' || typeof state.workspace !== 'string' || !Array.isArray(state.capabilities) || !state.capabilities.includes('workspace') ) { return false; } try { if (new URL(state.workspace).protocol !== 'https:') { return false; } } catch { return false; } if (!state.capabilities.includes('updates')) { return state.updates === undefined; } if (state.platform !== 'macos' || !state.updates) { return false; } const updates = state.updates; return ( [ 'idle', 'checking', 'available', 'current', 'downloading', 'verifying', 'installing', 'restarting', 'error', ].includes(updates.phase) && typeof updates.currentVersion === 'string' && typeof updates.build === 'string' && (updates.version === null || typeof updates.version === 'string') && (updates.notes === null || typeof updates.notes === 'string') && (updates.error === null || typeof updates.error === 'string') && Number.isFinite(updates.downloaded) && updates.downloaded >= 0 && (updates.total === null || (Number.isFinite(updates.total) && updates.total >= 0)) && typeof updates.preferences?.automatic === 'boolean' && [1, 6, 24].includes(updates.preferences.intervalHours) ); } export function updateIsBusy(updates?: NativeUpdates): boolean { return ( !!updates && [ 'checking', 'downloading', 'verifying', 'installing', 'restarting', ].includes(updates.phase) ); }