mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 21:12:49 +08:00
fix(web): keep the volume slider draggable under the per-frame progress loop (#111)
The 60fps requestAnimationFrame progress clock (#107) re-renders the player every ~16ms, and Vue re-applied `el.value = storeVolume` on a range input each time — snapping the thumb back to the stale store value mid-drag (un-draggable on desktop, janky on mobile). Extract the decoupling into a useDecoupledSlider composable used by both the desktop (Player.vue) and mobile (App.vue) sliders: a local display ref tracks the native drag via @input (so the bound value always matches the element), the store is committed only on @change (release), and an onRelease safety-net (pointerup/pointercancel/blur) clears the dragging guard even when the browser skips `change` (value released at its start point). External/store changes still flow into the display except while dragging. Adds a regression test for the no-snap-back invariant. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
4cb1da29d4
commit
5ae5168b6b
4 files changed
+187
-14
No files matched your search
+19
-9
@@ -44,11 +44,15 @@
|
||||
type="range"
|
||||
min="0"
|
||||
max="100"
|
||||
:value="mobileVolume"
|
||||
:value="mobileVolumeDisplay"
|
||||
class="m-volume-slider"
|
||||
@input="onMobileVolumeChange"
|
||||
@input="onMobileVolumeInput"
|
||||
@change="onMobileVolumeCommit"
|
||||
@pointerup="onMobileVolumeRelease"
|
||||
@pointercancel="onMobileVolumeRelease"
|
||||
@blur="onMobileVolumeRelease"
|
||||
/>
|
||||
<span class="m-volume-value">{{ mobileVolume }}</span>
|
||||
<span class="m-volume-value">{{ mobileVolumeDisplay }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -79,6 +83,7 @@ import { computed, onMounted, onUnmounted, ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { Icon } from '@iconify/vue';
|
||||
import { usePlayerStore } from './stores/player.js';
|
||||
import { useDecoupledSlider } from './composables/useDecoupledSlider.js';
|
||||
import { useWebSocket } from './composables/useWebSocket.js';
|
||||
import { useSession } from './composables/useSession.js';
|
||||
import Navbar from './components/Navbar.vue';
|
||||
@@ -99,7 +104,17 @@ const route = useRoute();
|
||||
const router = useRouter();
|
||||
const { connect } = useWebSocket();
|
||||
const currentSong = computed(() => playerStore.currentSong);
|
||||
const mobileVolume = computed(() => playerStore.activeBot?.volume ?? 75);
|
||||
// Volume slider decoupled from the 60fps updateMobileProgress() rAF re-render
|
||||
// so it isn't reset mid-drag (#111 — same root cause as the desktop player).
|
||||
const {
|
||||
display: mobileVolumeDisplay,
|
||||
onInput: onMobileVolumeInput,
|
||||
onChange: onMobileVolumeCommit,
|
||||
onRelease: onMobileVolumeRelease,
|
||||
} = useDecoupledSlider(
|
||||
() => playerStore.activeBot?.volume,
|
||||
(v) => playerStore.setVolume(v)
|
||||
);
|
||||
const mobileMode = computed(() => playerStore.activeBot?.playMode ?? 'seq');
|
||||
const mobileModeOrder = ['seq', 'loop', 'random', 'rloop'];
|
||||
const mobileModeIcons: Record<string, string> = {
|
||||
@@ -126,11 +141,6 @@ function updateMobileProgress() {
|
||||
mobileRaf = requestAnimationFrame(updateMobileProgress);
|
||||
}
|
||||
|
||||
function onMobileVolumeChange(e: Event) {
|
||||
const volume = Number((e.target as HTMLInputElement).value);
|
||||
playerStore.setVolume(volume);
|
||||
}
|
||||
|
||||
function toggleMobileVolume() {
|
||||
mobileVolumeOpen.value = !mobileVolumeOpen.value;
|
||||
if (mobileVolumeOpen.value) mobileQueueOpen.value = false;
|
||||
|
||||
Reference in new issue
Block a user