2020-11-25 21:31:34 +09:00
|
|
|
<template>
|
|
|
|
<FormBase>
|
|
|
|
<FormGroup>
|
2021-09-30 00:50:45 +09:00
|
|
|
<FormTextarea v-model="installThemeCode">
|
2020-12-26 10:47:36 +09:00
|
|
|
<span>{{ $ts._theme.code }}</span>
|
2020-11-25 21:31:34 +09:00
|
|
|
</FormTextarea>
|
2021-04-20 23:22:59 +09:00
|
|
|
<FormButton @click="() => preview(installThemeCode)" :disabled="installThemeCode == null" inline><i class="fas fa-eye"></i> {{ $ts.preview }}</FormButton>
|
2020-11-25 21:31:34 +09:00
|
|
|
</FormGroup>
|
|
|
|
|
2021-04-20 23:22:59 +09:00
|
|
|
<FormButton @click="() => install(installThemeCode)" :disabled="installThemeCode == null" primary inline><i class="fas fa-check"></i> {{ $ts.install }}</FormButton>
|
2020-11-25 21:31:34 +09:00
|
|
|
</FormBase>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent } from 'vue';
|
|
|
|
import * as JSON5 from 'json5';
|
2021-11-12 02:02:25 +09:00
|
|
|
import FormTextarea from '@/components/form/textarea.vue';
|
|
|
|
import FormSelect from '@/components/form/select.vue';
|
|
|
|
import FormRadios from '@/components/form/radios.vue';
|
|
|
|
import FormBase from '@/components/debobigego/base.vue';
|
|
|
|
import FormGroup from '@/components/debobigego/group.vue';
|
|
|
|
import FormLink from '@/components/debobigego/link.vue';
|
|
|
|
import FormButton from '@/components/debobigego/button.vue';
|
|
|
|
import { applyTheme, validateTheme } from '@/scripts/theme';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import { ColdDeviceStorage } from '@/store';
|
|
|
|
import { addTheme, getThemes } from '@/theme-store';
|
|
|
|
import * as symbols from '@/symbols';
|
2020-11-25 21:31:34 +09:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
|
|
|
FormTextarea,
|
|
|
|
FormSelect,
|
|
|
|
FormRadios,
|
|
|
|
FormBase,
|
|
|
|
FormGroup,
|
|
|
|
FormLink,
|
|
|
|
FormButton,
|
|
|
|
},
|
|
|
|
|
|
|
|
emits: ['info'],
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-04-10 12:54:12 +09:00
|
|
|
[symbols.PAGE_INFO]: {
|
2020-12-26 10:47:36 +09:00
|
|
|
title: this.$ts._theme.install,
|
2021-09-30 00:50:45 +09:00
|
|
|
icon: 'fas fa-download',
|
|
|
|
bg: 'var(--bg)',
|
2020-11-25 21:31:34 +09:00
|
|
|
},
|
|
|
|
installThemeCode: null,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
2021-04-10 12:54:12 +09:00
|
|
|
this.$emit('info', this[symbols.PAGE_INFO]);
|
2020-11-25 21:31:34 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
parseThemeCode(code) {
|
|
|
|
let theme;
|
|
|
|
|
|
|
|
try {
|
|
|
|
theme = JSON5.parse(code);
|
|
|
|
} catch (e) {
|
2021-11-18 18:45:58 +09:00
|
|
|
os.alert({
|
2020-11-25 21:31:34 +09:00
|
|
|
type: 'error',
|
2020-12-26 10:47:36 +09:00
|
|
|
text: this.$ts._theme.invalid
|
2020-11-25 21:31:34 +09:00
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!validateTheme(theme)) {
|
2021-11-18 18:45:58 +09:00
|
|
|
os.alert({
|
2020-11-25 21:31:34 +09:00
|
|
|
type: 'error',
|
2020-12-26 10:47:36 +09:00
|
|
|
text: this.$ts._theme.invalid
|
2020-11-25 21:31:34 +09:00
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
2021-01-11 22:31:17 +09:00
|
|
|
if (getThemes().some(t => t.id === theme.id)) {
|
2021-11-18 18:45:58 +09:00
|
|
|
os.alert({
|
2020-11-25 21:31:34 +09:00
|
|
|
type: 'info',
|
2020-12-26 10:47:36 +09:00
|
|
|
text: this.$ts._theme.alreadyInstalled
|
2020-11-25 21:31:34 +09:00
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return theme;
|
|
|
|
},
|
|
|
|
|
|
|
|
preview(code) {
|
|
|
|
const theme = this.parseThemeCode(code);
|
|
|
|
if (theme) applyTheme(theme, false);
|
|
|
|
},
|
|
|
|
|
2021-01-11 22:31:17 +09:00
|
|
|
async install(code) {
|
2020-11-25 21:31:34 +09:00
|
|
|
const theme = this.parseThemeCode(code);
|
|
|
|
if (!theme) return;
|
2021-01-11 22:31:17 +09:00
|
|
|
await addTheme(theme);
|
2021-11-18 18:45:58 +09:00
|
|
|
os.alert({
|
2020-11-25 21:31:34 +09:00
|
|
|
type: 'success',
|
|
|
|
text: this.$t('_theme.installed', { name: theme.name })
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|