From 18778db7c3592433e0ef17eacd284b942963733e Mon Sep 17 00:00:00 2001 From: loucass003 Date: Mon, 3 Feb 2025 00:13:16 +0100 Subject: [PATCH 1/4] Change reset sounds so you have clues at the begining and end of the reset action --- gui/src/components/home/ResetButton.tsx | 19 ++++++++++++++----- gui/src/hooks/app.ts | 8 ++++++-- gui/src/sounds/{sounds.tsx => sounds.ts} | 6 +++++- 3 files changed, 25 insertions(+), 8 deletions(-) rename gui/src/sounds/{sounds.tsx => sounds.ts} (92%) diff --git a/gui/src/components/home/ResetButton.tsx b/gui/src/components/home/ResetButton.tsx index 65c60ed4e7..237ba6e331 100644 --- a/gui/src/components/home/ResetButton.tsx +++ b/gui/src/components/home/ResetButton.tsx @@ -9,7 +9,10 @@ import { import { useConfig } from '@/hooks/config'; import { useCountdown } from '@/hooks/countdown'; import { useWebsocketAPI } from '@/hooks/websocket-api'; -import { playSoundOnResetStarted } from '@/sounds/sounds'; +import { + playSoundOnResetEnded, + playSoundOnResetStarted, +} from '@/sounds/sounds'; import { BigButton } from '@/components/commons/BigButton'; import { Button } from '@/components/commons/Button'; import { @@ -51,6 +54,7 @@ export function ResetButton({ const { isCounting, startCountdown, timer } = useCountdown({ duration: type === ResetType.Yaw ? 0.2 : undefined, onCountdownEnd: () => { + maybePlaySoundOnResetEnd(type); reset(); if (onReseted) onReseted(); }, @@ -77,9 +81,14 @@ export function ResetButton({ return ; }; - const maybePlaySoundOnResetStarted = (type: ResetType) => { + const maybePlaySoundOnResetEnd = (type: ResetType) => { + if (!config?.feedbackSound) return; + playSoundOnResetEnded(type, config?.feedbackSoundVolume); + }; + + const maybePlaySoundOnResetStart = () => { if (!config?.feedbackSound) return; - playSoundOnResetStarted(type, config?.feedbackSoundVolume); + playSoundOnResetStarted(config?.feedbackSoundVolume); }; return variant === 'small' ? ( @@ -87,7 +96,7 @@ export function ResetButton({ icon={getIcon()} onClick={() => { startCountdown(); - maybePlaySoundOnResetStarted(type); + maybePlaySoundOnResetStart(); }} variant="primary" disabled={isCounting || needsFullReset} @@ -103,7 +112,7 @@ export function ResetButton({ icon={getIcon()} onClick={() => { startCountdown(); - maybePlaySoundOnResetStarted(type); + maybePlaySoundOnResetStart(); }} disabled={isCounting || needsFullReset} > diff --git a/gui/src/hooks/app.ts b/gui/src/hooks/app.ts index 5421641d7d..ac6bd7de8a 100644 --- a/gui/src/hooks/app.ts +++ b/gui/src/hooks/app.ts @@ -19,7 +19,7 @@ import { StartDataFeedT, TrackerDataT, } from 'solarxr-protocol'; -import { playSoundOnResetStarted } from '@/sounds/sounds'; +import { playSoundOnResetEnded, playSoundOnResetStarted } from '@/sounds/sounds'; import { useConfig } from './config'; import { useDataFeedConfig } from './datafeed-config'; import { useWebsocketAPI } from './websocket-api'; @@ -118,7 +118,11 @@ export function useProvideAppContext(): AppContext { try { switch (status) { case ResetStatus.STARTED: { - playSoundOnResetStarted(resetType, config?.feedbackSoundVolume); + playSoundOnResetStarted(config?.feedbackSoundVolume); + break; + } + case ResetStatus.FINISHED: { + playSoundOnResetEnded(resetType, config?.feedbackSoundVolume); break; } } diff --git a/gui/src/sounds/sounds.tsx b/gui/src/sounds/sounds.ts similarity index 92% rename from gui/src/sounds/sounds.tsx rename to gui/src/sounds/sounds.ts index fbc6da1816..7fe00c2a50 100644 --- a/gui/src/sounds/sounds.tsx +++ b/gui/src/sounds/sounds.ts @@ -41,7 +41,7 @@ function restartAndPlay(audio: HTMLAudioElement, volume: number) { } } -export function playSoundOnResetStarted(resetType: ResetType, volume = 1) { +export function playSoundOnResetEnded(resetType: ResetType, volume = 1) { switch (resetType) { case ResetType.Yaw: { restartAndPlay(quickResetStartedSound, volume); @@ -58,6 +58,10 @@ export function playSoundOnResetStarted(resetType: ResetType, volume = 1) { } } +export function playSoundOnResetStarted(volume = 1) { + restartAndPlay(tapSetupSound1, volume); +} + let lastKnownVolume = 1; /* Easter egg */ tapSetupSoundEnd.onended = () => { From d63587fcd1a4d80917e6377e59a564ea5cfb3cc4 Mon Sep 17 00:00:00 2001 From: loucass003 Date: Mon, 3 Feb 2025 00:17:26 +0100 Subject: [PATCH 2/4] lint --- gui/src/sounds/sounds.ts | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/gui/src/sounds/sounds.ts b/gui/src/sounds/sounds.ts index 7fe00c2a50..49fb30b8b1 100644 --- a/gui/src/sounds/sounds.ts +++ b/gui/src/sounds/sounds.ts @@ -10,24 +10,12 @@ const fullResetStartedSound = new Audio( const mountingResetStartedSound = new Audio( await fetchResourceUrl('/sounds/mounting-reset-started-sound.mp3') ); -const tapSetupSound1 = new Audio( - await fetchResourceUrl('/sounds/first-tap.mp3') -); -const tapSetupSound2 = new Audio( - await fetchResourceUrl('/sounds/second-tap.mp3') -); -const tapSetupSound3 = new Audio( - await fetchResourceUrl('/sounds/third-tap.mp3') -); -const tapSetupSound4 = new Audio( - await fetchResourceUrl('/sounds/fourth-tap.mp3') -); -const tapSetupSound5 = new Audio( - await fetchResourceUrl('/sounds/fifth-tap.mp3') -); -const tapSetupSoundEnd = new Audio( - await fetchResourceUrl('/sounds/end-tap.mp3') -); +const tapSetupSound1 = new Audio(await fetchResourceUrl('/sounds/first-tap.mp3')); +const tapSetupSound2 = new Audio(await fetchResourceUrl('/sounds/second-tap.mp3')); +const tapSetupSound3 = new Audio(await fetchResourceUrl('/sounds/third-tap.mp3')); +const tapSetupSound4 = new Audio(await fetchResourceUrl('/sounds/fourth-tap.mp3')); +const tapSetupSound5 = new Audio(await fetchResourceUrl('/sounds/fifth-tap.mp3')); +const tapSetupSoundEnd = new Audio(await fetchResourceUrl('/sounds/end-tap.mp3')); const tapSetupExtraSound = new Audio( await fetchResourceUrl('/sounds/tapextrasetup.mp3') ); From 256545ab622dfbc265000d9d25829842be6aa97e Mon Sep 17 00:00:00 2001 From: loucass003 Date: Mon, 3 Feb 2025 00:21:05 +0100 Subject: [PATCH 3/4] Revert "Change reset sounds so you have clues at the begining and end of the reset action" This reverts commit 18778db7c3592433e0ef17eacd284b942963733e. --- gui/src/components/home/ResetButton.tsx | 19 +++++-------------- gui/src/hooks/app.ts | 8 ++------ gui/src/sounds/{sounds.ts => sounds.tsx} | 6 +----- 3 files changed, 8 insertions(+), 25 deletions(-) rename gui/src/sounds/{sounds.ts => sounds.tsx} (92%) diff --git a/gui/src/components/home/ResetButton.tsx b/gui/src/components/home/ResetButton.tsx index 237ba6e331..65c60ed4e7 100644 --- a/gui/src/components/home/ResetButton.tsx +++ b/gui/src/components/home/ResetButton.tsx @@ -9,10 +9,7 @@ import { import { useConfig } from '@/hooks/config'; import { useCountdown } from '@/hooks/countdown'; import { useWebsocketAPI } from '@/hooks/websocket-api'; -import { - playSoundOnResetEnded, - playSoundOnResetStarted, -} from '@/sounds/sounds'; +import { playSoundOnResetStarted } from '@/sounds/sounds'; import { BigButton } from '@/components/commons/BigButton'; import { Button } from '@/components/commons/Button'; import { @@ -54,7 +51,6 @@ export function ResetButton({ const { isCounting, startCountdown, timer } = useCountdown({ duration: type === ResetType.Yaw ? 0.2 : undefined, onCountdownEnd: () => { - maybePlaySoundOnResetEnd(type); reset(); if (onReseted) onReseted(); }, @@ -81,14 +77,9 @@ export function ResetButton({ return ; }; - const maybePlaySoundOnResetEnd = (type: ResetType) => { - if (!config?.feedbackSound) return; - playSoundOnResetEnded(type, config?.feedbackSoundVolume); - }; - - const maybePlaySoundOnResetStart = () => { + const maybePlaySoundOnResetStarted = (type: ResetType) => { if (!config?.feedbackSound) return; - playSoundOnResetStarted(config?.feedbackSoundVolume); + playSoundOnResetStarted(type, config?.feedbackSoundVolume); }; return variant === 'small' ? ( @@ -96,7 +87,7 @@ export function ResetButton({ icon={getIcon()} onClick={() => { startCountdown(); - maybePlaySoundOnResetStart(); + maybePlaySoundOnResetStarted(type); }} variant="primary" disabled={isCounting || needsFullReset} @@ -112,7 +103,7 @@ export function ResetButton({ icon={getIcon()} onClick={() => { startCountdown(); - maybePlaySoundOnResetStart(); + maybePlaySoundOnResetStarted(type); }} disabled={isCounting || needsFullReset} > diff --git a/gui/src/hooks/app.ts b/gui/src/hooks/app.ts index ac6bd7de8a..5421641d7d 100644 --- a/gui/src/hooks/app.ts +++ b/gui/src/hooks/app.ts @@ -19,7 +19,7 @@ import { StartDataFeedT, TrackerDataT, } from 'solarxr-protocol'; -import { playSoundOnResetEnded, playSoundOnResetStarted } from '@/sounds/sounds'; +import { playSoundOnResetStarted } from '@/sounds/sounds'; import { useConfig } from './config'; import { useDataFeedConfig } from './datafeed-config'; import { useWebsocketAPI } from './websocket-api'; @@ -118,11 +118,7 @@ export function useProvideAppContext(): AppContext { try { switch (status) { case ResetStatus.STARTED: { - playSoundOnResetStarted(config?.feedbackSoundVolume); - break; - } - case ResetStatus.FINISHED: { - playSoundOnResetEnded(resetType, config?.feedbackSoundVolume); + playSoundOnResetStarted(resetType, config?.feedbackSoundVolume); break; } } diff --git a/gui/src/sounds/sounds.ts b/gui/src/sounds/sounds.tsx similarity index 92% rename from gui/src/sounds/sounds.ts rename to gui/src/sounds/sounds.tsx index 49fb30b8b1..5195b41c6d 100644 --- a/gui/src/sounds/sounds.ts +++ b/gui/src/sounds/sounds.tsx @@ -29,7 +29,7 @@ function restartAndPlay(audio: HTMLAudioElement, volume: number) { } } -export function playSoundOnResetEnded(resetType: ResetType, volume = 1) { +export function playSoundOnResetStarted(resetType: ResetType, volume = 1) { switch (resetType) { case ResetType.Yaw: { restartAndPlay(quickResetStartedSound, volume); @@ -46,10 +46,6 @@ export function playSoundOnResetEnded(resetType: ResetType, volume = 1) { } } -export function playSoundOnResetStarted(volume = 1) { - restartAndPlay(tapSetupSound1, volume); -} - let lastKnownVolume = 1; /* Easter egg */ tapSetupSoundEnd.onended = () => { From 2cfda2272d9cee9009068ac0352d6946039aaef3 Mon Sep 17 00:00:00 2001 From: loucass003 Date: Mon, 3 Feb 2025 00:21:27 +0100 Subject: [PATCH 4/4] Revert "lint" This reverts commit d63587fcd1a4d80917e6377e59a564ea5cfb3cc4. --- gui/src/sounds/sounds.tsx | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/gui/src/sounds/sounds.tsx b/gui/src/sounds/sounds.tsx index 5195b41c6d..fbc6da1816 100644 --- a/gui/src/sounds/sounds.tsx +++ b/gui/src/sounds/sounds.tsx @@ -10,12 +10,24 @@ const fullResetStartedSound = new Audio( const mountingResetStartedSound = new Audio( await fetchResourceUrl('/sounds/mounting-reset-started-sound.mp3') ); -const tapSetupSound1 = new Audio(await fetchResourceUrl('/sounds/first-tap.mp3')); -const tapSetupSound2 = new Audio(await fetchResourceUrl('/sounds/second-tap.mp3')); -const tapSetupSound3 = new Audio(await fetchResourceUrl('/sounds/third-tap.mp3')); -const tapSetupSound4 = new Audio(await fetchResourceUrl('/sounds/fourth-tap.mp3')); -const tapSetupSound5 = new Audio(await fetchResourceUrl('/sounds/fifth-tap.mp3')); -const tapSetupSoundEnd = new Audio(await fetchResourceUrl('/sounds/end-tap.mp3')); +const tapSetupSound1 = new Audio( + await fetchResourceUrl('/sounds/first-tap.mp3') +); +const tapSetupSound2 = new Audio( + await fetchResourceUrl('/sounds/second-tap.mp3') +); +const tapSetupSound3 = new Audio( + await fetchResourceUrl('/sounds/third-tap.mp3') +); +const tapSetupSound4 = new Audio( + await fetchResourceUrl('/sounds/fourth-tap.mp3') +); +const tapSetupSound5 = new Audio( + await fetchResourceUrl('/sounds/fifth-tap.mp3') +); +const tapSetupSoundEnd = new Audio( + await fetchResourceUrl('/sounds/end-tap.mp3') +); const tapSetupExtraSound = new Audio( await fetchResourceUrl('/sounds/tapextrasetup.mp3') );