|
@@ -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') {
|
|
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
|
|
return null
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const readFormIdsFromPreferences = (preferences: Preferences): number[] => {
|
|
|
|
|
|
|
+const readFormIdsFromPreferences = (preferences: Preferences): string[] => {
|
|
|
let raw = ''
|
|
let raw = ''
|
|
|
try {
|
|
try {
|
|
|
raw = preferences.getSync(FORM_IDS_KEY, '') as string
|
|
raw = preferences.getSync(FORM_IDS_KEY, '') as string
|
|
@@ -64,7 +62,7 @@ const readFormIdsFromPreferences = (preferences: Preferences): number[] => {
|
|
|
if (!Array.isArray(parsed)) {
|
|
if (!Array.isArray(parsed)) {
|
|
|
return []
|
|
return []
|
|
|
}
|
|
}
|
|
|
- const result: number[] = []
|
|
|
|
|
|
|
+ const result: string[] = []
|
|
|
for (let i = 0; i < parsed.length; i++) {
|
|
for (let i = 0; i < parsed.length; i++) {
|
|
|
const normalized = normalizeFormId(parsed[i])
|
|
const normalized = normalizeFormId(parsed[i])
|
|
|
if (normalized !== null) {
|
|
if (normalized !== null) {
|
|
@@ -80,7 +78,7 @@ const readFormIdsFromPreferences = (preferences: Preferences): number[] => {
|
|
|
|
|
|
|
|
const writeFormIdsToPreferences = (
|
|
const writeFormIdsToPreferences = (
|
|
|
preferences: Preferences,
|
|
preferences: Preferences,
|
|
|
- formIds: number[]
|
|
|
|
|
|
|
+ formIds: string[]
|
|
|
): void => {
|
|
): void => {
|
|
|
const payload = JSON.stringify(formIds ?? [])
|
|
const payload = JSON.stringify(formIds ?? [])
|
|
|
preferences.putSync(FORM_IDS_KEY, payload)
|
|
preferences.putSync(FORM_IDS_KEY, payload)
|
|
@@ -88,7 +86,7 @@ const writeFormIdsToPreferences = (
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export class MusicCardFormStore {
|
|
export class MusicCardFormStore {
|
|
|
- static readFormIds(context?: common.Context): number[] {
|
|
|
|
|
|
|
+ static readFormIds(context?: common.Context): string[] {
|
|
|
const preferences = resolvePreferences(context)
|
|
const preferences = resolvePreferences(context)
|
|
|
if (!preferences) {
|
|
if (!preferences) {
|
|
|
return []
|
|
return []
|
|
@@ -96,7 +94,7 @@ export class MusicCardFormStore {
|
|
|
return readFormIdsFromPreferences(preferences)
|
|
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)
|
|
const preferences = resolvePreferences(context)
|
|
|
if (!preferences) {
|
|
if (!preferences) {
|
|
|
return
|
|
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)
|
|
const preferences = resolvePreferences(context)
|
|
|
if (!preferences) {
|
|
if (!preferences) {
|
|
|
return
|
|
return
|