summaryrefslogtreecommitdiff
path: root/packages/client/src
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2022-03-01 23:58:01 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2022-03-01 23:58:01 +0900
commitba4ef23d6b426f5e54d48d9519d597ca4e8b020f (patch)
tree9a4aee1b1e3809709165edae79e81565259d1f9f /packages/client/src
parent:art: (diff)
downloadsharkey-ba4ef23d6b426f5e54d48d9519d597ca4e8b020f.tar.gz
sharkey-ba4ef23d6b426f5e54d48d9519d597ca4e8b020f.tar.bz2
sharkey-ba4ef23d6b426f5e54d48d9519d597ca4e8b020f.zip
feat: instance default theme
Diffstat (limited to 'packages/client/src')
-rw-r--r--packages/client/src/init.ts13
-rw-r--r--packages/client/src/pages/admin/settings.vue16
-rw-r--r--packages/client/src/pages/settings/theme.vue8
-rw-r--r--packages/client/src/store.ts4
4 files changed, 39 insertions, 2 deletions
diff --git a/packages/client/src/init.ts b/packages/client/src/init.ts
index 113324d494..ab3299d22b 100644
--- a/packages/client/src/init.ts
+++ b/packages/client/src/init.ts
@@ -15,6 +15,7 @@ if (localStorage.getItem('accounts') != null) {
import { computed, createApp, watch, markRaw, version as vueVersion } from 'vue';
import compareVersions from 'compare-versions';
+import * as JSON5 from 'json5';
import widgets from '@/widgets';
import directives from '@/directives';
@@ -159,7 +160,9 @@ if ($i && $i.token) {
}
//#endregion
-fetchInstance().then(() => {
+const fetchInstanceMetaPromise = fetchInstance();
+
+fetchInstanceMetaPromise.then(() => {
localStorage.setItem('v', instance.version);
// Init service worker
@@ -267,6 +270,14 @@ window.matchMedia('(prefers-color-scheme: dark)').addListener(mql => {
});
//#endregion
+fetchInstanceMetaPromise.then(() => {
+ if (defaultStore.state.themeInitial) {
+ if (instance.defaultLightTheme != null) ColdDeviceStorage.set('lightTheme', JSON5.parse(instance.defaultLightTheme));
+ if (instance.defaultDarkTheme != null) ColdDeviceStorage.set('darkTheme', JSON5.parse(instance.defaultDarkTheme));
+ defaultStore.set('themeInitial', false);
+ }
+});
+
// shortcut
document.addEventListener('keydown', makeHotkey({
'd': () => {
diff --git a/packages/client/src/pages/admin/settings.vue b/packages/client/src/pages/admin/settings.vue
index 5cf4d6c882..c5d7821329 100644
--- a/packages/client/src/pages/admin/settings.vue
+++ b/packages/client/src/pages/admin/settings.vue
@@ -31,6 +31,16 @@
<template #caption>#RRGGBB</template>
</FormInput>
+ <FormTextarea v-model="defaultLightTheme" class="_formBlock">
+ <template #label>{{ $ts.instanceDefaultLightTheme }}</template>
+ <template #caption>{{ $ts.instanceDefaultThemeDescription }}</template>
+ </FormTextarea>
+
+ <FormTextarea v-model="defaultDarkTheme" class="_formBlock">
+ <template #label>{{ $ts.instanceDefaultDarkTheme }}</template>
+ <template #caption>{{ $ts.instanceDefaultThemeDescription }}</template>
+ </FormTextarea>
+
<FormInput v-model="tosUrl" class="_formBlock">
<template #prefix><i class="fas fa-link"></i></template>
<template #label>{{ $ts.tosUrl }}</template>
@@ -176,6 +186,8 @@ export default defineComponent({
bannerUrl: null,
backgroundImageUrl: null,
themeColor: null,
+ defaultLightTheme: null,
+ defaultDarkTheme: null,
enableLocalTimeline: false,
enableGlobalTimeline: false,
pinnedUsers: '',
@@ -202,6 +214,8 @@ export default defineComponent({
this.bannerUrl = meta.bannerUrl;
this.backgroundImageUrl = meta.backgroundImageUrl;
this.themeColor = meta.themeColor;
+ this.defaultLightTheme = meta.defaultLightTheme;
+ this.defaultDarkTheme = meta.defaultDarkTheme;
this.maintainerName = meta.maintainerName;
this.maintainerEmail = meta.maintainerEmail;
this.enableLocalTimeline = !meta.disableLocalTimeline;
@@ -228,6 +242,8 @@ export default defineComponent({
bannerUrl: this.bannerUrl,
backgroundImageUrl: this.backgroundImageUrl,
themeColor: this.themeColor === '' ? null : this.themeColor,
+ defaultLightTheme: this.defaultLightTheme === '' ? null : this.defaultLightTheme,
+ defaultDarkTheme: this.defaultDarkTheme === '' ? null : this.defaultDarkTheme,
maintainerName: this.maintainerName,
maintainerEmail: this.maintainerEmail,
disableLocalTimeline: !this.enableLocalTimeline,
diff --git a/packages/client/src/pages/settings/theme.vue b/packages/client/src/pages/settings/theme.vue
index 72b7e69174..92a6fee7a4 100644
--- a/packages/client/src/pages/settings/theme.vue
+++ b/packages/client/src/pages/settings/theme.vue
@@ -87,6 +87,7 @@
<script lang="ts">
import { computed, defineComponent, onActivated, onMounted, ref, watch } from 'vue';
+import * as JSON5 from 'json5';
import FormSwitch from '@/components/form/switch.vue';
import FormSelect from '@/components/form/select.vue';
import FormGroup from '@/components/form/group.vue';
@@ -99,6 +100,8 @@ import { isDeviceDarkmode } from '@/scripts/is-device-darkmode';
import { ColdDeviceStorage } from '@/store';
import { i18n } from '@/i18n';
import { defaultStore } from '@/store';
+import { instance } from '@/instance';
+import { concat } from '@/scripts/array';
import { fetchThemes, getThemes } from '@/theme-store';
import * as symbols from '@/symbols';
@@ -122,7 +125,10 @@ export default defineComponent({
};
const installedThemes = ref(getThemes());
- const themes = computed(() => builtinThemes.concat(installedThemes.value));
+ const instanceThemes = [];
+ if (instance.defaultLightTheme != null) instanceThemes.push(JSON5.parse(instance.defaultLightTheme));
+ if (instance.defaultDarkTheme != null) instanceThemes.push(JSON5.parse(instance.defaultDarkTheme));
+ const themes = computed(() => instanceThemes.concat(builtinThemes.concat(installedThemes.value)));
const darkThemes = computed(() => themes.value.filter(t => t.base === 'dark' || t.kind === 'dark'));
const lightThemes = computed(() => themes.value.filter(t => t.base === 'light' || t.kind === 'light'));
const darkTheme = ColdDeviceStorage.ref('darkTheme');
diff --git a/packages/client/src/store.ts b/packages/client/src/store.ts
index 39f5e4a65f..e6a2f42906 100644
--- a/packages/client/src/store.ts
+++ b/packages/client/src/store.ts
@@ -230,6 +230,10 @@ export const defaultStore = markRaw(new Storage('base', {
where: 'device',
default: ''
},
+ themeInitial: {
+ where: 'device',
+ default: true,
+ },
aiChanMode: {
where: 'device',
default: false