FIX: Debounce key LED colors
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="font-heading mx-2 flex rounded-b-lg border-x border-b border-zinc-800 p-4"
|
class="font-heading mx-2 flex rounded-b-lg border-x border-b border-zinc-800 p-4 transition-colors"
|
||||||
:class="{ 'rounded-t-lg': roundedTop }"
|
:class="{ 'rounded-t-lg': roundedTop }"
|
||||||
:style="{ backgroundColor: color.hex() }"
|
:style="{ backgroundColor: color.hex() }"
|
||||||
>
|
>
|
||||||
@@ -186,6 +186,7 @@ import Color from 'color'
|
|||||||
import { SliderRoot, SliderThumb, SliderTrack } from 'radix-vue'
|
import { SliderRoot, SliderThumb, SliderTrack } from 'radix-vue'
|
||||||
import { MoreHorizontal } from 'lucide-vue-next'
|
import { MoreHorizontal } from 'lucide-vue-next'
|
||||||
import { Separator } from '@renderer/components/ui/separator'
|
import { Separator } from '@renderer/components/ui/separator'
|
||||||
|
import { useDebounceFn } from '@vueuse/core'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
colorNumber: {
|
colorNumber: {
|
||||||
@@ -202,6 +203,17 @@ const emit = defineEmits(['input'])
|
|||||||
|
|
||||||
const previousColor = ref(Color(props.colorNumber))
|
const previousColor = ref(Color(props.colorNumber))
|
||||||
|
|
||||||
|
const updateColor = useDebounceFn(
|
||||||
|
(newColor) => {
|
||||||
|
if (newColor.rgbNumber() !== color.value.rgbNumber()) {
|
||||||
|
previousColor.value = newColor
|
||||||
|
emit('input', newColor.rgbNumber())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
20,
|
||||||
|
{ maxWait: 30 }
|
||||||
|
)
|
||||||
|
|
||||||
const color = computed({
|
const color = computed({
|
||||||
get() {
|
get() {
|
||||||
if (previousColor.value.rgbNumber() === props.colorNumber) {
|
if (previousColor.value.rgbNumber() === props.colorNumber) {
|
||||||
@@ -210,10 +222,7 @@ const color = computed({
|
|||||||
return Color(props.colorNumber)
|
return Color(props.colorNumber)
|
||||||
},
|
},
|
||||||
set(newColor) {
|
set(newColor) {
|
||||||
if (newColor.rgbNumber() !== color.value.rgbNumber()) {
|
updateColor(newColor)
|
||||||
previousColor.value = newColor
|
|
||||||
emit('input', newColor.rgbNumber())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
<button
|
<button
|
||||||
v-for="(option, key) in options"
|
v-for="(option, key) in options"
|
||||||
:key="key"
|
:key="key"
|
||||||
class="h-6 flex-1"
|
class="h-6 flex-1 transition-colors"
|
||||||
:class="{ 'color-tab': currentOption === key }"
|
:class="{ 'color-tab': currentOption === key }"
|
||||||
:style="{ background: Color(option.colorNumber).hex() }"
|
:style="{ background: Color(option.colorNumber).hex() }"
|
||||||
@click="currentOption = key"
|
@click="currentOption = key"
|
||||||
@@ -86,6 +86,8 @@ onBeforeMount(() => {
|
|||||||
width: var(--rounded);
|
width: var(--rounded);
|
||||||
height: var(--rounded);
|
height: var(--rounded);
|
||||||
content: ' ';
|
content: ' ';
|
||||||
|
transition: box-shadow 150ms;
|
||||||
|
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.color-tab:before {
|
.color-tab:before {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
|
import { useDebounceFn } from '@vueuse/core'
|
||||||
|
|
||||||
interface Profile {
|
interface Profile {
|
||||||
version: number
|
version: number
|
||||||
@@ -194,7 +195,7 @@ export const useDeviceStore = defineStore('device', {
|
|||||||
const propertyName = `button${key.toUpperCase()}${pressed ? 'Press' : 'Idle'}`
|
const propertyName = `button${key.toUpperCase()}${pressed ? 'Press' : 'Idle'}`
|
||||||
this.currentProfile![propertyName] = color
|
this.currentProfile![propertyName] = color
|
||||||
if (updateDevice) {
|
if (updateDevice) {
|
||||||
nanoIpc.send(
|
sendDebounced(
|
||||||
this.currentDeviceId!,
|
this.currentDeviceId!,
|
||||||
JSON.stringify({ profile: this.currentProfileName, updates: { [propertyName]: color } })
|
JSON.stringify({ profile: this.currentProfileName, updates: { [propertyName]: color } })
|
||||||
)
|
)
|
||||||
@@ -203,6 +204,10 @@ export const useDeviceStore = defineStore('device', {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const sendDebounced = useDebounceFn((deviceid, jsonstr) => nanoIpc.send(deviceid, jsonstr), 20, {
|
||||||
|
maxWait: 30
|
||||||
|
})
|
||||||
|
|
||||||
export const initializeDevices = () => {
|
export const initializeDevices = () => {
|
||||||
const deviceStore = useDeviceStore()
|
const deviceStore = useDeviceStore()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user