diff options
Diffstat (limited to 'users/ryan/modules/simple-bar/simple-bar-source/lib/components/data/sound.jsx')
| -rwxr-xr-x | users/ryan/modules/simple-bar/simple-bar-source/lib/components/data/sound.jsx | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/users/ryan/modules/simple-bar/simple-bar-source/lib/components/data/sound.jsx b/users/ryan/modules/simple-bar/simple-bar-source/lib/components/data/sound.jsx index 7301426..a3c5cab 100755 --- a/users/ryan/modules/simple-bar/simple-bar-source/lib/components/data/sound.jsx +++ b/users/ryan/modules/simple-bar/simple-bar-source/lib/components/data/sound.jsx | |||
| @@ -58,7 +58,7 @@ export const Widget = React.memo(() => { | |||
| 58 | `osascript -e 'set v to get volume settings' -e 'output volume of v & output muted of v'`, | 58 | `osascript -e 'set v to get volume settings' -e 'output volume of v & output muted of v'`, |
| 59 | refresh, | 59 | refresh, |
| 60 | ); | 60 | ); |
| 61 | const parts = Utils.cleanupOutput(output).split(","); | 61 | const parts = Utils.cleanupOutput(output).split(", "); |
| 62 | setState({ | 62 | setState({ |
| 63 | volume: parts[0], | 63 | volume: parts[0], |
| 64 | muted: parts[1], | 64 | muted: parts[1], |
| @@ -71,11 +71,6 @@ export const Widget = React.memo(() => { | |||
| 71 | // Refresh the widget at the specified interval. | 71 | // Refresh the widget at the specified interval. |
| 72 | useWidgetRefresh(visible, getSound, refresh); | 72 | useWidgetRefresh(visible, getSound, refresh); |
| 73 | 73 | ||
| 74 | // Update the sound settings when dragging ends. | ||
| 75 | React.useEffect(() => { | ||
| 76 | if (!dragging) setSound(volume); | ||
| 77 | }, [dragging, volume]); | ||
| 78 | |||
| 79 | // Update the volume state when the fetched volume changes. | 74 | // Update the volume state when the fetched volume changes. |
| 80 | React.useEffect(() => { | 75 | React.useEffect(() => { |
| 81 | setVolume((currentVolume) => { | 76 | setVolume((currentVolume) => { |
| @@ -106,8 +101,14 @@ export const Widget = React.memo(() => { | |||
| 106 | setVolume(value); | 101 | setVolume(value); |
| 107 | }; | 102 | }; |
| 108 | 103 | ||
| 109 | const onMouseDown = () => setDragging(true); | 104 | const onInteractionEnd = (e) => { |
| 110 | const onMouseUp = () => setDragging(false); | 105 | setDragging(false); |
| 106 | const finalVolume = parseInt(e.target.value, 10); | ||
| 107 | setSound(finalVolume); | ||
| 108 | }; | ||
| 109 | |||
| 110 | // const onMouseDown = () => setDragging(true); | ||
| 111 | // const onMouseUp = () => setDragging(false); | ||
| 111 | 112 | ||
| 112 | const formattedVolume = `${volume.toString().padStart(2, "0")}%`; | 113 | const formattedVolume = `${volume.toString().padStart(2, "0")}%`; |
| 113 | 114 | ||
| @@ -133,8 +134,9 @@ export const Widget = React.memo(() => { | |||
| 133 | step="1" | 134 | step="1" |
| 134 | value={volume} | 135 | value={volume} |
| 135 | className="sound__slider" | 136 | className="sound__slider" |
| 136 | onMouseDown={onMouseDown} | 137 | onMouseDown={() => setDragging(true)} |
| 137 | onMouseUp={onMouseUp} | 138 | onMouseUp={onInteractionEnd} |
| 139 | onKeyUp={onInteractionEnd} | ||
| 138 | onChange={onChange} | 140 | onChange={onChange} |
| 139 | /> | 141 | /> |
| 140 | </div> | 142 | </div> |
