2023-07-27 05:31:52 +00:00
|
|
|
<!--
|
2024-02-13 15:59:27 +00:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 05:31:52 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-11-25 12:31:34 +00:00
|
|
|
<template>
|
2023-01-06 04:40:17 +00:00
|
|
|
<div class="_gaps_m">
|
2023-12-16 04:18:12 +00:00
|
|
|
<MkCodeEditor v-model="installThemeCode" lang="json5">
|
2022-01-28 02:39:49 +00:00
|
|
|
<template #label>{{ i18n.ts._theme.code }}</template>
|
2023-12-16 04:18:12 +00:00
|
|
|
</MkCodeEditor>
|
2020-11-25 12:31:34 +00:00
|
|
|
|
2023-01-06 00:41:14 +00:00
|
|
|
<div class="_buttons">
|
2023-10-31 18:33:24 +00:00
|
|
|
<MkButton :disabled="installThemeCode == null" inline @click="() => previewTheme(installThemeCode)"><i class="ph-eye ph-bold ph-lg"></i> {{ i18n.ts.preview }}</MkButton>
|
2023-09-30 19:53:52 +00:00
|
|
|
<MkButton :disabled="installThemeCode == null" primary inline @click="() => install(installThemeCode)"><i class="ph-check ph-bold ph-lg"></i> {{ i18n.ts.install }}</MkButton>
|
2022-01-02 12:35:23 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-11-25 12:31:34 +00:00
|
|
|
</template>
|
|
|
|
|
2022-01-15 08:58:35 +00:00
|
|
|
<script lang="ts" setup>
|
2023-12-07 05:42:09 +00:00
|
|
|
import { ref, computed } from 'vue';
|
2023-12-16 04:18:12 +00:00
|
|
|
import MkCodeEditor from '@/components/MkCodeEditor.vue';
|
2023-01-06 00:41:14 +00:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-10-21 09:41:12 +00:00
|
|
|
import { parseThemeCode, previewTheme, installTheme } from '@/scripts/install-theme.js';
|
2023-09-19 07:37:43 +00:00
|
|
|
import * as os from '@/os.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata.js';
|
2020-11-25 12:31:34 +00:00
|
|
|
|
2023-12-26 05:19:35 +00:00
|
|
|
const installThemeCode = ref<string | null>(null);
|
2020-11-25 12:31:34 +00:00
|
|
|
|
2023-10-21 09:41:12 +00:00
|
|
|
async function install(code: string): Promise<void> {
|
2022-01-15 08:58:35 +00:00
|
|
|
try {
|
2023-10-21 09:41:12 +00:00
|
|
|
const theme = parseThemeCode(code);
|
|
|
|
await installTheme(code);
|
2022-01-15 08:58:35 +00:00
|
|
|
os.alert({
|
2023-10-21 09:41:12 +00:00
|
|
|
type: 'success',
|
2024-01-19 23:11:59 +00:00
|
|
|
text: i18n.tsx._theme.installed({ name: theme.name }),
|
2022-01-15 08:58:35 +00:00
|
|
|
});
|
2023-10-21 09:41:12 +00:00
|
|
|
} catch (err) {
|
|
|
|
switch (err.message.toLowerCase()) {
|
|
|
|
case 'this theme is already installed':
|
|
|
|
os.alert({
|
|
|
|
type: 'info',
|
|
|
|
text: i18n.ts._theme.alreadyInstalled,
|
|
|
|
});
|
|
|
|
break;
|
2020-11-25 12:31:34 +00:00
|
|
|
|
2023-10-21 09:41:12 +00:00
|
|
|
default:
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
|
|
|
text: i18n.ts._theme.invalid,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
console.error(err);
|
|
|
|
}
|
2022-01-15 08:58:35 +00:00
|
|
|
}
|
2020-11-25 12:31:34 +00:00
|
|
|
|
2023-12-07 05:42:09 +00:00
|
|
|
const headerActions = computed(() => []);
|
2022-06-20 08:38:49 +00:00
|
|
|
|
2023-12-07 05:42:09 +00:00
|
|
|
const headerTabs = computed(() => []);
|
2022-06-20 08:38:49 +00:00
|
|
|
|
2024-02-16 07:17:09 +00:00
|
|
|
definePageMetadata(() => ({
|
2022-06-20 08:38:49 +00:00
|
|
|
title: i18n.ts._theme.install,
|
2023-09-30 19:53:52 +00:00
|
|
|
icon: 'ph-download ph-bold ph-lg',
|
2024-02-16 07:17:09 +00:00
|
|
|
}));
|
2020-11-25 12:31:34 +00:00
|
|
|
</script>
|