diff --git a/src/device-state.ts b/src/device-state.ts index 33ac3960..09c2d535 100644 --- a/src/device-state.ts +++ b/src/device-state.ts @@ -415,15 +415,16 @@ export async function loadInitialState() { update_downloaded: false, }); + let loadedFromFile = false; if (!conf.provisioned || !conf.targetStateSet) { - await loadTargetFromFile(constants.appsJsonPath); + loadedFromFile = await loadTargetFromFile(constants.appsJsonPath); } else { log.debug('Skipping preloading'); } - // Only trigger initial target if we have received a target - // from the cloud at some point - if (conf.targetStateSet) { + // Only apply target if we have received a target + // from the cloud or loaded from file + if (conf.targetStateSet || loadedFromFile) { triggerApplyTarget({ initial: true }); } } diff --git a/src/device-state/preload.ts b/src/device-state/preload.ts index f87eb870..cd82dec1 100644 --- a/src/device-state/preload.ts +++ b/src/device-state/preload.ts @@ -19,7 +19,7 @@ export function appsJsonBackup(appsPath: string) { return `${appsPath}.preloaded`; } -export async function loadTargetFromFile(appsPath: string): Promise { +export async function loadTargetFromFile(appsPath: string): Promise { log.info('Attempting to load any preloaded applications'); try { const content = await fs.readFile(appsPath, 'utf8'); @@ -43,7 +43,7 @@ export async function loadTargetFromFile(appsPath: string): Promise { let appToPin: string | undefined; if (_.isEmpty(preloadState)) { - return; + return false; } const imgs: Image[] = []; @@ -100,6 +100,7 @@ export async function loadTargetFromFile(appsPath: string): Promise { }); } } + return true; } catch (e) { // Ensure that this is actually a file, and not an empty path // It can be an empty path because if the file does not exist @@ -131,4 +132,5 @@ export async function loadTargetFromFile(appsPath: string): Promise { ); } } + return false; }