neiam
/koco
public · Issues · Pulls · Labels · Forks · Compare · Actions failure · Badges · Packages
⭐
Log in to mark this repository.
clippy
19cd5f9 · gmorell · 2025-12-26 03:20
Files changed
modified
src/main.rs
+24
−44
@@ -639,7 +639,7 @@ impl Koco {
| 639 | 639 | |
| 640 | 640 | // Use label if title is empty |
| 641 | 641 | np.title = if !title.is_empty() { title.to_string() } else { label.to_string() }; |
| 642 | − np.artist = item.get("artist").and_then(|a| a.as_array()).and_then(|arr| arr.get(0)).and_then(|a| a.as_str()).unwrap_or("").to_string(); | |
| 642 | + np.artist = item.get("artist").and_then(|a| a.as_array()).and_then(|arr| arr.first()).and_then(|a| a.as_str()).unwrap_or("").to_string(); | |
| 643 | 643 | np.album = item.get("album").and_then(|a| a.as_str()).unwrap_or("").to_string(); |
| 644 | 644 | |
| 645 | 645 | debug!("Parsed - Title: '{}', Artist: '{}', Album: '{}'", np.title, np.artist, np.album); |
@@ -737,11 +737,10 @@ impl Koco {
| 737 | 737 | let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(1)); |
| 738 | 738 | loop { |
| 739 | 739 | interval.tick().await; |
| 740 | − if let Ok(mut np) = now_playing.lock() { | |
| 741 | − if np.playing && np.position < np.duration { | |
| 740 | + if let Ok(mut np) = now_playing.lock() | |
| 741 | + && np.playing && np.position < np.duration { | |
| 742 | 742 | np.position += 1.0; |
| 743 | 743 | } |
| 744 | − } | |
| 745 | 744 | } |
| 746 | 745 | }); |
| 747 | 746 | } |
@@ -1034,41 +1033,34 @@ impl eframe::App for Koco {
| 1034 | 1033 | // Handle keyboard input |
| 1035 | 1034 | if let Some(instance) = self.current_instance() { |
| 1036 | 1035 | ctx.input(|i| { |
| 1037 | − if i.key_pressed(egui::Key::ArrowUp) { | |
| 1038 | − if let Err(e) = instance.send_key("up") { | |
| 1036 | + if i.key_pressed(egui::Key::ArrowUp) | |
| 1037 | + && let Err(e) = instance.send_key("up") { | |
| 1039 | 1038 | info!("Failed to send up command: {}", e); |
| 1040 | 1039 | } |
| 1041 | − } | |
| 1042 | − if i.key_pressed(egui::Key::ArrowDown) { | |
| 1043 | − if let Err(e) = instance.send_key("down") { | |
| 1040 | + if i.key_pressed(egui::Key::ArrowDown) | |
| 1041 | + && let Err(e) = instance.send_key("down") { | |
| 1044 | 1042 | info!("Failed to send down command: {}", e); |
| 1045 | 1043 | } |
| 1046 | − } | |
| 1047 | − if i.key_pressed(egui::Key::ArrowLeft) { | |
| 1048 | − if let Err(e) = instance.send_key("left") { | |
| 1044 | + if i.key_pressed(egui::Key::ArrowLeft) | |
| 1045 | + && let Err(e) = instance.send_key("left") { | |
| 1049 | 1046 | info!("Failed to send left command: {}", e); |
| 1050 | 1047 | } |
| 1051 | − } | |
| 1052 | − if i.key_pressed(egui::Key::ArrowRight) { | |
| 1053 | − if let Err(e) = instance.send_key("right") { | |
| 1048 | + if i.key_pressed(egui::Key::ArrowRight) | |
| 1049 | + && let Err(e) = instance.send_key("right") { | |
| 1054 | 1050 | info!("Failed to send right command: {}", e); |
| 1055 | 1051 | } |
| 1056 | − } | |
| 1057 | − if i.key_pressed(egui::Key::Enter) { | |
| 1058 | − if let Err(e) = instance.send_key("select") { | |
| 1052 | + if i.key_pressed(egui::Key::Enter) | |
| 1053 | + && let Err(e) = instance.send_key("select") { | |
| 1059 | 1054 | info!("Failed to send select command: {}", e); |
| 1060 | 1055 | } |
| 1061 | − } | |
| 1062 | − if i.key_pressed(egui::Key::Escape) || i.key_pressed(egui::Key::Backspace) { | |
| 1063 | − if let Err(e) = instance.send_key("back") { | |
| 1056 | + if (i.key_pressed(egui::Key::Escape) || i.key_pressed(egui::Key::Backspace)) | |
| 1057 | + && let Err(e) = instance.send_key("back") { | |
| 1064 | 1058 | info!("Failed to send back command: {}", e); |
| 1065 | 1059 | } |
| 1066 | − } | |
| 1067 | − if i.key_pressed(egui::Key::Space) { | |
| 1068 | − if let Err(e) = instance.send_key("playpause") { | |
| 1060 | + if i.key_pressed(egui::Key::Space) | |
| 1061 | + && let Err(e) = instance.send_key("playpause") { | |
| 1069 | 1062 | info!("Failed to send playpause command: {}", e); |
| 1070 | 1063 | } |
| 1071 | − } | |
| 1072 | 1064 | }); |
| 1073 | 1065 | } |
| 1074 | 1066 |
@@ -1123,11 +1115,9 @@ impl eframe::App for Koco {
| 1123 | 1115 | ), |
| 1124 | 1116 | ) |
| 1125 | 1117 | .clicked() |
| 1126 | − { | |
| 1127 | − if let Err(e) = instance.send_key("up") { | |
| 1118 | + && let Err(e) = instance.send_key("up") { | |
| 1128 | 1119 | info!("Failed to send up command: {}", e); |
| 1129 | 1120 | } |
| 1130 | − } | |
| 1131 | 1121 | ui.label(""); // Empty cell |
| 1132 | 1122 | ui.end_row(); |
| 1133 | 1123 |
@@ -1143,11 +1133,9 @@ impl eframe::App for Koco {
| 1143 | 1133 | ), |
| 1144 | 1134 | ) |
| 1145 | 1135 | .clicked() |
| 1146 | − { | |
| 1147 | − if let Err(e) = instance.send_key("left") { | |
| 1136 | + && let Err(e) = instance.send_key("left") { | |
| 1148 | 1137 | info!("Failed to send left command: {}", e); |
| 1149 | 1138 | } |
| 1150 | − } | |
| 1151 | 1139 | if ui |
| 1152 | 1140 | .add_sized( |
| 1153 | 1141 | [80.0, 80.0], |
@@ -1159,11 +1147,9 @@ impl eframe::App for Koco {
| 1159 | 1147 | ), |
| 1160 | 1148 | ) |
| 1161 | 1149 | .clicked() |
| 1162 | − { | |
| 1163 | − if let Err(e) = instance.send_key("select") { | |
| 1150 | + && let Err(e) = instance.send_key("select") { | |
| 1164 | 1151 | info!("Failed to send select command: {}", e); |
| 1165 | 1152 | } |
| 1166 | − } | |
| 1167 | 1153 | if ui |
| 1168 | 1154 | .add_sized( |
| 1169 | 1155 | [80.0, 80.0], |
@@ -1175,11 +1161,9 @@ impl eframe::App for Koco {
| 1175 | 1161 | ), |
| 1176 | 1162 | ) |
| 1177 | 1163 | .clicked() |
| 1178 | − { | |
| 1179 | − if let Err(e) = instance.send_key("right") { | |
| 1164 | + && let Err(e) = instance.send_key("right") { | |
| 1180 | 1165 | info!("Failed to send right command: {}", e); |
| 1181 | 1166 | } |
| 1182 | − } | |
| 1183 | 1167 | ui.end_row(); |
| 1184 | 1168 | |
| 1185 | 1169 | // Row 3: Empty, Down, Empty |
@@ -1194,11 +1178,9 @@ impl eframe::App for Koco {
| 1194 | 1178 | ), |
| 1195 | 1179 | ) |
| 1196 | 1180 | .clicked() |
| 1197 | − { | |
| 1198 | − if let Err(e) = instance.send_key("back") { | |
| 1181 | + && let Err(e) = instance.send_key("back") { | |
| 1199 | 1182 | info!("Failed to send back command: {}", e); |
| 1200 | 1183 | } |
| 1201 | − } | |
| 1202 | 1184 | if ui |
| 1203 | 1185 | .add_sized( |
| 1204 | 1186 | [80.0, 80.0], |
@@ -1210,11 +1192,9 @@ impl eframe::App for Koco {
| 1210 | 1192 | ), |
| 1211 | 1193 | ) |
| 1212 | 1194 | .clicked() |
| 1213 | − { | |
| 1214 | − if let Err(e) = instance.send_key("down") { | |
| 1195 | + && let Err(e) = instance.send_key("down") { | |
| 1215 | 1196 | info!("Failed to send down command: {}", e); |
| 1216 | 1197 | } |
| 1217 | − } | |
| 1218 | 1198 | ui.label(""); // Empty cell |
| 1219 | 1199 | ui.end_row(); |
| 1220 | 1200 | }); |
@@ -1235,7 +1215,7 @@ impl eframe::App for Koco {
| 1235 | 1215 | if !np.title.is_empty() { |
| 1236 | 1216 | // Calculate progress percentage |
| 1237 | 1217 | let percentage = if np.duration > 0.0 { |
| 1238 | − (np.position / np.duration).min(1.0).max(0.0) | |
| 1218 | + (np.position / np.duration).clamp(0.0, 1.0) | |
| 1239 | 1219 | } else { |
| 1240 | 1220 | 0.0 |
| 1241 | 1221 | }; |
Parents: 7119455