From 1e7e00e8ddd2e491e6ba7d8b8f31121f15f66d31 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Mon, 30 Dec 2024 14:30:54 +0100 Subject: [PATCH] fix(ignore): Improvements for #25299 (#25364) --- lib/util/settingsMigration.ts | 14 +++++++++----- lib/util/utils.ts | 12 +++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/util/settingsMigration.ts b/lib/util/settingsMigration.ts index 6663cd0e3..51dff5a11 100644 --- a/lib/util/settingsMigration.ts +++ b/lib/util/settingsMigration.ts @@ -459,15 +459,19 @@ function migrateToFour( const saveBase64DeviceIconsAsImage = (currentSettings: Partial): ReturnType => { const [validPath, previousValue] = getValue(currentSettings, ['devices']); + let changed = false; - for (const deviceKey in currentSettings.devices) { - const base64Match = utils.matchBase64File(currentSettings.devices[deviceKey].icon ?? ''); - if (base64Match) { - currentSettings.devices[deviceKey].icon = utils.saveBase64DeviceIcon(base64Match); + if (validPath) { + for (const deviceKey in currentSettings.devices) { + const base64Match = utils.matchBase64File(currentSettings.devices[deviceKey].icon); + if (base64Match) { + changed = true; + currentSettings.devices[deviceKey].icon = utils.saveBase64DeviceIcon(base64Match); + } } } - return [validPath, previousValue, validPath]; + return [validPath, previousValue, changed]; }; customHandlers.push({ diff --git a/lib/util/utils.ts b/lib/util/utils.ts index 6b3a6c91c..f3a1666ca 100644 --- a/lib/util/utils.ts +++ b/lib/util/utils.ts @@ -375,11 +375,13 @@ function deviceNotCoordinator(device: zh.Device): boolean { return device.type !== 'Coordinator'; } -function matchBase64File(value: string): {extension: string; data: string} | false { - const match = value.match(BASE64_IMAGE_REGEX); - if (match) { - assert(match.groups?.extension && match.groups?.data); - return {extension: match.groups.extension, data: match.groups.data}; +function matchBase64File(value: string | undefined): {extension: string; data: string} | false { + if (value !== undefined) { + const match = value.match(BASE64_IMAGE_REGEX); + if (match) { + assert(match.groups?.extension && match.groups?.data); + return {extension: match.groups.extension, data: match.groups.data}; + } } return false; }