Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions StreamAwesome/src/logic/persistence/PersistenceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export class PersistenceHandler {
return null
}

if (record.version !== streamAwesomeVersion) {
console.error('Incompatible version found in persistent icon.')
if (!PersistenceHandler.isCompatibleVersion(record.version)) {
console.error(`Incompatible version found in persistent icon: ${record.version} (current: ${streamAwesomeVersion}).`)

return null
}
Expand All @@ -29,6 +29,21 @@ export class PersistenceHandler {
) as CustomIcon<FontAwesomePreset> | null
}

// major versions are compatible
private static isCompatibleVersion(version: string): boolean {
if (!/^\d+\.\d+\.\d+$/.test(version)) {
return false
}

// dev environment
const currentMajor = streamAwesomeVersion.split('.')[0]
if (currentMajor === '0') {
return true
}

return version.split('.')[0] === currentMajor
}

public static convertIconToPersistentIcon(icon: CustomIcon<FontAwesomePreset>): PersistentIcon {
const flattenedIcon = PersistenceHandler.flattenObject(
icon as unknown as Record<string, unknown>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class PersistentIconConverter {
isBrandsIcon: this.extractBoolean(record, 'fontawesomeicon.isbrandsicon'),
style: this.extractString(record, 'fontawesomeicon.style'),
family: this.extractString(record, 'fontawesomeicon.family'),
duotoneAlpha: this.extractNumber(record, 'fontawesomeicon.duotonealpha')
duotoneAlpha: this.extractOptionalNumber(record, 'fontawesomeicon.duotonealpha', 0.5)
}
}

Expand Down Expand Up @@ -74,6 +74,13 @@ export class PersistentIconConverter {
return parsedNumber
}

private extractOptionalNumber(record: Record<string, unknown>, key: string, fallback: number): number {
if (record[key] === undefined || record[key] === null) {
return fallback
}
return this.extractNumber(record, key)
}

private extractString(record: Record<string, unknown>, key: string): string {
const value = record[key]
if (value === undefined || value === null || Array.isArray(value)) {
Expand Down
Loading