2020-11-25 14:31:34 +02:00
|
|
|
<template>
|
2022-01-02 14:35:23 +02:00
|
|
|
<div class="_formRoot">
|
|
|
|
<FormTextarea v-model="installThemeCode" class="_formBlock">
|
|
|
|
<template #label>{{ $ts._theme.code }}</template>
|
|
|
|
</FormTextarea>
|
2020-11-25 14:31:34 +02:00
|
|
|
|
2022-01-02 14:35:23 +02:00
|
|
|
<div class="_formBlock" style="display: flex; gap: var(--margin); flex-wrap: wrap;">
|
|
|
|
<FormButton :disabled="installThemeCode == null" inline @click="() => preview(installThemeCode)"><i class="fas fa-eye"></i> {{ $ts.preview }}</FormButton>
|
|
|
|
<FormButton :disabled="installThemeCode == null" primary inline @click="() => install(installThemeCode)"><i class="fas fa-check"></i> {{ $ts.install }}</FormButton>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-11-25 14:31:34 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent } from 'vue';
|
|
|
|
import * as JSON5 from 'json5';
|
2021-11-11 19:02:25 +02:00
|
|
|
import FormTextarea from '@/components/form/textarea.vue';
|
2022-01-02 14:35:23 +02:00
|
|
|
import FormButton from '@/components/ui/button.vue';
|
2021-11-11 19:02:25 +02:00
|
|
|
import { applyTheme, validateTheme } from '@/scripts/theme';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import { addTheme, getThemes } from '@/theme-store';
|
|
|
|
import * as symbols from '@/symbols';
|
2020-11-25 14:31:34 +02:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
|
|
|
FormTextarea,
|
|
|
|
FormButton,
|
|
|
|
},
|
|
|
|
|
|
|
|
emits: ['info'],
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-04-10 06:54:12 +03:00
|
|
|
[symbols.PAGE_INFO]: {
|
2020-12-26 03:47:36 +02:00
|
|
|
title: this.$ts._theme.install,
|
2021-09-29 18:50:45 +03:00
|
|
|
icon: 'fas fa-download',
|
|
|
|
bg: 'var(--bg)',
|
2020-11-25 14:31:34 +02:00
|
|
|
},
|
|
|
|
installThemeCode: null,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
parseThemeCode(code) {
|
|
|
|
let theme;
|
|
|
|
|
|
|
|
try {
|
|
|
|
theme = JSON5.parse(code);
|
|
|
|
} catch (e) {
|
2021-11-18 11:45:58 +02:00
|
|
|
os.alert({
|
2020-11-25 14:31:34 +02:00
|
|
|
type: 'error',
|
2020-12-26 03:47:36 +02:00
|
|
|
text: this.$ts._theme.invalid
|
2020-11-25 14:31:34 +02:00
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!validateTheme(theme)) {
|
2021-11-18 11:45:58 +02:00
|
|
|
os.alert({
|
2020-11-25 14:31:34 +02:00
|
|
|
type: 'error',
|
2020-12-26 03:47:36 +02:00
|
|
|
text: this.$ts._theme.invalid
|
2020-11-25 14:31:34 +02:00
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
2021-01-11 15:31:17 +02:00
|
|
|
if (getThemes().some(t => t.id === theme.id)) {
|
2021-11-18 11:45:58 +02:00
|
|
|
os.alert({
|
2020-11-25 14:31:34 +02:00
|
|
|
type: 'info',
|
2020-12-26 03:47:36 +02:00
|
|
|
text: this.$ts._theme.alreadyInstalled
|
2020-11-25 14:31:34 +02:00
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return theme;
|
|
|
|
},
|
|
|
|
|
|
|
|
preview(code) {
|
|
|
|
const theme = this.parseThemeCode(code);
|
|
|
|
if (theme) applyTheme(theme, false);
|
|
|
|
},
|
|
|
|
|
2021-01-11 15:31:17 +02:00
|
|
|
async install(code) {
|
2020-11-25 14:31:34 +02:00
|
|
|
const theme = this.parseThemeCode(code);
|
|
|
|
if (!theme) return;
|
2021-01-11 15:31:17 +02:00
|
|
|
await addTheme(theme);
|
2021-11-18 11:45:58 +02:00
|
|
|
os.alert({
|
2020-11-25 14:31:34 +02:00
|
|
|
type: 'success',
|
|
|
|
text: this.$t('_theme.installed', { name: theme.name })
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|