(&self, mut command: MainCommand)
| 178 | |
| 179 | #[tracing::instrument(level = "debug", skip(self, command))] |
| 180 | async fn send_ui_request(&self, mut command: MainCommand) -> Result<MainCommandResponse> { |
| 181 | if self.app_handle.webview_windows().is_empty() { |
| 182 | return Err("No webview spawned yet".into()); |
| 183 | } |
| 184 | |
| 185 | let (tx, rx) = oneshot::channel(); |
| 186 | let request = command.to_ui_request()?; |
| 187 | self.app_handle |
| 188 | .once(format!("ui-reply-{}", request.channel), move |f| { |
| 189 | let payload = f.payload().to_string(); |
| 190 | let _ = tx.send(payload); |
| 191 | }); |
| 192 | tracing::debug!("Sending ui request {:?}", request); |
| 193 | self.app_handle.emit("ui-requests", request)?; |
| 194 | |
| 195 | let res = rx.await; |
| 196 | |
| 197 | match res { |
| 198 | Ok(data) => match command { |
| 199 | MainCommand::GetCurrentSong() => Ok(MainCommandResponse::GetCurrentSong( |
| 200 | serde_json::from_str(&data)?, |
| 201 | )), |
| 202 | MainCommand::GetPlayerState() => Ok(MainCommandResponse::GetPlayerState( |
| 203 | serde_json::from_str(&data)?, |
| 204 | )), |
| 205 | MainCommand::GetVolume() => { |
| 206 | Ok(MainCommandResponse::GetVolume(serde_json::from_str(&data)?)) |
| 207 | } |
| 208 | MainCommand::GetTime() => { |
| 209 | Ok(MainCommandResponse::GetTime(serde_json::from_str(&data)?)) |
| 210 | } |
| 211 | MainCommand::GetQueue() => { |
| 212 | Ok(MainCommandResponse::GetQueue(serde_json::from_str(&data)?)) |
| 213 | } |
| 214 | _ => Err("Not a ui request".into()), |
| 215 | }, |
| 216 | Err(_) => Err("Failed to get response from UI".into()), |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | #[tracing::instrument(level = "debug", skip(self))] |
| 221 | pub async fn extension_updated(&self) -> Result<MainCommandResponse> { |
no test coverage detected