2020-11-25 06:31:34 -06:00
|
|
|
<template>
|
|
|
|
<FormBase>
|
|
|
|
<FormGroup>
|
|
|
|
<FormTextarea v-model:value="installThemeCode">
|
2020-12-25 19:47:36 -06:00
|
|
|
<span>{{ $ts._theme.code }}</span>
|
2020-11-25 06:31:34 -06:00
|
|
|
</FormTextarea>
|
2020-12-25 19:47:36 -06:00
|
|
|
<FormButton @click="() => preview(installThemeCode)" :disabled="installThemeCode == null" inline><Fa :icon="faEye"/> {{ $ts.preview }}</FormButton>
|
2020-11-25 06:31:34 -06:00
|
|
|
</FormGroup>
|
|
|
|
|
2020-12-25 19:47:36 -06:00
|
|
|
<FormButton @click="() => install(installThemeCode)" :disabled="installThemeCode == null" primary inline><Fa :icon="faCheck"/> {{ $ts.install }}</FormButton>
|
2020-11-25 06:31:34 -06:00
|
|
|
</FormBase>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent } from 'vue';
|
|
|
|
import { faPalette, faDownload, faFolderOpen, faCheck, faTrashAlt, faEye } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import * as JSON5 from 'json5';
|
2021-03-23 03:30:14 -05:00
|
|
|
import FormTextarea from '@client/components/form/textarea.vue';
|
|
|
|
import FormSelect from '@client/components/form/select.vue';
|
|
|
|
import FormRadios from '@client/components/form/radios.vue';
|
|
|
|
import FormBase from '@client/components/form/base.vue';
|
|
|
|
import FormGroup from '@client/components/form/group.vue';
|
|
|
|
import FormLink from '@client/components/form/link.vue';
|
|
|
|
import FormButton from '@client/components/form/button.vue';
|
|
|
|
import { applyTheme, validateTheme } from '@client/scripts/theme';
|
|
|
|
import * as os from '@client/os';
|
|
|
|
import { ColdDeviceStorage } from '@client/store';
|
|
|
|
import { addTheme, getThemes } from '@client/theme-store';
|
2021-04-09 22:54:12 -05:00
|
|
|
import * as symbols from '@client/symbols';
|
2020-11-25 06:31:34 -06:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
|
|
|
FormTextarea,
|
|
|
|
FormSelect,
|
|
|
|
FormRadios,
|
|
|
|
FormBase,
|
|
|
|
FormGroup,
|
|
|
|
FormLink,
|
|
|
|
FormButton,
|
|
|
|
},
|
|
|
|
|
|
|
|
emits: ['info'],
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-04-09 22:54:12 -05:00
|
|
|
[symbols.PAGE_INFO]: {
|
2020-12-25 19:47:36 -06:00
|
|
|
title: this.$ts._theme.install,
|
2020-11-25 06:31:34 -06:00
|
|
|
icon: faDownload
|
|
|
|
},
|
|
|
|
installThemeCode: null,
|
|
|
|
faPalette, faDownload, faFolderOpen, faCheck, faTrashAlt, faEye
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
2021-04-09 22:54:12 -05:00
|
|
|
this.$emit('info', this[symbols.PAGE_INFO]);
|
2020-11-25 06:31:34 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
parseThemeCode(code) {
|
|
|
|
let theme;
|
|
|
|
|
|
|
|
try {
|
|
|
|
theme = JSON5.parse(code);
|
|
|
|
} catch (e) {
|
|
|
|
os.dialog({
|
|
|
|
type: 'error',
|
2020-12-25 19:47:36 -06:00
|
|
|
text: this.$ts._theme.invalid
|
2020-11-25 06:31:34 -06:00
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!validateTheme(theme)) {
|
|
|
|
os.dialog({
|
|
|
|
type: 'error',
|
2020-12-25 19:47:36 -06:00
|
|
|
text: this.$ts._theme.invalid
|
2020-11-25 06:31:34 -06:00
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
2021-01-11 07:31:17 -06:00
|
|
|
if (getThemes().some(t => t.id === theme.id)) {
|
2020-11-25 06:31:34 -06:00
|
|
|
os.dialog({
|
|
|
|
type: 'info',
|
2020-12-25 19:47:36 -06:00
|
|
|
text: this.$ts._theme.alreadyInstalled
|
2020-11-25 06:31:34 -06:00
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return theme;
|
|
|
|
},
|
|
|
|
|
|
|
|
preview(code) {
|
|
|
|
const theme = this.parseThemeCode(code);
|
|
|
|
if (theme) applyTheme(theme, false);
|
|
|
|
},
|
|
|
|
|
2021-01-11 07:31:17 -06:00
|
|
|
async install(code) {
|
2020-11-25 06:31:34 -06:00
|
|
|
const theme = this.parseThemeCode(code);
|
|
|
|
if (!theme) return;
|
2021-01-11 07:31:17 -06:00
|
|
|
await addTheme(theme);
|
2020-11-25 06:31:34 -06:00
|
|
|
os.dialog({
|
|
|
|
type: 'success',
|
|
|
|
text: this.$t('_theme.installed', { name: theme.name })
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|