mirror of
https://github.com/misskey-dev/misskey.git
synced 2025-04-08 14:36:38 +09:00
34 lines
940 B
TypeScript
34 lines
940 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import type { Theme } from '@/theme.js';
|
|
import { getBuiltinThemes } from '@/theme.js';
|
|
import { $i } from '@/account.js';
|
|
import { prefer } from '@/preferences.js';
|
|
|
|
export function getThemes(): Theme[] {
|
|
if ($i == null) return [];
|
|
return prefer.s.themes;
|
|
}
|
|
|
|
export async function addTheme(theme: Theme): Promise<void> {
|
|
if ($i == null) return;
|
|
const builtinThemes = await getBuiltinThemes();
|
|
if (builtinThemes.some(t => t.id === theme.id)) {
|
|
throw new Error('builtin theme');
|
|
}
|
|
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);
|
|
prefer.commit('themes', themes);
|
|
}
|