テーマインポート機能を実装するなど

This commit is contained in:
syuilo 2020-03-23 19:06:46 +09:00
parent b12bf78c6d
commit dac962580b
10 changed files with 118 additions and 12 deletions

View File

@ -466,6 +466,17 @@ details: "詳細"
chooseEmoji: "絵文字を選択" chooseEmoji: "絵文字を選択"
unableToProcess: "操作を完了できません" unableToProcess: "操作を完了できません"
recentUsed: "最近使用" recentUsed: "最近使用"
install: "インストール"
uninstall: "アンインストール"
_theme:
explore: "テーマを探す"
install: "テーマのインストール"
manage: "テーマの管理"
code: "テーマコード"
installed: "{name}をインストールしました"
alreadyInstalled: "そのテーマは既にインストールされています"
invalid: "テーマの形式が間違っています"
_sfx: _sfx:
note: "ノート" note: "ノート"

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="mjndxjcg _panel"> <div class="mjndxjcg _panel">
<img src="https://xn--931a.moe/assets/error.png" class="_ghost"/> <img src="https://xn--931a.moe/assets/error.jpg" class="_ghost"/>
<p><fa :icon="faExclamationTriangle"/> {{ $t('error') }}</p> <p><fa :icon="faExclamationTriangle"/> {{ $t('error') }}</p>
<mk-button @click="() => $emit('retry')" class="button">{{ $t('retry') }}</mk-button> <mk-button @click="() => $emit('retry')" class="button">{{ $t('retry') }}</mk-button>
</div> </div>

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="mk-notes" v-size="[{ max: 500 }]"> <div class="mk-notes" v-size="[{ max: 500 }]">
<div class="empty" v-if="empty"> <div class="empty" v-if="empty">
<img src="https://xn--931a.moe/assets/info.png" class="_ghost"/> <img src="https://xn--931a.moe/assets/info.jpg" class="_ghost"/>
<div>{{ $t('noNotes') }}</div> <div>{{ $t('noNotes') }}</div>
</div> </div>

View File

@ -178,6 +178,7 @@ os.init(async () => {
}, },
watch: { watch: {
'$store.state.device.darkMode'() { '$store.state.device.darkMode'() {
// TODO: このファイルでbuiltinThemesを参照するとcode splittingが効かず、初回読み込み時に全てのテーマコードを読み込むことになってしまい無駄なので何とかする
const themes = builtinThemes.concat(this.$store.state.device.themes); const themes = builtinThemes.concat(this.$store.state.device.themes);
applyTheme(themes.find(x => x.id === (this.$store.state.device.darkMode ? this.$store.state.device.darkTheme : this.$store.state.device.lightTheme))); applyTheme(themes.find(x => x.id === (this.$store.state.device.darkMode ? this.$store.state.device.darkTheme : this.$store.state.device.lightTheme)));
} }

View File

@ -6,7 +6,7 @@
<mk-pagination :pagination="pagination" class="mk-follow-requests" ref="list"> <mk-pagination :pagination="pagination" class="mk-follow-requests" ref="list">
<template #empty> <template #empty>
<div class="tkdrhpxr"> <div class="tkdrhpxr">
<img src="https://xn--931a.moe/assets/info.png" class="_ghost"/> <img src="https://xn--931a.moe/assets/info.jpg" class="_ghost"/>
<div>{{ $t('noFollowRequests') }}</div> <div>{{ $t('noFollowRequests') }}</div>
</div> </div>
</template> </template>

View File

@ -32,7 +32,7 @@
</router-link> </router-link>
</div> </div>
<div class="no-history" v-if="!fetching && messages.length == 0"> <div class="no-history" v-if="!fetching && messages.length == 0">
<img src="https://xn--931a.moe/assets/info.png" class="_ghost"/> <img src="https://xn--931a.moe/assets/info.jpg" class="_ghost"/>
<div>{{ $t('noHistory') }}</div> <div>{{ $t('noHistory') }}</div>
</div> </div>
<mk-loading v-if="fetching"/> <mk-loading v-if="fetching"/>

View File

@ -5,7 +5,7 @@
<section class="_card"> <section class="_card">
<div class="_content"> <div class="_content">
<img src="https://xn--931a.moe/assets/not-found.png" class="_ghost"/> <img src="https://xn--931a.moe/assets/not-found.jpg" class="_ghost"/>
<div>{{ $t('notFoundDescription') }}</div> <div>{{ $t('notFoundDescription') }}</div>
</div> </div>
</section> </section>

View File

@ -42,6 +42,7 @@
<option v-for="x in lightThemes" :value="x.id" :key="x.id">{{ x.name }}</option> <option v-for="x in lightThemes" :value="x.id" :key="x.id">{{ x.name }}</option>
</optgroup> </optgroup>
</mk-select> </mk-select>
<a href="https://assets.msky.cafe/theme/list" rel="noopener" target="_blank" class="_link">{{ $t('_theme.explore') }}</a>
</div> </div>
<div class="_content"> <div class="_content">
<mk-switch v-model="syncDeviceDarkMode">{{ $t('syncDeviceDarkMode') }}</mk-switch> <mk-switch v-model="syncDeviceDarkMode">{{ $t('syncDeviceDarkMode') }}</mk-switch>
@ -50,18 +51,43 @@
<mk-button primary v-if="wallpaper == null" @click="setWallpaper">{{ $t('setWallpaper') }}</mk-button> <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> <mk-button primary v-else @click="wallpaper = null">{{ $t('removeWallpaper') }}</mk-button>
</div> </div>
<div class="_content">
<details>
<summary><fa :icon="faDownload"/> {{ $t('_theme.install') }}</summary>
<mk-textarea v-model="installThemeCode">
<span>{{ $t('_theme.code') }}</span>
</mk-textarea>
<mk-button @click="() => install(this.installThemeCode)" :disabled="installThemeCode == null"><fa :icon="faCheck"/> {{ $t('install') }}</mk-button>
</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">
<span>{{ $t('_theme.code') }}</span>
</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>
</section> </section>
</template> </template>
<script lang="ts"> <script lang="ts">
import Vue from 'vue'; import Vue from 'vue';
import { faPalette } from '@fortawesome/free-solid-svg-icons'; import { faPalette, faDownload, faFolderOpen, faCheck, faTrashAlt } from '@fortawesome/free-solid-svg-icons';
import * as JSON5 from 'json5';
import MkInput from '../../components/ui/input.vue'; import MkInput from '../../components/ui/input.vue';
import MkButton from '../../components/ui/button.vue'; import MkButton from '../../components/ui/button.vue';
import MkSelect from '../../components/ui/select.vue'; import MkSelect from '../../components/ui/select.vue';
import MkSwitch from '../../components/ui/switch.vue'; import MkSwitch from '../../components/ui/switch.vue';
import MkTextarea from '../../components/ui/textarea.vue';
import i18n from '../../i18n'; import i18n from '../../i18n';
import { Theme, builtinThemes, applyTheme } from '../../theme'; import { Theme, builtinThemes, applyTheme, validateTheme } from '../../theme';
import { selectFile } from '../../scripts/select-file'; import { selectFile } from '../../scripts/select-file';
import { isDeviceDarkmode } from '../../scripts/is-device-darkmode'; import { isDeviceDarkmode } from '../../scripts/is-device-darkmode';
@ -73,12 +99,16 @@ export default Vue.extend({
MkButton, MkButton,
MkSelect, MkSelect,
MkSwitch, MkSwitch,
MkTextarea,
}, },
data() { data() {
return { return {
builtinThemes,
installThemeCode: null,
selectedThemeId: null,
wallpaper: localStorage.getItem('wallpaper'), wallpaper: localStorage.getItem('wallpaper'),
faPalette faPalette, faDownload, faFolderOpen, faCheck, faTrashAlt
} }
}, },
@ -118,6 +148,16 @@ export default Vue.extend({
get() { return this.$store.state.device.syncDeviceDarkMode; }, get() { return this.$store.state.device.syncDeviceDarkMode; },
set(value) { this.$store.commit('device/set', { key: 'syncDeviceDarkMode', value }); } set(value) { this.$store.commit('device/set', { key: 'syncDeviceDarkMode', value }); }
}, },
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');
},
}, },
watch: { watch: {
@ -155,6 +195,53 @@ export default Vue.extend({
this.wallpaper = file.url; this.wallpaper = file.url;
}); });
}, },
install(code) {
let theme;
try {
theme = JSON5.parse(code);
} catch (e) {
this.$root.dialog({
type: 'error',
text: this.$t('_theme.invalid')
});
return;
}
if (!validateTheme(theme)) {
this.$root.dialog({
type: 'error',
text: this.$t('_theme.invalid')
});
return;
}
if (this.$store.state.device.themes.some(t => t.id === theme.id)) {
this.$root.dialog({
type: 'info',
text: this.$t('_theme.alreadyInstalled')
});
return;
}
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
});
},
} }
}); });
</script> </script>
@ -179,7 +266,7 @@ export default Vue.extend({
top: 50%; top: 50%;
left: 50%; left: 50%;
overflow: hidden; overflow: hidden;
padding: 0 200px; padding: 0 100px;
transform: translate3d(-50%, -50%, 0); transform: translate3d(-50%, -50%, 0);
input { input {

View File

@ -102,3 +102,10 @@ function compile(theme: Theme): { [key: string]: string } {
function genValue(c: tinycolor.Instance): string { function genValue(c: tinycolor.Instance): string {
return c.toRgbString(); return c.toRgbString();
} }
export function validateTheme(theme: Record<string, any>): boolean {
if (theme.id == null) return false;
if (theme.name == null) return false;
if (theme.base == null || !['light', 'dark'].includes(theme.base)) return false;
return true;
}

View File

@ -16,9 +16,9 @@ html
link(rel='icon' href= icon || '/favicon.ico') link(rel='icon' href= icon || '/favicon.ico')
link(rel='apple-touch-icon' href= icon || '/apple-touch-icon.png') link(rel='apple-touch-icon' href= icon || '/apple-touch-icon.png')
link(rel='manifest' href='/manifest.json') link(rel='manifest' href='/manifest.json')
link(rel='prefetch' href='https://xn--931a.moe/assets/info.png') link(rel='prefetch' href='https://xn--931a.moe/assets/info.jpg')
link(rel='prefetch' href='https://xn--931a.moe/assets/not-found.png') link(rel='prefetch' href='https://xn--931a.moe/assets/not-found.jpg')
link(rel='prefetch' href='https://xn--931a.moe/assets/error.png') link(rel='prefetch' href='https://xn--931a.moe/assets/error.jpg')
title title
block title block title