ADD: Ring color configuration

This commit is contained in:
Robert Kossessa
2024-03-13 21:29:36 +01:00
parent bf286606d0
commit f91312c824
2 changed files with 74 additions and 18 deletions

View File

@@ -1,27 +1,58 @@
<template> <template>
<ConfigSection title="Ring Colors" :icon-component="Palette"> <ConfigSection title="Ring Colors" :icon-component="Palette">
<PaletteInput v-model="ringColors" /> <PaletteInput
ref="paletteInput"
:options="ringColors"
@input="
(optionKey, colorNumber) => {
ringColors = {
...ringColors,
[optionKey]: {
...ringColors[optionKey],
colorNumber
}
}
}
"
/>
</ConfigSection> </ConfigSection>
</template> </template>
<script setup> <script setup>
import { Palette } from 'lucide-vue-next' import { Palette } from 'lucide-vue-next'
import ConfigSection from '@renderer/components/common/ConfigSection.vue' import ConfigSection from '@renderer/components/common/ConfigSection.vue'
import PaletteInput from '@renderer/components/common/PaletteInput.vue' import PaletteInput from '@renderer/components/common/PaletteInput.vue'
import Color from 'color' import { useDeviceStore } from '@renderer/deviceStore'
import { ref } from 'vue' import { computed } from 'vue'
const ringColors = ref({ const deviceStore = useDeviceStore()
const ringColors = computed({
get() {
return {
primary: { primary: {
titleKey: 'config_options.light_designer.primary_color', titleKey: 'config_options.light_designer.primary_color',
color: Color('#8f9af2') colorNumber: deviceStore.currentProfile.primary
}, },
secondary: { secondary: {
titleKey: 'config_options.light_designer.secondary_color', titleKey: 'config_options.light_designer.secondary_color',
color: Color('#c06300') colorNumber: deviceStore.currentProfile.secondary
}, },
pointer: { pointer: {
titleKey: 'config_options.light_designer.pointer_color', titleKey: 'config_options.light_designer.pointer_color',
color: Color('#ffa346') colorNumber: deviceStore.currentProfile.pointer
}
}
},
set(newValue) {
if (newValue.primary.colorNumber !== deviceStore.currentProfile.primary) {
deviceStore.setPrimaryColor(newValue.primary.colorNumber)
}
if (newValue.secondary.colorNumber !== deviceStore.currentProfile.secondary) {
deviceStore.setSecondaryColor(newValue.secondary.colorNumber)
}
if (newValue.pointer.colorNumber !== deviceStore.currentProfile.pointer) {
deviceStore.setPointerColor(newValue.pointer.colorNumber)
}
} }
}) })
</script> </script>

View File

@@ -68,10 +68,8 @@ export const useDeviceStore = defineStore('device', {
}), }),
getters: { getters: {
connected: (state) => state.currentDeviceId !== null, connected: (state) => state.currentDeviceId !== null,
currentProfile: (state) => currentProfile: (state): Profile | null =>
state.currentProfileName state.profiles.find((profile) => profile.name === state.currentProfileName) || null,
? state.profiles.find((profile) => profile.name === state.currentProfileName)
: null,
profileTags: (state) => [...new Set(state.profiles.map((profile) => profile.profileTag))], profileTags: (state) => [...new Set(state.profiles.map((profile) => profile.profileTag))],
profilesByTag: (state) => profilesByTag: (state) =>
state.profiles.reduce((acc, profile) => { state.profiles.reduce((acc, profile) => {
@@ -204,6 +202,33 @@ export const useDeviceStore = defineStore('device', {
JSON.stringify({ profile: this.currentProfileName, updates: { [propertyName]: color } }) JSON.stringify({ profile: this.currentProfileName, updates: { [propertyName]: color } })
) )
} }
},
setPrimaryColor(color: number, updateDevice: boolean = true) {
this.currentProfile!.primary = color
if (updateDevice) {
sendDebounced(
this.currentDeviceId!,
JSON.stringify({ profile: this.currentProfileName, updates: { primary: color } })
)
}
},
setSecondaryColor(color: number, updateDevice: boolean = true) {
this.currentProfile!.secondary = color
if (updateDevice) {
sendDebounced(
this.currentDeviceId!,
JSON.stringify({ profile: this.currentProfileName, updates: { secondary: color } })
)
}
},
setPointerColor(color: number, updateDevice: boolean = true) {
this.currentProfile!.pointer = color
if (updateDevice) {
sendDebounced(
this.currentDeviceId!,
JSON.stringify({ profile: this.currentProfileName, updates: { pointer: color } })
)
}
} }
} }
}) })