mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-21 12:51:17 -05:00
Merge pull request #129 from RooVetGit/jq/sound-setting-improvements
Sound setting improvements
This commit is contained in:
@@ -22,7 +22,7 @@ import { Cline } from "../Cline"
|
||||
import { openMention } from "../mentions"
|
||||
import { getNonce } from "./getNonce"
|
||||
import { getUri } from "./getUri"
|
||||
import { playSound, setSoundEnabled } from "../../utils/sound"
|
||||
import { playSound, setSoundEnabled, setSoundVolume } from "../../utils/sound"
|
||||
|
||||
/*
|
||||
https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
|
||||
@@ -66,6 +66,7 @@ type GlobalStateKey =
|
||||
| "openRouterUseMiddleOutTransform"
|
||||
| "allowedCommands"
|
||||
| "soundEnabled"
|
||||
| "soundVolume"
|
||||
| "diffEnabled"
|
||||
| "debugDiffEnabled"
|
||||
| "alwaysAllowMcp"
|
||||
@@ -137,6 +138,11 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
||||
this.outputChannel.appendLine("Resolving webview view")
|
||||
this.view = webviewView
|
||||
|
||||
// Initialize sound enabled state
|
||||
this.getState().then(({ soundEnabled }) => {
|
||||
setSoundEnabled(soundEnabled ?? false)
|
||||
})
|
||||
|
||||
webviewView.webview.options = {
|
||||
// Allow scripts in the webview
|
||||
enableScripts: true,
|
||||
@@ -597,6 +603,12 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
||||
setSoundEnabled(soundEnabled) // Add this line to update the sound utility
|
||||
await this.postStateToWebview()
|
||||
break
|
||||
case "soundVolume":
|
||||
const soundVolume = message.value ?? 0.5
|
||||
await this.updateGlobalState("soundVolume", soundVolume)
|
||||
setSoundVolume(soundVolume)
|
||||
await this.postStateToWebview()
|
||||
break
|
||||
case "diffEnabled":
|
||||
const diffEnabled = message.bool ?? true
|
||||
await this.updateGlobalState("diffEnabled", diffEnabled)
|
||||
@@ -935,6 +947,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
||||
diffEnabled,
|
||||
debugDiffEnabled,
|
||||
taskHistory,
|
||||
soundVolume,
|
||||
} = await this.getState()
|
||||
|
||||
const allowedCommands = vscode.workspace
|
||||
@@ -960,6 +973,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
||||
debugDiffEnabled: debugDiffEnabled ?? false,
|
||||
shouldShowAnnouncement: lastShownAnnouncementId !== this.latestAnnouncementId,
|
||||
allowedCommands,
|
||||
soundVolume: soundVolume ?? 0.5,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1053,6 +1067,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
||||
soundEnabled,
|
||||
diffEnabled,
|
||||
debugDiffEnabled,
|
||||
soundVolume,
|
||||
] = await Promise.all([
|
||||
this.getGlobalState("apiProvider") as Promise<ApiProvider | undefined>,
|
||||
this.getGlobalState("apiModelId") as Promise<string | undefined>,
|
||||
@@ -1091,6 +1106,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
||||
this.getGlobalState("soundEnabled") as Promise<boolean | undefined>,
|
||||
this.getGlobalState("diffEnabled") as Promise<boolean | undefined>,
|
||||
this.getGlobalState("debugDiffEnabled") as Promise<boolean | undefined>,
|
||||
this.getGlobalState("soundVolume") as Promise<number | undefined>,
|
||||
])
|
||||
|
||||
let apiProvider: ApiProvider
|
||||
@@ -1147,6 +1163,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
||||
soundEnabled: soundEnabled ?? false,
|
||||
diffEnabled: diffEnabled ?? false,
|
||||
debugDiffEnabled: debugDiffEnabled ?? false,
|
||||
soundVolume,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ export interface ExtensionState {
|
||||
uriScheme?: string
|
||||
allowedCommands?: string[]
|
||||
soundEnabled?: boolean
|
||||
soundVolume?: number
|
||||
diffEnabled?: boolean
|
||||
debugDiffEnabled?: boolean
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ export interface WebviewMessage {
|
||||
| "alwaysAllowMcp"
|
||||
| "playSound"
|
||||
| "soundEnabled"
|
||||
| "soundVolume"
|
||||
| "diffEnabled"
|
||||
| "debugDiffEnabled"
|
||||
| "openMcpSettings"
|
||||
@@ -44,6 +45,7 @@ export interface WebviewMessage {
|
||||
apiConfiguration?: ApiConfiguration
|
||||
images?: string[]
|
||||
bool?: boolean
|
||||
value?: number
|
||||
commands?: string[]
|
||||
audioType?: AudioType
|
||||
// For toggleToolAutoApprove
|
||||
|
||||
@@ -21,6 +21,7 @@ export const isWAV = (filepath: string): boolean => {
|
||||
}
|
||||
|
||||
let isSoundEnabled = false
|
||||
let volume = .5
|
||||
|
||||
/**
|
||||
* Set sound configuration
|
||||
@@ -30,6 +31,14 @@ export const setSoundEnabled = (enabled: boolean): void => {
|
||||
isSoundEnabled = enabled
|
||||
}
|
||||
|
||||
/**
|
||||
* Set sound volume
|
||||
* @param volume number
|
||||
*/
|
||||
export const setSoundVolume = (newVolume: number): void => {
|
||||
volume = newVolume
|
||||
}
|
||||
|
||||
/**
|
||||
* Play a sound file
|
||||
* @param filepath string
|
||||
@@ -54,11 +63,9 @@ export const playSound = (filepath: string): void => {
|
||||
return // Skip playback within minimum interval to prevent continuous playback
|
||||
}
|
||||
|
||||
const player = require("play-sound")()
|
||||
player.play(filepath, function (err: any) {
|
||||
if (err) {
|
||||
throw new Error("Failed to play sound effect")
|
||||
}
|
||||
const sound = require("sound-play")
|
||||
sound.play(filepath, volume).catch(() => {
|
||||
throw new Error("Failed to play sound effect")
|
||||
})
|
||||
|
||||
lastPlayedTime = currentTime
|
||||
|
||||
Reference in New Issue
Block a user