mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
feat(settings): add custom theme selector
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { CustomThemeBase64 } from '@/old-interface/types/CustomThemes';
|
||||
import type { CustomThemeBase64 } from '@/types/CustomThemes';
|
||||
import { applyCustomCSS, imageData, removeImageFromDocument, UpdateImageData } from './Themes';
|
||||
import { settingsState } from '@/seqta/utils/listeners/SettingsState';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { CustomImage, CustomTheme } from '@/old-interface/types/CustomThemes';
|
||||
import type { CustomImage, CustomTheme } from '@/types/CustomThemes';
|
||||
import { settingsState } from '@/seqta/utils/listeners/SettingsState';
|
||||
import { applyCustomCSS } from './Themes';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import localforage from 'localforage';
|
||||
import type { CustomTheme } from '@/old-interface/types/CustomThemes';
|
||||
import type { CustomTheme } from '@/types/CustomThemes';
|
||||
import { removeTheme } from './removeTheme';
|
||||
import { settingsState } from '@/seqta/utils/listeners/SettingsState';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import localforage from 'localforage';
|
||||
import type { CustomTheme } from '@/old-interface/types/CustomThemes';
|
||||
import type { CustomTheme } from '@/types/CustomThemes';
|
||||
import { removeTheme } from './removeTheme';
|
||||
import { Mutex } from '@/seqta/utils/mutex';
|
||||
import { settingsState } from '@/seqta/utils/listeners/SettingsState';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import localforage from 'localforage';
|
||||
import type { CustomTheme } from '@/old-interface/types/CustomThemes';
|
||||
import type { CustomTheme } from '@/types/CustomThemes';
|
||||
import { applyTheme } from './applyTheme';
|
||||
import { settingsState } from '@/seqta/utils/listeners/SettingsState';
|
||||
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
import localforage from 'localforage';
|
||||
import type { CustomTheme, ThemeList } from '@/old-interface/types/CustomThemes';
|
||||
import { blobToBase64 } from '@/seqta/utils/blobToBase64';
|
||||
import type { CustomTheme, ThemeList } from '@/types/CustomThemes';
|
||||
import { settingsState } from '@/seqta/utils/listeners/SettingsState';
|
||||
|
||||
export const getAvailableThemes = async (): Promise<ThemeList | {}> => {
|
||||
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 theme;
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -1,28 +1,12 @@
|
||||
import localforage from 'localforage';
|
||||
import type { CustomImageBase64, CustomTheme, CustomThemeBase64 } from '@/old-interface/types/CustomThemes';
|
||||
import { blobToBase64 } from '@/seqta/utils/blobToBase64';
|
||||
import type { CustomTheme } from '@/types/CustomThemes';
|
||||
|
||||
|
||||
export const getTheme = async (themeId: string): Promise<CustomThemeBase64 | null> => {
|
||||
export const getTheme = async (themeId: string): Promise<CustomTheme | null> => {
|
||||
try {
|
||||
const theme = await localforage.getItem(themeId) as CustomTheme;
|
||||
|
||||
const CustomImages: CustomImageBase64[] = await Promise.all(
|
||||
theme.CustomImages.map(async (image) => {
|
||||
const base64 = await blobToBase64(image.blob);
|
||||
return {
|
||||
id: image.id,
|
||||
variableName: image.variableName,
|
||||
url: base64,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
return {
|
||||
...theme,
|
||||
coverImage: theme.coverImage ? await blobToBase64(theme.coverImage as Blob) : null,
|
||||
CustomImages,
|
||||
};
|
||||
return theme;
|
||||
} catch (error) {
|
||||
console.error('Error getting theme:', error);
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import localforage from 'localforage';
|
||||
import type { CustomTheme } from '@/old-interface/types/CustomThemes';
|
||||
import type { CustomTheme } from '@/types/CustomThemes';
|
||||
import { settingsState } from '@/seqta/utils/listeners/SettingsState';
|
||||
|
||||
export const removeTheme = async (theme: CustomTheme) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import localforage from 'localforage';
|
||||
import type { CustomTheme, CustomThemeBase64 } from '@/old-interface/types/CustomThemes';
|
||||
import type { CustomTheme, CustomThemeBase64 } from '@/types/CustomThemes';
|
||||
import { disableTheme } from './disableTheme';
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import localforage from 'localforage';
|
||||
import type { CustomTheme } from '@/old-interface/types/CustomThemes';
|
||||
import type { CustomTheme } from '@/types/CustomThemes';
|
||||
import { applyTheme } from './applyTheme';
|
||||
import { removeTheme } from './removeTheme';
|
||||
import { settingsState } from '@/seqta/utils/listeners/SettingsState';
|
||||
|
||||
Reference in New Issue
Block a user