summaryrefslogtreecommitdiff
path: root/packages/frontend/src/theme-store.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/frontend/src/theme-store.ts')
-rw-r--r--packages/frontend/src/theme-store.ts36
1 files changed, 11 insertions, 25 deletions
diff --git a/packages/frontend/src/theme-store.ts b/packages/frontend/src/theme-store.ts
index c41cc17652..2ae5d8730e 100644
--- a/packages/frontend/src/theme-store.ts
+++ b/packages/frontend/src/theme-store.ts
@@ -3,28 +3,14 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
-import { Theme, getBuiltinThemes } from '@/scripts/theme.js';
-import { miLocalStorage } from '@/local-storage.js';
-import { misskeyApi } from '@/scripts/misskey-api.js';
-import { $i } from '@/account.js';
-
-const lsCacheKey = $i ? `themes:${$i.id}` as const : null;
+import type { Theme } from '@/theme.js';
+import { getBuiltinThemes } from '@/theme.js';
+import { $i } from '@/i.js';
+import { prefer } from '@/preferences.js';
export function getThemes(): Theme[] {
if ($i == null) return [];
- return JSON.parse(miLocalStorage.getItem(lsCacheKey!) ?? '[]');
-}
-
-export async function fetchThemes(): Promise<void> {
- if ($i == null) return;
-
- try {
- const themes = await misskeyApi('i/registry/get', { scope: ['client'], key: 'themes' });
- miLocalStorage.setItem(lsCacheKey!, JSON.stringify(themes));
- } catch (err) {
- if (err.code === 'NO_SUCH_KEY') return;
- throw err;
- }
+ return prefer.s.themes;
}
export async function addTheme(theme: Theme): Promise<void> {
@@ -33,15 +19,15 @@ export async function addTheme(theme: Theme): Promise<void> {
if (builtinThemes.some(t => t.id === theme.id)) {
throw new Error('builtin theme');
}
- await fetchThemes();
- const themes = getThemes().concat(theme);
- await misskeyApi('i/registry/set', { scope: ['client'], key: 'themes', value: themes });
- miLocalStorage.setItem(lsCacheKey!, JSON.stringify(themes));
+ const themes = getThemes();
+ if (themes.some(t => t.id === theme.id)) {
+ throw new Error('already exists');
+ }
+ prefer.commit('themes', [...themes, theme]);
}
export async function removeTheme(theme: Theme): Promise<void> {
if ($i == null) return;
const themes = getThemes().filter(t => t.id !== theme.id);
- await misskeyApi('i/registry/set', { scope: ['client'], key: 'themes', value: themes });
- miLocalStorage.setItem(lsCacheKey!, JSON.stringify(themes));
+ prefer.commit('themes', themes);
}