Merge branch 'appearance-tab' into shigusegubu-themes3

This commit is contained in:
Henry Jameson 2024-06-27 02:07:31 +03:00
commit 79bc1e5606
8 changed files with 156 additions and 156 deletions

View file

@ -1,4 +1,3 @@
import { set, clone } from 'lodash'
import Select from '../select/select.vue' import Select from '../select/select.vue'
import Checkbox from 'src/components/checkbox/checkbox.vue' import Checkbox from 'src/components/checkbox/checkbox.vue'
import Popover from 'src/components/popover/popover.vue' import Popover from 'src/components/popover/popover.vue'
@ -16,8 +15,6 @@ library.add(
faFont faFont
) )
const PRESET_FONTS = new Set(['serif', 'sans-serif', 'monospace', 'inherit'])
export default { export default {
components: { components: {
Select, Select,
@ -27,94 +24,36 @@ export default {
props: [ props: [
'name', 'label', 'modelValue', 'fallback', 'options', 'no-inherit' 'name', 'label', 'modelValue', 'fallback', 'options', 'no-inherit'
], ],
mounted () {
this.$store.dispatch('queryLocalFonts')
},
emits: ['update:modelValue'], emits: ['update:modelValue'],
data () { data () {
return { return {
manualEntry: true, manualEntry: false,
localValue: clone(this.modelValue),
familyCustomLocal: null,
availableOptions: [ availableOptions: [
this.noInherit ? '' : 'inherit', this.noInherit ? '' : 'inherit',
'serif', 'serif',
'sans-serif', 'sans-serif',
'monospace', 'monospace',
'local',
...(this.options || []) ...(this.options || [])
].filter(_ => _) ].filter(_ => _)
} }
}, },
beforeUpdate () {
this.localValue = clone(this.modelValue)
if (this.familyCustomLocal === null && !this.isInvalidFamily(this.modelValue?.family)) {
this.familyCustomLocal = this.modelValue?.family
}
},
methods: { methods: {
lookupLocalFonts () {
if (!this.fontsList) {
this.$store.dispatch('queryLocalFonts')
}
this.toggleManualEntry()
},
isInvalidFamily (value) {
return PRESET_FONTS.has(value) || (value === '')
},
toggleManualEntry () { toggleManualEntry () {
this.manualEntry = !this.manualEntry this.manualEntry = !this.manualEntry
} }
}, },
computed: { computed: {
present () { present () {
return typeof this.localValue !== 'undefined' return typeof this.modelValue !== 'undefined'
}, },
defaultValue () { localFontsList () {
return this.localValue || this.fallback || {} return this.$store.state.interface.localFonts?.values()
}, },
fontsListCapable () { localFontsSize () {
return this.$store.state.interface.browserSupport.localFonts return this.$store.state.interface.localFonts?.size
},
fontsList () {
return this.$store.state.interface.localFonts
},
family: {
get () {
return this.defaultValue.family
},
set (v) {
this.familyCustomLocal = ''
set(this.localValue, 'family', v)
this.$emit('update:modelValue', this.localValue)
}
},
familyCustom: {
get () {
return this.familyCustomLocal
},
set (v) {
this.familyCustomLocal = v
if (!this.isInvalidFamily(v)) {
set(this.localValue, 'family', v)
this.$emit('update:modelValue', this.localValue)
}
}
},
invalidCustom () {
return this.isInvalidFamily(this.familyCustomLocal)
},
isCustom () {
return !PRESET_FONTS.has(this.defaultValue.family)
},
preset: {
get () {
if (PRESET_FONTS.has(this.family)) {
return this.family
} else {
return 'local'
}
},
set (v) {
this.family = v === 'local' ? '' : v
}
} }
} }
} }

View file

@ -10,42 +10,18 @@
> >
{{ label }} {{ label }}
</label> </label>
<p> {{ ' ' }}
<Select <Checkbox
:id="name + '-font-switcher'" v-if="typeof fallback !== 'undefined'"
v-model="preset" :id="name + '-o'"
:disabled="!present" :modelValue="present"
class="font-switcher" @change="$emit('update:modelValue', typeof modelValue === 'undefined' ? fallback : undefined)"
> >
<option {{ $t('settings.style.themes3.define') }}
v-for="option in availableOptions" </Checkbox>
:key="option" <p v-if="modelValue?.family">
:value="option"
>
{{ $t('settings.style.themes3.font.' + option) }}
</option>
</Select>
{{ ' ' }}
<Checkbox
v-if="typeof fallback !== 'undefined'"
:id="name + '-o'"
:modelValue="present"
@change="$emit('update:modelValue', typeof modelValue === 'undefined' ? fallback : undefined)"
>
{{ $t('settings.style.themes3.define') }}
</Checkbox>
</p>
<p v-if="isCustom">
<label <label
v-if="fontsList !== null && !manualEntry" v-if="manualEntry"
:id="name + '-label'"
:for="preset === 'custom' ? name : name + '-font-switcher'"
class="label"
>
{{ $t('settings.style.themes3.font.select') }}
</label>
<label
v-else
:id="name + '-label'" :id="name + '-label'"
:for="preset === 'custom' ? name : name + '-font-switcher'" :for="preset === 'custom' ? name : name + '-font-switcher'"
class="label" class="label"
@ -59,12 +35,22 @@
</template> </template>
</i18n-t> </i18n-t>
</label> </label>
<label
v-else
:id="name + '-label'"
:for="preset === 'custom' ? name : name + '-font-switcher'"
class="label"
>
{{ $t('settings.style.themes3.font.select') }}
</label>
{{ ' ' }} {{ ' ' }}
<span class="btn-group"> <span
v-if="manualEntry"
class="btn-group"
>
<button <button
v-if="fontsListCapable && (fontsList === null || manualEntry)"
class="btn button-default" class="btn button-default"
@click="lookupLocalFonts" @click="toggleManualEntry"
:title="$t('settings.style.themes3.font.lookup_local_fonts')" :title="$t('settings.style.themes3.font.lookup_local_fonts')"
> >
<FAIcon <FAIcon
@ -72,17 +58,19 @@
icon="font" icon="font"
/> />
</button> </button>
<input <input
v-if="fontsLists === null || manualEntry" :id="name"
:id="name" :model-value="modelValue.family"
v-model="familyCustom" class="input custom-font"
class="input custom-font" type="text"
type="text" @update:modelValue="$emit('update:modelValue', { ...(modelValue || {}), family: $event.target.value })"
> >
</span> </span>
<span class="btn-group"> <span
v-else
class="btn-group"
>
<button <button
v-if="fontsList !== null && !manualEntry"
class="btn button-default" class="btn button-default"
@click="toggleManualEntry" @click="toggleManualEntry"
:title="$t('settings.style.themes3.font.enter_manually')" :title="$t('settings.style.themes3.font.enter_manually')"
@ -93,40 +81,49 @@
/> />
</button> </button>
<Select <Select
v-if="fontsList !== null && !manualEntry"
:id="name + '-local-font-switcher'" :id="name + '-local-font-switcher'"
v-model="familyCustom" :model-value="modelValue.family"
class="custom-font" class="custom-font"
@update:modelValue="$emit('update:modelValue', { ...(modelValue || {}), family: $event.target.value })"
> >
<option <optgroup
v-for="option in fontsList.values()" :label="$t('settings.style.themes3.font.group-builtin')"
:key="option"
:value="option"
:style="{ fontFamily: option }"
> >
{{ option }} <option
</option> v-for="option in availableOptions"
:key="option"
:value="option"
:style="{ fontFamily: option === 'inherit' ? null : option }"
>
{{ $t('settings.style.themes3.font.builtin.' + option) }}
</option>
</optgroup>
<optgroup
v-if="localFontsSize > 0"
:label="$t('settings.style.themes3.font.group-local')"
>
<option
v-for="option in localFontsList"
:key="option"
:value="option"
:style="{ fontFamily: option }"
>
{{ option }}
</option>
</optgroup>
<optgroup
v-else
:label="$t('settings.style.themes3.font.group-local')"
>
<option disabled>
{{ $t('settings.style.themes3.font.local-unavailable1') }}
</option>
<option disabled>
{{ $t('settings.style.themes3.font.local-unavailable2') }}
</option>
</optgroup>
</Select> </Select>
</span> </span>
<span
v-if="invalidCustom"
class="InvalidIndicator"
>
<Popover
trigger="hover"
:trigger-attrs="{ 'aria-label': $t('settings.style.themes3.font.invalid_custom_reserved') }"
>
<template #trigger>
&nbsp;
<FAIcon icon="exclamation-triangle" />
</template>
<template #content>
<div class="invalid-tooltip">
{{ $t('settings.style.themes3.font.invalid_custom_reserved') }}
</div>
</template>
</Popover>
</span>
</p> </p>
</div> </div>
</template> </template>

View file

@ -4,6 +4,8 @@ import IntegerSetting from '../helpers/integer_setting.vue'
import FloatSetting from '../helpers/float_setting.vue' import FloatSetting from '../helpers/float_setting.vue'
import UnitSetting, { defaultHorizontalUnits } from '../helpers/unit_setting.vue' import UnitSetting, { defaultHorizontalUnits } from '../helpers/unit_setting.vue'
import FontControl from 'src/components/font_control/font_control.vue'
import SharedComputedObject from '../helpers/shared_computed_object.js' import SharedComputedObject from '../helpers/shared_computed_object.js'
import ProfileSettingIndicator from '../helpers/profile_setting_indicator.vue' import ProfileSettingIndicator from '../helpers/profile_setting_indicator.vue'
import { library } from '@fortawesome/fontawesome-svg-core' import { library } from '@fortawesome/fontawesome-svg-core'
@ -36,12 +38,16 @@ const AppearanceTab = {
IntegerSetting, IntegerSetting,
FloatSetting, FloatSetting,
UnitSetting, UnitSetting,
ProfileSettingIndicator ProfileSettingIndicator,
FontControl
}, },
computed: { computed: {
horizontalUnits () { horizontalUnits () {
return defaultHorizontalUnits return defaultHorizontalUnits
}, },
fontsOverride () {
return this.$store.getters.mergedConfig.fontsOverride
},
columns () { columns () {
const mode = this.$store.getters.mergedConfig.thirdColumnMode const mode = this.$store.getters.mergedConfig.thirdColumnMode

View file

@ -34,6 +34,51 @@
</small> </small>
</div> </div>
</li> </li>
<li>
<h3>{{ $t('settings.style.interface_font_user_override') }}</h3>
<ul class="setting-list">
<li>
<FontControl
:model-value="fontsOverride.interface"
name="ui"
:label="$t('settings.style.fonts.components.interface')"
:fallback="{ family: 'sans-serif' }"
no-inherit="1"
@update:modelValue="v => $store.dispatch('setOption', { name: 'fontsOverride', value: { ...fontsOverride, interface: v } })"
/>
</li>
<li>
<FontControl
v-if="expertLevel > 0"
:model-value="fontsOverride.input"
name="input"
:fallback="{ family: 'inherit' }"
:label="$t('settings.style.fonts.components.input')"
@update:modelValue="v => $store.dispatch('setOption', { name: 'fontsOverride', value: { ...fontsOverride, input: v } })"
/>
</li>
<li>
<FontControl
v-if="expertLevel > 0"
:model-value="fontsOverride.post"
name="post"
:fallback="{ family: 'inherit' }"
:label="$t('settings.style.fonts.components.post')"
@update:modelValue="v => $store.dispatch('setOption', { name: 'fontsOverride', value: { ...fontsOverride, post: v } })"
/>
</li>
<li>
<FontControl
v-if="expertLevel > 0"
:model-value="fontsOverride.postCode"
name="postCode"
:fallback="{ family: 'monospace' }"
:label="$t('settings.style.fonts.components.postCode')"
@update:modelValue="v => $store.dispatch('setOption', { name: 'fontsOverride', value: { ...fontsOverride, postCode: v } })"
/>
</li>
</ul>
</li>
<li> <li>
<UnitSetting <UnitSetting
path="emojiSize" path="emojiSize"

View file

@ -748,19 +748,24 @@
"themes3": { "themes3": {
"define": "Override", "define": "Override",
"font": { "font": {
"local": "Local font (must be installed on computer)", "group-builtin": "Browser default fonts",
"serif": "Serif (browser default)", "builtin" : {
"sans-serif": "Sans-serif (browser default)", "serif": "Serif",
"monospace": "Monospace (browser default)", "sans-serif": "Sans-serif",
"inherit": "Same as parent component", "monospace": "Monospace",
"invalid_custom_reserved": "Empty or reserved font name, it will not be saved as custom font - use dropdown instead", "inherit": "Unchanged"
},
"group-local": "Locally installed fonts",
"local-unavailable1": "List of locally installed fonts unavailalbe",
"local-unavailable2": "Use manual entry to specify custom font",
"font_list_unavailable": "Couldn't get locally installed fonts: {error}", "font_list_unavailable": "Couldn't get locally installed fonts: {error}",
"lookup_local_fonts": "Load list of fonts installed on this computer", "lookup_local_fonts": "Load list of fonts installed on this computer",
"enter_manually": "Enter font name family manually", "enter_manually": "Enter font name family manually",
"entry": "Font's {fontFamily}", "entry": "Enter {fontFamily}",
"select": "Select local font" "select": "Select font"
} }
}, },
"interface_font_user_override": "Override theme/browser font used",
"switcher": { "switcher": {
"keep_color": "Keep colors", "keep_color": "Keep colors",
"keep_shadows": "Keep shadows", "keep_shadows": "Keep shadows",

View file

@ -121,6 +121,7 @@ export const defaultState = {
navbarSize: undefined, // instance default navbarSize: undefined, // instance default
panelHeaderSize: undefined, // instance default panelHeaderSize: undefined, // instance default
forcedRoundness: undefined, // instance default forcedRoundness: undefined, // instance default
fontsOverride: undefined, // instance default
navbarColumnStretch: false, navbarColumnStretch: false,
greentext: undefined, // instance default greentext: undefined, // instance default
useAtIcon: undefined, // instance default useAtIcon: undefined, // instance default
@ -184,6 +185,7 @@ const config = {
applyConfig(state) applyConfig(state)
}, },
setOption (state, { name, value }) { setOption (state, { name, value }) {
console.log('SET OPTION', state, name, value)
set(state, name, value) set(state, name, value)
}, },
setHighlight (state, { user, color, type }) { setHighlight (state, { user, color, type }) {

View file

@ -104,6 +104,7 @@ const defaultState = {
navbarSize: '3.5rem', navbarSize: '3.5rem',
panelHeaderSize: '3.2rem', panelHeaderSize: '3.2rem',
forcedRoundness: -1, forcedRoundness: -1,
fontsOverride: {},
virtualScrolling: true, virtualScrolling: true,
sensitiveByDefault: false, sensitiveByDefault: false,
conversationDisplay: 'linear', conversationDisplay: 'linear',

View file

@ -108,7 +108,6 @@ const interfaceMod = {
state.lastTimeline = value state.lastTimeline = value
}, },
setFontsList (state, value) { setFontsList (state, value) {
console.log(value)
state.localFonts = new Set(value.map(font => font.family)) state.localFonts = new Set(value.map(font => font.family))
} }
}, },
@ -184,10 +183,16 @@ const interfaceMod = {
commit('setLayoutType', wideLayout ? 'wide' : normalOrMobile) commit('setLayoutType', wideLayout ? 'wide' : normalOrMobile)
} }
}, },
queryLocalFonts ({ commit, dispatch }) { queryLocalFonts ({ commit, dispatch, state }) {
if (state.localFonts !== null) return
commit('setFontsList', [])
if (!state.browserSupport.localFonts) {
return
}
window window
.queryLocalFonts() .queryLocalFonts()
.then((fonts) => { .then((fonts) => {
console.log(fonts)
commit('setFontsList', fonts) commit('setFontsList', fonts)
}) })
.catch((e) => { .catch((e) => {