Skip to content

Commit 8391111

Browse files
authored
Merge pull request #129 from RooVetGit/jq/sound-setting-improvements
Sound setting improvements
2 parents 3449033 + ca4806d commit 8391111

File tree

12 files changed

+486
-126
lines changed

12 files changed

+486
-126
lines changed

.changeset/eighty-nails-peel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"roo-cline": patch
3+
---
4+
5+
Add volume slider in settings and change sound effects to only trigger when user intervention is required, an error occurs, or a task is completed.

package-lock.json

Lines changed: 7 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@
216216
"os-name": "^6.0.0",
217217
"p-wait-for": "^5.0.2",
218218
"pdf-parse": "^1.1.1",
219-
"play-sound": "^1.1.6",
220219
"puppeteer-chromium-resolver": "^23.0.0",
221220
"puppeteer-core": "^23.4.0",
222221
"serialize-error": "^11.0.3",
222+
"sound-play": "^1.1.0",
223223
"strip-ansi": "^7.1.0",
224224
"tree-sitter-wasms": "^0.1.11",
225225
"turndown": "^7.2.0",

src/core/webview/ClineProvider.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { Cline } from "../Cline"
2222
import { openMention } from "../mentions"
2323
import { getNonce } from "./getNonce"
2424
import { getUri } from "./getUri"
25-
import { playSound, setSoundEnabled } from "../../utils/sound"
25+
import { playSound, setSoundEnabled, setSoundVolume } from "../../utils/sound"
2626

2727
/*
2828
https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
@@ -66,6 +66,7 @@ type GlobalStateKey =
6666
| "openRouterUseMiddleOutTransform"
6767
| "allowedCommands"
6868
| "soundEnabled"
69+
| "soundVolume"
6970
| "diffEnabled"
7071
| "debugDiffEnabled"
7172
| "alwaysAllowMcp"
@@ -137,6 +138,11 @@ export class ClineProvider implements vscode.WebviewViewProvider {
137138
this.outputChannel.appendLine("Resolving webview view")
138139
this.view = webviewView
139140

141+
// Initialize sound enabled state
142+
this.getState().then(({ soundEnabled }) => {
143+
setSoundEnabled(soundEnabled ?? false)
144+
})
145+
140146
webviewView.webview.options = {
141147
// Allow scripts in the webview
142148
enableScripts: true,
@@ -597,6 +603,12 @@ export class ClineProvider implements vscode.WebviewViewProvider {
597603
setSoundEnabled(soundEnabled) // Add this line to update the sound utility
598604
await this.postStateToWebview()
599605
break
606+
case "soundVolume":
607+
const soundVolume = message.value ?? 0.5
608+
await this.updateGlobalState("soundVolume", soundVolume)
609+
setSoundVolume(soundVolume)
610+
await this.postStateToWebview()
611+
break
600612
case "diffEnabled":
601613
const diffEnabled = message.bool ?? true
602614
await this.updateGlobalState("diffEnabled", diffEnabled)
@@ -935,6 +947,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
935947
diffEnabled,
936948
debugDiffEnabled,
937949
taskHistory,
950+
soundVolume,
938951
} = await this.getState()
939952

940953
const allowedCommands = vscode.workspace
@@ -960,6 +973,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
960973
debugDiffEnabled: debugDiffEnabled ?? false,
961974
shouldShowAnnouncement: lastShownAnnouncementId !== this.latestAnnouncementId,
962975
allowedCommands,
976+
soundVolume: soundVolume ?? 0.5,
963977
}
964978
}
965979

@@ -1053,6 +1067,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
10531067
soundEnabled,
10541068
diffEnabled,
10551069
debugDiffEnabled,
1070+
soundVolume,
10561071
] = await Promise.all([
10571072
this.getGlobalState("apiProvider") as Promise<ApiProvider | undefined>,
10581073
this.getGlobalState("apiModelId") as Promise<string | undefined>,
@@ -1091,6 +1106,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
10911106
this.getGlobalState("soundEnabled") as Promise<boolean | undefined>,
10921107
this.getGlobalState("diffEnabled") as Promise<boolean | undefined>,
10931108
this.getGlobalState("debugDiffEnabled") as Promise<boolean | undefined>,
1109+
this.getGlobalState("soundVolume") as Promise<number | undefined>,
10941110
])
10951111

10961112
let apiProvider: ApiProvider
@@ -1147,6 +1163,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
11471163
soundEnabled: soundEnabled ?? false,
11481164
diffEnabled: diffEnabled ?? false,
11491165
debugDiffEnabled: debugDiffEnabled ?? false,
1166+
soundVolume,
11501167
}
11511168
}
11521169

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export interface ExtensionState {
5151
uriScheme?: string
5252
allowedCommands?: string[]
5353
soundEnabled?: boolean
54+
soundVolume?: number
5455
diffEnabled?: boolean
5556
debugDiffEnabled?: boolean
5657
}

src/shared/WebviewMessage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface WebviewMessage {
3232
| "alwaysAllowMcp"
3333
| "playSound"
3434
| "soundEnabled"
35+
| "soundVolume"
3536
| "diffEnabled"
3637
| "debugDiffEnabled"
3738
| "openMcpSettings"
@@ -44,6 +45,7 @@ export interface WebviewMessage {
4445
apiConfiguration?: ApiConfiguration
4546
images?: string[]
4647
bool?: boolean
48+
value?: number
4749
commands?: string[]
4850
audioType?: AudioType
4951
// For toggleToolAutoApprove

src/utils/sound.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const isWAV = (filepath: string): boolean => {
2121
}
2222

2323
let isSoundEnabled = false
24+
let volume = .5
2425

2526
/**
2627
* Set sound configuration
@@ -30,6 +31,14 @@ export const setSoundEnabled = (enabled: boolean): void => {
3031
isSoundEnabled = enabled
3132
}
3233

34+
/**
35+
* Set sound volume
36+
* @param volume number
37+
*/
38+
export const setSoundVolume = (newVolume: number): void => {
39+
volume = newVolume
40+
}
41+
3342
/**
3443
* Play a sound file
3544
* @param filepath string
@@ -54,11 +63,9 @@ export const playSound = (filepath: string): void => {
5463
return // Skip playback within minimum interval to prevent continuous playback
5564
}
5665

57-
const player = require("play-sound")()
58-
player.play(filepath, function (err: any) {
59-
if (err) {
60-
throw new Error("Failed to play sound effect")
61-
}
66+
const sound = require("sound-play")
67+
sound.play(filepath, volume).catch(() => {
68+
throw new Error("Failed to play sound effect")
6269
})
6370

6471
lastPlayedTime = currentTime

0 commit comments

Comments
 (0)