1import * as Updates from './Updates'; 2import { UpdateInfoType } from './UseUpdates.types'; 3// The currently running info, constructed from Updates constants 4export const currentlyRunning = { 5 updateId: Updates.updateId ?? undefined, 6 channel: Updates.channel ?? undefined, 7 createdAt: Updates.createdAt ?? undefined, 8 isEmbeddedLaunch: Updates.isEmbeddedLaunch, 9 isEmergencyLaunch: Updates.isEmergencyLaunch, 10 manifest: Updates.manifest ?? undefined, 11 runtimeVersion: Updates.runtimeVersion ?? undefined, 12}; 13// Constructs an UpdateInfo from a manifest 14export const updateFromManifest = (manifest) => { 15 return { 16 type: UpdateInfoType.NEW, 17 updateId: manifest.id ?? '', 18 createdAt: manifest && 'createdAt' in manifest && manifest.createdAt 19 ? new Date(manifest.createdAt) 20 : // We should never reach this if the manifest is valid and has a commit time, 21 // but leave this in so that createdAt is always defined 22 new Date(0), 23 manifest, 24 }; 25}; 26export const updateFromRollback = (rollback) => ({ 27 type: UpdateInfoType.ROLLBACK, 28 createdAt: new Date(rollback.commitTime), 29 manifest: undefined, 30 updateId: undefined, 31}); 32// Default useUpdates() state 33export const defaultUseUpdatesState = { 34 isChecking: false, 35 isDownloading: false, 36 isUpdateAvailable: false, 37 isUpdatePending: false, 38}; 39// Transform the useUpdates() state based on native state machine context 40export const reduceUpdatesStateFromContext = (updatesState, context) => { 41 const availableUpdate = context?.latestManifest 42 ? updateFromManifest(context?.latestManifest) 43 : context.rollback 44 ? updateFromRollback(context.rollback) 45 : undefined; 46 const downloadedUpdate = context?.downloadedManifest 47 ? updateFromManifest(context?.downloadedManifest) 48 : context.rollback 49 ? updateFromRollback(context.rollback) 50 : undefined; 51 return { 52 ...updatesState, 53 isUpdateAvailable: context.isUpdateAvailable, 54 isUpdatePending: context.isUpdatePending, 55 isChecking: context.isChecking, 56 isDownloading: context.isDownloading, 57 availableUpdate, 58 downloadedUpdate, 59 checkError: context.checkError, 60 downloadError: context.downloadError, 61 lastCheckForUpdateTimeSinceRestart: context.lastCheckForUpdateTime, 62 }; 63}; 64//# sourceMappingURL=UseUpdatesUtils.js.map