MCPcopy Create free account
hub / github.com/Moosync/Moosync / send_ui_request

Method send_ui_request

src-tauri/src/extensions/request_handler.rs:180–218  ·  view source on GitHub ↗
(&self, mut command: MainCommand)

Source from the content-addressed store, hash-verified

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> {

Callers 1

handle_requestMethod · 0.80

Calls 4

to_ui_requestMethod · 0.80
onceMethod · 0.80
sendMethod · 0.80
emitMethod · 0.80

Tested by

no test coverage detected