2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-11-25 13:31:34 +01:00
|
|
|
<template>
|
2023-01-06 05:40:17 +01:00
|
|
|
<div class="_gaps_m">
|
2023-01-07 07:09:46 +01:00
|
|
|
<MkTextarea v-model="installThemeCode">
|
2022-01-28 03:39:49 +01:00
|
|
|
<template #label>{{ i18n.ts._theme.code }}</template>
|
2023-01-07 07:09:46 +01:00
|
|
|
</MkTextarea>
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2023-01-06 01:41:14 +01:00
|
|
|
<div class="_buttons">
|
|
|
|
<MkButton :disabled="installThemeCode == null" inline @click="() => preview(installThemeCode)"><i class="ti ti-eye"></i> {{ i18n.ts.preview }}</MkButton>
|
|
|
|
<MkButton :disabled="installThemeCode == null" primary inline @click="() => install(installThemeCode)"><i class="ti ti-check"></i> {{ i18n.ts.install }}</MkButton>
|
2022-01-02 13:35:23 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-11-25 13:31:34 +01:00
|
|
|
</template>
|
|
|
|
|
2022-01-15 09:58:35 +01:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { } from 'vue';
|
2022-05-01 15:51:07 +02:00
|
|
|
import JSON5 from 'json5';
|
2023-01-07 07:09:46 +01:00
|
|
|
import MkTextarea from '@/components/MkTextarea.vue';
|
2023-01-06 01:41:14 +01:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { applyTheme, validateTheme } from '@/scripts/theme.js';
|
|
|
|
import * as os from '@/os.js';
|
2021-11-11 18:02:25 +01:00
|
|
|
import { addTheme, getThemes } from '@/theme-store';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata.js';
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2022-01-15 09:58:35 +01:00
|
|
|
let installThemeCode = $ref(null);
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2022-01-15 09:58:35 +01:00
|
|
|
function parseThemeCode(code: string) {
|
|
|
|
let theme;
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2022-01-15 09:58:35 +01:00
|
|
|
try {
|
|
|
|
theme = JSON5.parse(code);
|
2022-05-26 15:53:09 +02:00
|
|
|
} catch (err) {
|
2022-01-15 09:58:35 +01:00
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
2022-06-20 10:38:49 +02:00
|
|
|
text: i18n.ts._theme.invalid,
|
2022-01-15 09:58:35 +01:00
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!validateTheme(theme)) {
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
2022-06-20 10:38:49 +02:00
|
|
|
text: i18n.ts._theme.invalid,
|
2022-01-15 09:58:35 +01:00
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (getThemes().some(t => t.id === theme.id)) {
|
|
|
|
os.alert({
|
|
|
|
type: 'info',
|
2022-06-20 10:38:49 +02:00
|
|
|
text: i18n.ts._theme.alreadyInstalled,
|
2022-01-15 09:58:35 +01:00
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2022-01-15 09:58:35 +01:00
|
|
|
return theme;
|
|
|
|
}
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2022-01-15 09:58:35 +01:00
|
|
|
function preview(code: string): void {
|
|
|
|
const theme = parseThemeCode(code);
|
|
|
|
if (theme) applyTheme(theme, false);
|
|
|
|
}
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2022-01-15 09:58:35 +01:00
|
|
|
async function install(code: string): Promise<void> {
|
|
|
|
const theme = parseThemeCode(code);
|
|
|
|
if (!theme) return;
|
|
|
|
await addTheme(theme);
|
|
|
|
os.alert({
|
|
|
|
type: 'success',
|
2022-06-20 10:38:49 +02:00
|
|
|
text: i18n.t('_theme.installed', { name: theme.name }),
|
2022-01-15 09:58:35 +01:00
|
|
|
});
|
|
|
|
}
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts._theme.install,
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-download',
|
2020-11-25 13:31:34 +01:00
|
|
|
});
|
|
|
|
</script>
|