Skip to content

Commit e2c173f

Browse files
committed
fix: analyzer event not cleared up on receive
1 parent aa1a262 commit e2c173f

3 files changed

Lines changed: 26 additions & 17 deletions

File tree

src-tauri/src/player.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,8 @@ fn decode_loop(
690690
}
691691
PlayerControlEvent::ChangeAnalyzer(request) => {
692692
info!("audio: change analyzer! {:?}", request);
693+
694+
while let Ok(_) = analyzer_receiver.try_lock().unwrap().try_recv() {}
693695
if let Some(request_type) = &request.analyzer_type {
694696
let new_state = AnalyzerState {
695697
is_enabled: request.is_enabled.unwrap_or(true),
@@ -1213,6 +1215,11 @@ fn decode_loop(
12131215
}
12141216
PlayerControlEvent::ChangeAnalyzer(request) => {
12151217
info!("audio: change analyzer! {:?}", request);
1218+
1219+
while let Ok(_) =
1220+
analyzer_receiver.try_lock().unwrap().try_recv()
1221+
{
1222+
}
12161223
if let Some(request_type) = &request.analyzer_type {
12171224
let new_state = AnalyzerState {
12181225
is_enabled: request.is_enabled.unwrap_or(true),
@@ -1352,6 +1359,11 @@ fn decode_loop(
13521359
}
13531360
PlayerControlEvent::ChangeAnalyzer(request) => {
13541361
info!("audio: change analyzer! {:?}", request);
1362+
1363+
while let Ok(_) =
1364+
analyzer_receiver.try_lock().unwrap().try_recv()
1365+
{
1366+
}
13551367
if let Some(request_type) = &request.analyzer_type {
13561368
let new_state = AnalyzerState {
13571369
is_enabled: request.is_enabled.unwrap_or(true),
@@ -1821,29 +1833,29 @@ pub struct AudioDevices {
18211833
}
18221834

18231835
#[tauri::command]
1824-
pub fn get_devices(_app_handle: tauri::AppHandle) -> Option<AudioDevices> {
1825-
// Get default host.
1836+
pub async fn get_devices(_app_handle: tauri::AppHandle) -> Result<AudioDevices, String> {
18261837
let host = cpal::default_host();
18271838

1839+
// Fetch output devices and map using the new description() API
18281840
let cpal_devices: Vec<AudioDevice> = host
18291841
.output_devices()
1830-
.unwrap()
1831-
.map(|device| AudioDevice {
1832-
name: device.name().unwrap(),
1842+
.map_err(|e| format!("Failed to get output devices: {}", e))?
1843+
.filter_map(|device| {
1844+
// description() returns a Result<DeviceDescription, DevicePropertyError>
1845+
device.description().ok().map(|desc| AudioDevice {
1846+
name: desc.name().to_string(), // Accessing the name field from DeviceDescription
1847+
})
18331848
})
18341849
.collect();
18351850

1836-
let cpal_default = host.default_output_device();
1837-
1838-
let default = if cpal_default.is_none() {
1839-
None
1840-
} else {
1841-
Some(AudioDevice {
1842-
name: cpal_default.unwrap().name().unwrap(),
1851+
// Fetch default device and map its description
1852+
let default = host.default_output_device().and_then(|device| {
1853+
device.description().ok().map(|desc| AudioDevice {
1854+
name: desc.name().to_string(),
18431855
})
1844-
};
1856+
});
18451857

1846-
Some(AudioDevices {
1858+
Ok(AudioDevices {
18471859
devices: cpal_devices,
18481860
default,
18491861
})

src-tauri/src/scrape.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ async fn fetch_wikipedia(url: &str) -> Result<String, Box<dyn Error>> {
118118

119119
// Get the HTML content from the response
120120
let body = response.text().await?;
121-
info!("{:?}", body);
122121

123122
// Parse the HTML content using the scraper crate
124123
let document = Html::parse_document(&body);
@@ -127,7 +126,6 @@ async fn fetch_wikipedia(url: &str) -> Result<String, Box<dyn Error>> {
127126
let lyrics_selector = Selector::parse("#mw-content-text").unwrap();
128127

129128
let lyrics_element = document.select(&lyrics_selector).next();
130-
info!("{:?}", lyrics_element);
131129

132130
// Extract and return the lyrics
133131
match lyrics_element {

src/window/EventListener.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const appWindow = getCurrentWebviewWindow();
2525

2626
export function startMenuListener() {
2727
appWindow.listen("menu", async ({ event, payload }) => {
28-
console.log("menu", event);
2928
switch (payload) {
3029
case "about":
3130
console.log("about");

0 commit comments

Comments
 (0)