mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 11:44:40 +00:00
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import localforage from 'localforage';
|
|
import { CustomTheme, ThemeList } from '@/interface/types/CustomThemes';
|
|
import { blobToBase64 } from '@/seqta/utils/blobToBase64';
|
|
import { settingsState } from '@/seqta/utils/listeners/SettingsState';
|
|
|
|
export const getAvailableThemes = async (): Promise<ThemeList | {}> => {
|
|
try {
|
|
const themeIds = await localforage.getItem('customThemes') as string[] | null;
|
|
if (themeIds) {
|
|
const themes = await Promise.all(
|
|
themeIds.map(async (id) => {
|
|
const theme = await localforage.getItem(id) as CustomTheme;
|
|
const { CustomImages, ...themeWithoutImages } = theme;
|
|
return {
|
|
...themeWithoutImages,
|
|
coverImage: theme.coverImage ? await blobToBase64(theme.coverImage as Blob) : '',
|
|
};
|
|
})
|
|
);
|
|
|
|
return { themes, selectedTheme: settingsState.selectedTheme ? settingsState.selectedTheme : '' };
|
|
}
|
|
return {
|
|
themes: [],
|
|
selectedTheme: '',
|
|
};
|
|
} catch (error) {
|
|
console.error('Error getting available themes:', error);
|
|
return {
|
|
themes: [],
|
|
selectedTheme: ''
|
|
};
|
|
}
|
|
};
|