Просмотр исходного кода

fix(card): store form ids as strings

onecold 4 месяцев назад
Родитель
Сommit
b8f559f24d
1 измененных файлов с 12 добавлено и 14 удалено
  1. 12 14
      entry/src/main/ets/common/player/MusicCardFormStore.ets

+ 12 - 14
entry/src/main/ets/common/player/MusicCardFormStore.ets

@@ -35,20 +35,18 @@ const resolvePreferences = (context?: common.Context): Preferences | undefined =
   }
 }
 
-const normalizeFormId = (value: unknown): number | null => {
-  if (typeof value === 'number' && Number.isFinite(value)) {
-    return value
-  }
+const normalizeFormId = (value: unknown): string | null => {
   if (typeof value === 'string') {
-    const parsed = Number(value)
-    if (Number.isFinite(parsed)) {
-      return parsed
-    }
+    const normalized = value.trim()
+    return normalized.length > 0 ? normalized : null
+  }
+  if (typeof value === 'number' && Number.isFinite(value)) {
+    return `${value}`
   }
   return null
 }
 
-const readFormIdsFromPreferences = (preferences: Preferences): number[] => {
+const readFormIdsFromPreferences = (preferences: Preferences): string[] => {
   let raw = ''
   try {
     raw = preferences.getSync(FORM_IDS_KEY, '') as string
@@ -64,7 +62,7 @@ const readFormIdsFromPreferences = (preferences: Preferences): number[] => {
     if (!Array.isArray(parsed)) {
       return []
     }
-    const result: number[] = []
+    const result: string[] = []
     for (let i = 0; i < parsed.length; i++) {
       const normalized = normalizeFormId(parsed[i])
       if (normalized !== null) {
@@ -80,7 +78,7 @@ const readFormIdsFromPreferences = (preferences: Preferences): number[] => {
 
 const writeFormIdsToPreferences = (
   preferences: Preferences,
-  formIds: number[]
+  formIds: string[]
 ): void => {
   const payload = JSON.stringify(formIds ?? [])
   preferences.putSync(FORM_IDS_KEY, payload)
@@ -88,7 +86,7 @@ const writeFormIdsToPreferences = (
 }
 
 export class MusicCardFormStore {
-  static readFormIds(context?: common.Context): number[] {
+  static readFormIds(context?: common.Context): string[] {
     const preferences = resolvePreferences(context)
     if (!preferences) {
       return []
@@ -96,7 +94,7 @@ export class MusicCardFormStore {
     return readFormIdsFromPreferences(preferences)
   }
 
-  static addFormId(context: common.Context | undefined, formId: number): void {
+  static addFormId(context: common.Context | undefined, formId: string): void {
     const preferences = resolvePreferences(context)
     if (!preferences) {
       return
@@ -117,7 +115,7 @@ export class MusicCardFormStore {
     }
   }
 
-  static removeFormId(context: common.Context | undefined, formId: number): void {
+  static removeFormId(context: common.Context | undefined, formId: string): void {
     const preferences = resolvePreferences(context)
     if (!preferences) {
       return