2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
2020-01-30 03:10:42 +01:00
|
|
|
<section class="rfqxtzch _card">
|
2020-01-29 20:37:25 +01:00
|
|
|
<div class="_title"><fa :icon="faPalette"/> {{ $t('theme') }}</div>
|
|
|
|
<div class="_content">
|
2020-03-22 02:39:12 +01:00
|
|
|
<div class="darkMode" :class="{ disabled: syncDeviceDarkMode }">
|
|
|
|
<div class="toggleWrapper">
|
|
|
|
<input type="checkbox" class="dn" id="dn" v-model="darkMode" :disabled="syncDeviceDarkMode"/>
|
|
|
|
<label for="dn" class="toggle">
|
2020-07-24 18:56:52 +02:00
|
|
|
<span class="before">{{ $t('light') }}</span>
|
|
|
|
<span class="after">{{ $t('dark') }}</span>
|
2020-03-22 02:39:12 +01:00
|
|
|
<span class="toggle__handler">
|
|
|
|
<span class="crater crater--1"></span>
|
|
|
|
<span class="crater crater--2"></span>
|
|
|
|
<span class="crater crater--3"></span>
|
|
|
|
</span>
|
|
|
|
<span class="star star--1"></span>
|
|
|
|
<span class="star star--2"></span>
|
|
|
|
<span class="star star--3"></span>
|
|
|
|
<span class="star star--4"></span>
|
|
|
|
<span class="star star--5"></span>
|
|
|
|
<span class="star star--6"></span>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-07-24 18:56:52 +02:00
|
|
|
<mk-switch v-model="syncDeviceDarkMode">{{ $t('syncDeviceDarkMode') }}</mk-switch>
|
2020-03-22 02:39:12 +01:00
|
|
|
</div>
|
|
|
|
<div class="_content">
|
|
|
|
<mk-select v-model="lightTheme">
|
|
|
|
<template #label>{{ $t('themeForLightMode') }}</template>
|
2020-01-29 20:37:25 +01:00
|
|
|
<optgroup :label="$t('lightThemes')">
|
|
|
|
<option v-for="x in lightThemes" :value="x.id" :key="x.id">{{ x.name }}</option>
|
|
|
|
</optgroup>
|
|
|
|
<optgroup :label="$t('darkThemes')">
|
|
|
|
<option v-for="x in darkThemes" :value="x.id" :key="x.id">{{ x.name }}</option>
|
|
|
|
</optgroup>
|
|
|
|
</mk-select>
|
2020-03-22 02:39:12 +01:00
|
|
|
<mk-select v-model="darkTheme">
|
|
|
|
<template #label>{{ $t('themeForDarkMode') }}</template>
|
|
|
|
<optgroup :label="$t('darkThemes')">
|
|
|
|
<option v-for="x in darkThemes" :value="x.id" :key="x.id">{{ x.name }}</option>
|
|
|
|
</optgroup>
|
|
|
|
<optgroup :label="$t('lightThemes')">
|
|
|
|
<option v-for="x in lightThemes" :value="x.id" :key="x.id">{{ x.name }}</option>
|
|
|
|
</optgroup>
|
|
|
|
</mk-select>
|
2020-07-24 18:56:52 +02:00
|
|
|
<a href="https://assets.msky.cafe/theme/list" rel="noopener" target="_blank" class="_link">{{ $t('_theme.explore') }}</a>・<router-link to="/theme-editor" class="_link">{{ $t('_theme.make') }}</router-link>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
2020-02-16 19:10:51 +01:00
|
|
|
<div class="_content">
|
2020-07-24 18:56:52 +02:00
|
|
|
<mk-button primary v-if="wallpaper == null" @click="setWallpaper">{{ $t('setWallpaper') }}</mk-button>
|
|
|
|
<mk-button primary v-else @click="wallpaper = null">{{ $t('removeWallpaper') }}</mk-button>
|
2020-02-16 19:10:51 +01:00
|
|
|
</div>
|
2020-03-23 11:06:46 +01:00
|
|
|
<div class="_content">
|
|
|
|
<details>
|
|
|
|
<summary><fa :icon="faDownload"/> {{ $t('_theme.install') }}</summary>
|
|
|
|
<mk-textarea v-model="installThemeCode">
|
2020-07-24 18:56:52 +02:00
|
|
|
<span>{{ $t('_theme.code') }}</span>
|
2020-03-23 11:06:46 +01:00
|
|
|
</mk-textarea>
|
2020-03-28 07:57:31 +01:00
|
|
|
<mk-button @click="() => install(this.installThemeCode)" :disabled="installThemeCode == null" primary inline><fa :icon="faCheck"/> {{ $t('install') }}</mk-button>
|
|
|
|
<mk-button @click="() => preview(this.installThemeCode)" :disabled="installThemeCode == null" inline><fa :icon="faEye"/> {{ $t('preview') }}</mk-button>
|
2020-03-23 11:06:46 +01:00
|
|
|
</details>
|
|
|
|
</div>
|
|
|
|
<div class="_content">
|
|
|
|
<details>
|
|
|
|
<summary><fa :icon="faFolderOpen"/> {{ $t('_theme.manage') }}</summary>
|
|
|
|
<mk-select v-model="selectedThemeId">
|
|
|
|
<option v-for="x in installedThemes" :value="x.id" :key="x.id">{{ x.name }}</option>
|
|
|
|
</mk-select>
|
|
|
|
<template v-if="selectedTheme">
|
|
|
|
<mk-textarea readonly tall :value="selectedThemeCode">
|
2020-07-24 18:56:52 +02:00
|
|
|
<span>{{ $t('_theme.code') }}</span>
|
2020-03-23 11:06:46 +01:00
|
|
|
</mk-textarea>
|
|
|
|
<mk-button @click="uninstall()" v-if="!builtinThemes.some(t => t.id == selectedTheme.id)"><fa :icon="faTrashAlt"/> {{ $t('uninstall') }}</mk-button>
|
|
|
|
</template>
|
|
|
|
</details>
|
|
|
|
</div>
|
2020-01-29 20:37:25 +01:00
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2020-03-28 07:57:31 +01:00
|
|
|
import { faPalette, faDownload, faFolderOpen, faCheck, faTrashAlt, faEye } from '@fortawesome/free-solid-svg-icons';
|
2020-03-23 11:06:46 +01:00
|
|
|
import * as JSON5 from 'json5';
|
2020-01-29 20:37:25 +01:00
|
|
|
import MkInput from '../../components/ui/input.vue';
|
|
|
|
import MkButton from '../../components/ui/button.vue';
|
|
|
|
import MkSelect from '../../components/ui/select.vue';
|
2020-03-22 02:39:12 +01:00
|
|
|
import MkSwitch from '../../components/ui/switch.vue';
|
2020-03-23 11:06:46 +01:00
|
|
|
import MkTextarea from '../../components/ui/textarea.vue';
|
2020-07-09 17:20:26 +02:00
|
|
|
import { Theme, builtinThemes, applyTheme, validateTheme } from '../../scripts/theme';
|
2020-02-16 19:10:51 +01:00
|
|
|
import { selectFile } from '../../scripts/select-file';
|
2020-03-22 02:57:58 +01:00
|
|
|
import { isDeviceDarkmode } from '../../scripts/is-device-darkmode';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
components: {
|
|
|
|
MkInput,
|
|
|
|
MkButton,
|
|
|
|
MkSelect,
|
2020-03-22 02:39:12 +01:00
|
|
|
MkSwitch,
|
2020-03-23 11:06:46 +01:00
|
|
|
MkTextarea,
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2020-03-23 11:06:46 +01:00
|
|
|
builtinThemes,
|
|
|
|
installThemeCode: null,
|
|
|
|
selectedThemeId: null,
|
2020-02-16 19:10:51 +01:00
|
|
|
wallpaper: localStorage.getItem('wallpaper'),
|
2020-03-28 07:57:31 +01:00
|
|
|
faPalette, faDownload, faFolderOpen, faCheck, faTrashAlt, faEye
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
themes(): Theme[] {
|
|
|
|
return builtinThemes.concat(this.$store.state.device.themes);
|
|
|
|
},
|
|
|
|
|
|
|
|
installedThemes(): Theme[] {
|
|
|
|
return 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');
|
|
|
|
},
|
|
|
|
|
2020-03-22 02:39:12 +01:00
|
|
|
darkTheme: {
|
|
|
|
get() { return this.$store.state.device.darkTheme; },
|
|
|
|
set(value) { this.$store.commit('device/set', { key: 'darkTheme', value }); }
|
|
|
|
},
|
|
|
|
|
|
|
|
lightTheme: {
|
|
|
|
get() { return this.$store.state.device.lightTheme; },
|
|
|
|
set(value) { this.$store.commit('device/set', { key: 'lightTheme', value }); }
|
|
|
|
},
|
|
|
|
|
|
|
|
darkMode: {
|
|
|
|
get() { return this.$store.state.device.darkMode; },
|
|
|
|
set(value) { this.$store.commit('device/set', { key: 'darkMode', value }); }
|
|
|
|
},
|
|
|
|
|
|
|
|
syncDeviceDarkMode: {
|
|
|
|
get() { return this.$store.state.device.syncDeviceDarkMode; },
|
|
|
|
set(value) { this.$store.commit('device/set', { key: 'syncDeviceDarkMode', value }); }
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
2020-03-23 11:06:46 +01:00
|
|
|
|
|
|
|
selectedTheme() {
|
|
|
|
if (this.selectedThemeId == null) return null;
|
|
|
|
return this.themes.find(x => x.id === this.selectedThemeId);
|
|
|
|
},
|
|
|
|
|
|
|
|
selectedThemeCode() {
|
|
|
|
if (this.selectedTheme == null) return null;
|
|
|
|
return JSON5.stringify(this.selectedTheme, null, '\t');
|
|
|
|
},
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
2020-03-22 02:39:12 +01:00
|
|
|
darkTheme() {
|
|
|
|
if (this.$store.state.device.darkMode) {
|
|
|
|
applyTheme(this.themes.find(x => x.id === this.darkTheme));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
lightTheme() {
|
|
|
|
if (!this.$store.state.device.darkMode) {
|
|
|
|
applyTheme(this.themes.find(x => x.id === this.lightTheme));
|
|
|
|
}
|
2020-02-16 19:10:51 +01:00
|
|
|
},
|
|
|
|
|
2020-03-22 02:57:58 +01:00
|
|
|
syncDeviceDarkMode() {
|
|
|
|
if (this.$store.state.device.syncDeviceDarkMode) {
|
|
|
|
this.$store.commit('device/set', { key: 'darkMode', value: isDeviceDarkmode() });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-02-16 19:10:51 +01:00
|
|
|
wallpaper() {
|
|
|
|
if (this.wallpaper == null) {
|
|
|
|
localStorage.removeItem('wallpaper');
|
|
|
|
} else {
|
|
|
|
localStorage.setItem('wallpaper', this.wallpaper);
|
|
|
|
}
|
|
|
|
location.reload();
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2020-02-16 19:10:51 +01:00
|
|
|
setWallpaper(e) {
|
|
|
|
selectFile(this, e.currentTarget || e.target, null, false).then(file => {
|
|
|
|
this.wallpaper = file.url;
|
|
|
|
});
|
|
|
|
},
|
2020-03-23 11:06:46 +01:00
|
|
|
|
2020-03-28 07:57:31 +01:00
|
|
|
parseThemeCode(code) {
|
2020-03-23 11:06:46 +01:00
|
|
|
let theme;
|
2020-03-28 07:57:31 +01:00
|
|
|
|
2020-03-23 11:06:46 +01:00
|
|
|
try {
|
|
|
|
theme = JSON5.parse(code);
|
|
|
|
} catch (e) {
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'error',
|
|
|
|
text: this.$t('_theme.invalid')
|
|
|
|
});
|
2020-03-28 07:57:31 +01:00
|
|
|
return false;
|
2020-03-23 11:06:46 +01:00
|
|
|
}
|
|
|
|
if (!validateTheme(theme)) {
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'error',
|
|
|
|
text: this.$t('_theme.invalid')
|
|
|
|
});
|
2020-03-28 07:57:31 +01:00
|
|
|
return false;
|
2020-03-23 11:06:46 +01:00
|
|
|
}
|
|
|
|
if (this.$store.state.device.themes.some(t => t.id === theme.id)) {
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'info',
|
|
|
|
text: this.$t('_theme.alreadyInstalled')
|
|
|
|
});
|
2020-03-28 07:57:31 +01:00
|
|
|
return false;
|
2020-03-23 11:06:46 +01:00
|
|
|
}
|
2020-03-28 07:57:31 +01:00
|
|
|
|
|
|
|
return theme;
|
|
|
|
},
|
|
|
|
|
|
|
|
preview(code) {
|
|
|
|
const theme = this.parseThemeCode(code);
|
|
|
|
if (theme) applyTheme(theme, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
install(code) {
|
|
|
|
const theme = this.parseThemeCode(code);
|
|
|
|
if (!theme) return;
|
2020-03-23 11:06:46 +01:00
|
|
|
const themes = this.$store.state.device.themes.concat(theme);
|
|
|
|
this.$store.commit('device/set', {
|
|
|
|
key: 'themes', value: themes
|
|
|
|
});
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'success',
|
|
|
|
text: this.$t('_theme.installed', { name: theme.name })
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
uninstall() {
|
|
|
|
const theme = this.selectedTheme;
|
|
|
|
const themes = this.$store.state.device.themes.filter(t => t.id != theme.id);
|
|
|
|
this.$store.commit('device/set', {
|
|
|
|
key: 'themes', value: themes
|
|
|
|
});
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'info',
|
|
|
|
iconOnly: true, autoClose: true
|
|
|
|
});
|
|
|
|
},
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
2020-03-22 02:39:12 +01:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.rfqxtzch {
|
|
|
|
> ._content {
|
|
|
|
> .darkMode {
|
|
|
|
position: relative;
|
|
|
|
padding: 32px 0;
|
|
|
|
|
|
|
|
&.disabled {
|
|
|
|
opacity: 0.7;
|
|
|
|
|
|
|
|
&, * {
|
|
|
|
cursor: not-allowed !important;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.toggleWrapper {
|
|
|
|
position: absolute;
|
|
|
|
top: 50%;
|
|
|
|
left: 50%;
|
|
|
|
overflow: hidden;
|
2020-03-23 11:06:46 +01:00
|
|
|
padding: 0 100px;
|
2020-03-22 02:39:12 +01:00
|
|
|
transform: translate3d(-50%, -50%, 0);
|
|
|
|
|
|
|
|
input {
|
|
|
|
position: absolute;
|
|
|
|
left: -99em;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.toggle {
|
|
|
|
cursor: pointer;
|
|
|
|
display: inline-block;
|
|
|
|
position: relative;
|
|
|
|
width: 90px;
|
|
|
|
height: 50px;
|
|
|
|
background-color: #83D8FF;
|
|
|
|
border-radius: 90px - 6;
|
|
|
|
transition: background-color 200ms cubic-bezier(0.445, 0.05, 0.55, 0.95) !important;
|
|
|
|
|
|
|
|
> .before, > .after {
|
|
|
|
position: absolute;
|
|
|
|
top: 15px;
|
|
|
|
font-size: 18px;
|
|
|
|
transition: color 1s ease;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .before {
|
2020-03-22 02:55:46 +01:00
|
|
|
left: -70px;
|
2020-03-22 02:39:12 +01:00
|
|
|
color: var(--accent);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .after {
|
2020-03-22 02:55:46 +01:00
|
|
|
right: -68px;
|
2020-03-22 02:39:12 +01:00
|
|
|
color: var(--fg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.toggle__handler {
|
|
|
|
display: inline-block;
|
|
|
|
position: relative;
|
|
|
|
z-index: 1;
|
|
|
|
top: 3px;
|
|
|
|
left: 3px;
|
|
|
|
width: 50px - 6;
|
|
|
|
height: 50px - 6;
|
|
|
|
background-color: #FFCF96;
|
|
|
|
border-radius: 50px;
|
|
|
|
box-shadow: 0 2px 6px rgba(0,0,0,.3);
|
|
|
|
transition: all 400ms cubic-bezier(0.68, -0.55, 0.265, 1.55) !important;
|
|
|
|
transform: rotate(-45deg);
|
|
|
|
|
|
|
|
.crater {
|
|
|
|
position: absolute;
|
|
|
|
background-color: #E8CDA5;
|
|
|
|
opacity: 0;
|
|
|
|
transition: opacity 200ms ease-in-out !important;
|
|
|
|
border-radius: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.crater--1 {
|
|
|
|
top: 18px;
|
|
|
|
left: 10px;
|
|
|
|
width: 4px;
|
|
|
|
height: 4px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.crater--2 {
|
|
|
|
top: 28px;
|
|
|
|
left: 22px;
|
|
|
|
width: 6px;
|
|
|
|
height: 6px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.crater--3 {
|
|
|
|
top: 10px;
|
|
|
|
left: 25px;
|
|
|
|
width: 8px;
|
|
|
|
height: 8px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.star {
|
|
|
|
position: absolute;
|
|
|
|
background-color: #ffffff;
|
|
|
|
transition: all 300ms cubic-bezier(0.445, 0.05, 0.55, 0.95) !important;
|
|
|
|
border-radius: 50%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.star--1 {
|
|
|
|
top: 10px;
|
|
|
|
left: 35px;
|
|
|
|
z-index: 0;
|
|
|
|
width: 30px;
|
|
|
|
height: 3px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.star--2 {
|
|
|
|
top: 18px;
|
|
|
|
left: 28px;
|
|
|
|
z-index: 1;
|
|
|
|
width: 30px;
|
|
|
|
height: 3px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.star--3 {
|
|
|
|
top: 27px;
|
|
|
|
left: 40px;
|
|
|
|
z-index: 0;
|
|
|
|
width: 30px;
|
|
|
|
height: 3px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.star--4,
|
|
|
|
.star--5,
|
|
|
|
.star--6 {
|
|
|
|
opacity: 0;
|
|
|
|
transition: all 300ms 0 cubic-bezier(0.445, 0.05, 0.55, 0.95) !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.star--4 {
|
|
|
|
top: 16px;
|
|
|
|
left: 11px;
|
|
|
|
z-index: 0;
|
|
|
|
width: 2px;
|
|
|
|
height: 2px;
|
|
|
|
transform: translate3d(3px,0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
.star--5 {
|
|
|
|
top: 32px;
|
|
|
|
left: 17px;
|
|
|
|
z-index: 0;
|
|
|
|
width: 3px;
|
|
|
|
height: 3px;
|
|
|
|
transform: translate3d(3px,0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
.star--6 {
|
|
|
|
top: 36px;
|
|
|
|
left: 28px;
|
|
|
|
z-index: 0;
|
|
|
|
width: 2px;
|
|
|
|
height: 2px;
|
|
|
|
transform: translate3d(3px,0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
input:checked {
|
|
|
|
+ .toggle {
|
|
|
|
background-color: #749DD6;
|
|
|
|
|
|
|
|
> .before {
|
|
|
|
color: var(--fg);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .after {
|
|
|
|
color: var(--accent);
|
|
|
|
}
|
|
|
|
|
|
|
|
.toggle__handler {
|
|
|
|
background-color: #FFE5B5;
|
|
|
|
transform: translate3d(40px, 0, 0) rotate(0);
|
|
|
|
|
|
|
|
.crater { opacity: 1; }
|
|
|
|
}
|
|
|
|
|
|
|
|
.star--1 {
|
|
|
|
width: 2px;
|
|
|
|
height: 2px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.star--2 {
|
|
|
|
width: 4px;
|
|
|
|
height: 4px;
|
|
|
|
transform: translate3d(-5px, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
.star--3 {
|
|
|
|
width: 2px;
|
|
|
|
height: 2px;
|
|
|
|
transform: translate3d(-7px, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
.star--4,
|
|
|
|
.star--5,
|
|
|
|
.star--6 {
|
|
|
|
opacity: 1;
|
|
|
|
transform: translate3d(0,0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
.star--4 {
|
|
|
|
transition: all 300ms 200ms cubic-bezier(0.445, 0.05, 0.55, 0.95) !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.star--5 {
|
|
|
|
transition: all 300ms 300ms cubic-bezier(0.445, 0.05, 0.55, 0.95) !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.star--6 {
|
|
|
|
transition: all 300ms 400ms cubic-bezier(0.445, 0.05, 0.55, 0.95) !important;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|