2018-09-29 00:01:11 +09:00
|
|
|
<template>
|
|
|
|
<div class="nicnklzforebnpfgasiypmpdaaglujqm">
|
|
|
|
<label>
|
2018-11-09 03:44:35 +09:00
|
|
|
<span>{{ $t('light-theme') }}</span>
|
2018-11-09 13:47:22 +09:00
|
|
|
<ui-select v-model="light" :placeholder="$t('light-theme')">
|
|
|
|
<optgroup :label="$t('light-themes')">
|
2018-10-08 15:23:10 +09:00
|
|
|
<option v-for="x in lightThemes" :value="x.id" :key="x.id">{{ x.name }}</option>
|
|
|
|
</optgroup>
|
2018-11-09 13:47:22 +09:00
|
|
|
<optgroup :label="$t('dark-themes')">
|
2018-10-08 15:23:10 +09:00
|
|
|
<option v-for="x in darkThemes" :value="x.id" :key="x.id">{{ x.name }}</option>
|
|
|
|
</optgroup>
|
2018-09-29 00:01:11 +09:00
|
|
|
</ui-select>
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<label>
|
2018-11-09 03:44:35 +09:00
|
|
|
<span>{{ $t('dark-theme') }}</span>
|
2018-11-09 13:47:22 +09:00
|
|
|
<ui-select v-model="dark" :placeholder="$t('dark-theme')">
|
|
|
|
<optgroup :label="$t('dark-themes')">
|
2018-10-08 15:23:10 +09:00
|
|
|
<option v-for="x in darkThemes" :value="x.id" :key="x.id">{{ x.name }}</option>
|
|
|
|
</optgroup>
|
2018-11-09 13:47:22 +09:00
|
|
|
<optgroup :label="$t('light-themes')">
|
2018-10-08 15:23:10 +09:00
|
|
|
<option v-for="x in lightThemes" :value="x.id" :key="x.id">{{ x.name }}</option>
|
|
|
|
</optgroup>
|
2018-09-29 00:01:11 +09:00
|
|
|
</ui-select>
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<details class="creator">
|
2018-11-09 03:44:35 +09:00
|
|
|
<summary><fa icon="palette"/> {{ $t('create-a-theme') }}</summary>
|
2018-09-29 00:01:11 +09:00
|
|
|
<div>
|
2018-11-09 03:44:35 +09:00
|
|
|
<span>{{ $t('base-theme') }}:</span>
|
|
|
|
<ui-radio v-model="myThemeBase" value="light">{{ $t('base-theme-light') }}</ui-radio>
|
|
|
|
<ui-radio v-model="myThemeBase" value="dark">{{ $t('base-theme-dark') }}</ui-radio>
|
2018-09-29 00:01:11 +09:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<ui-input v-model="myThemeName">
|
2018-11-09 03:44:35 +09:00
|
|
|
<span>{{ $t('theme-name') }}</span>
|
2018-09-29 00:01:11 +09:00
|
|
|
</ui-input>
|
2018-10-03 03:07:46 +09:00
|
|
|
<ui-textarea v-model="myThemeDesc">
|
2018-11-09 03:44:35 +09:00
|
|
|
<span>{{ $t('desc') }}</span>
|
2018-10-03 03:07:46 +09:00
|
|
|
</ui-textarea>
|
2018-09-29 00:01:11 +09:00
|
|
|
</div>
|
|
|
|
<div>
|
2018-11-09 03:44:35 +09:00
|
|
|
<div style="padding-bottom:8px;">{{ $t('primary-color') }}:</div>
|
2018-09-29 00:01:11 +09:00
|
|
|
<color-picker v-model="myThemePrimary"/>
|
|
|
|
</div>
|
|
|
|
<div>
|
2018-11-09 03:44:35 +09:00
|
|
|
<div style="padding-bottom:8px;">{{ $t('secondary-color') }}:</div>
|
2018-09-29 00:01:11 +09:00
|
|
|
<color-picker v-model="myThemeSecondary"/>
|
|
|
|
</div>
|
|
|
|
<div>
|
2018-11-09 03:44:35 +09:00
|
|
|
<div style="padding-bottom:8px;">{{ $t('text-color') }}:</div>
|
2018-09-29 00:01:11 +09:00
|
|
|
<color-picker v-model="myThemeText"/>
|
|
|
|
</div>
|
2018-11-09 03:44:35 +09:00
|
|
|
<ui-button @click="preview()"><fa icon="eye"/> {{ $t('preview-created-theme') }}</ui-button>
|
|
|
|
<ui-button primary @click="gen()"><fa :icon="['far', 'save']"/> {{ $t('save-created-theme') }}</ui-button>
|
2018-09-29 00:01:11 +09:00
|
|
|
</details>
|
|
|
|
|
|
|
|
<details>
|
2018-11-09 03:44:35 +09:00
|
|
|
<summary><fa icon="download"/> {{ $t('install-a-theme') }}</summary>
|
|
|
|
<ui-button @click="import_()"><fa icon="file-import"/> {{ $t('import') }}</ui-button>
|
2018-10-03 03:00:55 +09:00
|
|
|
<input ref="file" type="file" accept=".misskeytheme" style="display:none;" @change="onUpdateImportFile"/>
|
2018-11-09 03:44:35 +09:00
|
|
|
<p>{{ $t('import-by-code') }}:</p>
|
2018-09-29 00:01:11 +09:00
|
|
|
<ui-textarea v-model="installThemeCode">
|
2018-11-09 03:44:35 +09:00
|
|
|
<span>{{ $t('theme-code') }}</span>
|
2018-09-29 00:01:11 +09:00
|
|
|
</ui-textarea>
|
2018-11-09 03:44:35 +09:00
|
|
|
<ui-button @click="() => install(this.installThemeCode)"><fa icon="check"/> {{ $t('install') }}</ui-button>
|
2018-09-29 00:01:11 +09:00
|
|
|
</details>
|
|
|
|
|
|
|
|
<details>
|
2018-11-09 03:44:35 +09:00
|
|
|
<summary><fa icon="folder-open"/> {{ $t('manage-themes') }}</summary>
|
2018-11-09 13:47:22 +09:00
|
|
|
<ui-select v-model="selectedThemeId" :placeholder="$t('select-theme')">
|
|
|
|
<optgroup :label="$t('builtin-themes')">
|
2018-10-09 06:46:52 +09:00
|
|
|
<option v-for="x in builtinThemes" :value="x.id" :key="x.id">{{ x.name }}</option>
|
|
|
|
</optgroup>
|
2018-11-09 13:47:22 +09:00
|
|
|
<optgroup :label="$t('my-themes')">
|
2018-10-09 06:46:52 +09:00
|
|
|
<option v-for="x in installedThemes.filter(t => t.author == this.$store.state.i.username)" :value="x.id" :key="x.id">{{ x.name }}</option>
|
|
|
|
</optgroup>
|
2018-11-09 13:47:22 +09:00
|
|
|
<optgroup :label="$t('installed-themes')">
|
2018-10-09 06:46:52 +09:00
|
|
|
<option v-for="x in installedThemes.filter(t => t.author != this.$store.state.i.username)" :value="x.id" :key="x.id">{{ x.name }}</option>
|
|
|
|
</optgroup>
|
2018-09-29 00:01:11 +09:00
|
|
|
</ui-select>
|
2018-10-09 06:46:52 +09:00
|
|
|
<template v-if="selectedTheme">
|
|
|
|
<ui-input readonly :value="selectedTheme.author">
|
2018-11-09 03:44:35 +09:00
|
|
|
<span>{{ $t('author') }}</span>
|
2018-10-02 16:10:45 +09:00
|
|
|
</ui-input>
|
2018-10-09 06:46:52 +09:00
|
|
|
<ui-textarea v-if="selectedTheme.desc" readonly :value="selectedTheme.desc">
|
2018-11-09 03:44:35 +09:00
|
|
|
<span>{{ $t('desc') }}</span>
|
2018-10-02 16:10:45 +09:00
|
|
|
</ui-textarea>
|
2018-10-09 06:46:52 +09:00
|
|
|
<ui-textarea readonly :value="selectedThemeCode">
|
2018-11-09 03:44:35 +09:00
|
|
|
<span>{{ $t('theme-code') }}</span>
|
2018-10-02 16:10:45 +09:00
|
|
|
</ui-textarea>
|
2018-11-09 03:44:35 +09:00
|
|
|
<ui-button @click="export_()" link :download="`${selectedTheme.name}.misskeytheme`" ref="export"><fa icon="box"/> {{ $t('export') }}</ui-button>
|
|
|
|
<ui-button @click="uninstall()" v-if="!builtinThemes.some(t => t.id == selectedTheme.id)"><fa :icon="['far', 'trash-alt']"/> {{ $t('uninstall') }}</ui-button>
|
2018-10-02 16:10:45 +09:00
|
|
|
</template>
|
2018-09-29 00:01:11 +09:00
|
|
|
</details>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-11-09 03:44:35 +09:00
|
|
|
import i18n from '../../../i18n';
|
2018-10-02 16:04:31 +09:00
|
|
|
import { lightTheme, darkTheme, builtinThemes, applyTheme, Theme } from '../../../theme';
|
2018-09-29 00:01:11 +09:00
|
|
|
import { Chrome } from 'vue-color';
|
|
|
|
import * as uuid from 'uuid';
|
|
|
|
import * as tinycolor from 'tinycolor2';
|
2018-10-02 16:04:31 +09:00
|
|
|
import * as JSON5 from 'json5';
|
|
|
|
|
|
|
|
// 後方互換性のため
|
|
|
|
function convertOldThemedefinition(t) {
|
|
|
|
const t2 = {
|
|
|
|
id: t.meta.id,
|
|
|
|
name: t.meta.name,
|
|
|
|
author: t.meta.author,
|
|
|
|
base: t.meta.base,
|
|
|
|
vars: t.meta.vars,
|
|
|
|
props: t
|
|
|
|
};
|
|
|
|
delete t2.props.meta;
|
|
|
|
return t2;
|
|
|
|
}
|
2018-09-29 00:01:11 +09:00
|
|
|
|
|
|
|
export default Vue.extend({
|
2018-11-09 03:44:35 +09:00
|
|
|
i18n: i18n('common/views/components/theme.vue'),
|
2018-09-29 00:01:11 +09:00
|
|
|
components: {
|
|
|
|
ColorPicker: Chrome
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2018-10-09 06:46:52 +09:00
|
|
|
builtinThemes: builtinThemes,
|
2018-09-29 00:01:11 +09:00
|
|
|
installThemeCode: null,
|
2018-10-09 06:46:52 +09:00
|
|
|
selectedThemeId: null,
|
2018-09-29 00:01:11 +09:00
|
|
|
myThemeBase: 'light',
|
|
|
|
myThemeName: '',
|
2018-10-03 03:07:46 +09:00
|
|
|
myThemeDesc: '',
|
2018-10-02 16:04:31 +09:00
|
|
|
myThemePrimary: lightTheme.vars.primary,
|
|
|
|
myThemeSecondary: lightTheme.vars.secondary,
|
|
|
|
myThemeText: lightTheme.vars.text
|
2018-09-29 00:01:11 +09:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2018-10-02 16:04:31 +09:00
|
|
|
themes(): Theme[] {
|
2018-10-08 15:23:10 +09:00
|
|
|
return builtinThemes.concat(this.$store.state.device.themes);
|
|
|
|
},
|
|
|
|
|
|
|
|
darkThemes(): Theme[] {
|
|
|
|
return this.themes.filter(t => t.base == 'dark' || t.kind == 'dark');
|
|
|
|
},
|
|
|
|
|
|
|
|
lightThemes(): Theme[] {
|
|
|
|
return this.themes.filter(t => t.base == 'light' || t.kind == 'light');
|
2018-09-29 00:01:11 +09:00
|
|
|
},
|
|
|
|
|
2018-10-02 16:04:31 +09:00
|
|
|
installedThemes(): Theme[] {
|
2018-09-29 00:01:11 +09:00
|
|
|
return this.$store.state.device.themes;
|
|
|
|
},
|
|
|
|
|
|
|
|
light: {
|
|
|
|
get() { return this.$store.state.device.lightTheme; },
|
|
|
|
set(value) { this.$store.commit('device/set', { key: 'lightTheme', value }); }
|
|
|
|
},
|
|
|
|
|
|
|
|
dark: {
|
|
|
|
get() { return this.$store.state.device.darkTheme; },
|
|
|
|
set(value) { this.$store.commit('device/set', { key: 'darkTheme', value }); }
|
|
|
|
},
|
|
|
|
|
2018-10-09 06:46:52 +09:00
|
|
|
selectedTheme() {
|
|
|
|
if (this.selectedThemeId == null) return null;
|
|
|
|
return this.themes.find(x => x.id == this.selectedThemeId);
|
2018-10-02 16:10:45 +09:00
|
|
|
},
|
|
|
|
|
2018-10-09 06:46:52 +09:00
|
|
|
selectedThemeCode() {
|
|
|
|
if (this.selectedTheme == null) return null;
|
|
|
|
return JSON5.stringify(this.selectedTheme, null, '\t');
|
2018-09-29 00:01:11 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
myTheme(): any {
|
|
|
|
return {
|
2018-10-02 16:04:31 +09:00
|
|
|
name: this.myThemeName,
|
2018-10-02 16:10:45 +09:00
|
|
|
author: this.$store.state.i.username,
|
2018-10-03 03:07:46 +09:00
|
|
|
desc: this.myThemeDesc,
|
2018-10-02 16:04:31 +09:00
|
|
|
base: this.myThemeBase,
|
|
|
|
vars: {
|
|
|
|
primary: tinycolor(typeof this.myThemePrimary == 'string' ? this.myThemePrimary : this.myThemePrimary.rgba).toRgbString(),
|
|
|
|
secondary: tinycolor(typeof this.myThemeSecondary == 'string' ? this.myThemeSecondary : this.myThemeSecondary.rgba).toRgbString(),
|
|
|
|
text: tinycolor(typeof this.myThemeText == 'string' ? this.myThemeText : this.myThemeText.rgba).toRgbString()
|
2018-09-29 00:01:11 +09:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
myThemeBase(v) {
|
|
|
|
const theme = v == 'light' ? lightTheme : darkTheme;
|
2018-10-02 16:04:31 +09:00
|
|
|
this.myThemePrimary = theme.vars.primary;
|
|
|
|
this.myThemeSecondary = theme.vars.secondary;
|
|
|
|
this.myThemeText = theme.vars.text;
|
2018-09-29 00:01:11 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-10-02 16:04:31 +09:00
|
|
|
beforeCreate() {
|
|
|
|
// migrate old theme definitions
|
|
|
|
// 後方互換性のため
|
|
|
|
this.$store.commit('device/set', {
|
|
|
|
key: 'themes', value: this.$store.state.device.themes.map(t => {
|
|
|
|
if (t.id == null) {
|
|
|
|
return convertOldThemedefinition(t);
|
|
|
|
} else {
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-09-29 00:01:11 +09:00
|
|
|
methods: {
|
2018-10-03 02:57:31 +09:00
|
|
|
install(code) {
|
2018-10-02 16:04:31 +09:00
|
|
|
let theme;
|
|
|
|
|
|
|
|
try {
|
2018-10-03 02:57:31 +09:00
|
|
|
theme = JSON5.parse(code);
|
2018-10-02 16:04:31 +09:00
|
|
|
} catch (e) {
|
2018-10-10 21:23:38 +09:00
|
|
|
this.$swal({
|
|
|
|
type: 'error',
|
2018-11-09 03:44:35 +09:00
|
|
|
text: this.$t('invalid-theme')
|
2018-10-10 21:23:38 +09:00
|
|
|
});
|
2018-09-29 00:01:11 +09:00
|
|
|
return;
|
|
|
|
}
|
2018-10-02 16:04:31 +09:00
|
|
|
|
|
|
|
// 後方互換性のため
|
|
|
|
if (theme.id == null && theme.meta != null) {
|
|
|
|
theme = convertOldThemedefinition(theme);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (theme.id == null) {
|
2018-10-10 21:23:38 +09:00
|
|
|
this.$swal({
|
|
|
|
type: 'error',
|
2018-11-09 03:44:35 +09:00
|
|
|
text: this.$t('invalid-theme')
|
2018-10-10 21:23:38 +09:00
|
|
|
});
|
2018-10-02 16:04:31 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.$store.state.device.themes.some(t => t.id == theme.id)) {
|
2018-10-10 21:23:38 +09:00
|
|
|
this.$swal({
|
|
|
|
type: 'info',
|
2018-11-09 03:44:35 +09:00
|
|
|
text: this.$t('already-installed')
|
2018-10-10 21:23:38 +09:00
|
|
|
});
|
2018-09-29 00:01:11 +09:00
|
|
|
return;
|
|
|
|
}
|
2018-10-02 16:04:31 +09:00
|
|
|
|
2018-09-29 00:01:11 +09:00
|
|
|
const themes = this.$store.state.device.themes.concat(theme);
|
|
|
|
this.$store.commit('device/set', {
|
|
|
|
key: 'themes', value: themes
|
|
|
|
});
|
2018-10-02 16:04:31 +09:00
|
|
|
|
2018-10-10 21:23:38 +09:00
|
|
|
this.$swal({
|
|
|
|
type: 'success',
|
2018-11-09 03:44:35 +09:00
|
|
|
text: this.$t('installed').replace('{}', theme.name)
|
2018-10-10 21:23:38 +09:00
|
|
|
});
|
2018-09-30 23:03:21 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
uninstall() {
|
2018-10-09 06:46:52 +09:00
|
|
|
const theme = this.selectedTheme;
|
2018-10-02 16:04:31 +09:00
|
|
|
const themes = this.$store.state.device.themes.filter(t => t.id != theme.id);
|
2018-09-30 23:03:21 +09:00
|
|
|
this.$store.commit('device/set', {
|
|
|
|
key: 'themes', value: themes
|
|
|
|
});
|
2018-10-10 21:23:38 +09:00
|
|
|
|
|
|
|
this.$swal({
|
|
|
|
type: 'info',
|
2018-11-09 03:44:35 +09:00
|
|
|
text: this.$t('uninstalled').replace('{}', theme.name)
|
2018-10-10 21:23:38 +09:00
|
|
|
});
|
2018-09-29 00:01:11 +09:00
|
|
|
},
|
|
|
|
|
2018-10-03 02:57:31 +09:00
|
|
|
import_() {
|
|
|
|
(this.$refs.file as any).click();
|
|
|
|
}
|
|
|
|
|
|
|
|
export_() {
|
2018-10-09 06:46:52 +09:00
|
|
|
const blob = new Blob([this.selectedThemeCode], {
|
2018-10-03 02:57:31 +09:00
|
|
|
type: 'application/json5'
|
|
|
|
});
|
|
|
|
this.$refs.export.$el.href = window.URL.createObjectURL(blob);
|
|
|
|
},
|
|
|
|
|
|
|
|
onUpdateImportFile() {
|
|
|
|
const f = (this.$refs.file as any).files[0];
|
|
|
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
|
|
|
|
reader.onload = e => {
|
|
|
|
this.install(e.target.result);
|
|
|
|
};
|
|
|
|
|
|
|
|
reader.readAsText(f);
|
|
|
|
},
|
|
|
|
|
2018-09-29 00:01:11 +09:00
|
|
|
preview() {
|
|
|
|
applyTheme(this.myTheme, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
gen() {
|
|
|
|
const theme = this.myTheme;
|
2018-10-10 21:23:38 +09:00
|
|
|
|
2018-10-03 03:07:46 +09:00
|
|
|
if (theme.name == null || theme.name.trim() == '') {
|
2018-10-10 21:23:38 +09:00
|
|
|
this.$swal({
|
|
|
|
type: 'warning',
|
2018-11-09 03:44:35 +09:00
|
|
|
text: this.$t('theme-name-required')
|
2018-10-10 21:23:38 +09:00
|
|
|
});
|
2018-10-03 03:07:46 +09:00
|
|
|
return;
|
|
|
|
}
|
2018-10-10 21:23:38 +09:00
|
|
|
|
2018-10-02 16:04:31 +09:00
|
|
|
theme.id = uuid();
|
2018-10-10 21:23:38 +09:00
|
|
|
|
2018-09-29 00:01:11 +09:00
|
|
|
const themes = this.$store.state.device.themes.concat(theme);
|
|
|
|
this.$store.commit('device/set', {
|
|
|
|
key: 'themes', value: themes
|
|
|
|
});
|
2018-10-10 21:23:38 +09:00
|
|
|
|
|
|
|
this.$swal({
|
|
|
|
type: 'success',
|
2018-11-09 03:44:35 +09:00
|
|
|
text: this.$t('saved')
|
2018-10-10 21:23:38 +09:00
|
|
|
});
|
2018-09-29 00:01:11 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
|
|
|
.nicnklzforebnpfgasiypmpdaaglujqm
|
2018-10-02 16:23:55 +09:00
|
|
|
> details
|
|
|
|
border-top solid 1px var(--faceDivider)
|
|
|
|
|
2018-10-03 02:57:31 +09:00
|
|
|
> summary
|
|
|
|
padding 16px 0
|
|
|
|
|
|
|
|
> *:last-child
|
|
|
|
margin-bottom 16px
|
|
|
|
|
2018-09-29 00:01:11 +09:00
|
|
|
> .creator
|
|
|
|
> div
|
|
|
|
padding 16px 0
|
|
|
|
border-bottom solid 1px var(--faceDivider)
|
|
|
|
</style>
|