Skip to content

Commit 2930b64

Browse files
committed
fix(deeplink): prevent deadlock in pause/resume actions
1 parent d9721fa commit 2930b64

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

apps/desktop/src-tauri/src/deeplink_actions.rs

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,49 @@ impl DeepLinkAction {
162162
}
163163
DeepLinkAction::PauseRecording => {
164164
let state = app.state::<ArcLock<App>>();
165-
let guard = state.read().await;
166-
if let Some(recording) = guard.current_recording() {
167-
recording.pause().await.map_err(|e| e.to_string())
168-
} else {
169-
Ok(())
165+
let (instant_handle, studio_handle) = {
166+
let guard = state.read().await;
167+
match guard.current_recording() {
168+
Some(crate::recording::InProgressRecording::Instant { handle, .. }) => {
169+
(Some(handle.clone()), None)
170+
}
171+
Some(crate::recording::InProgressRecording::Studio { handle, .. }) => {
172+
(None, Some(handle.clone()))
173+
}
174+
None => (None, None),
175+
}
176+
};
177+
178+
if let Some(handle) = instant_handle {
179+
handle.pause().await.map_err(|e| e.to_string())?;
180+
}
181+
if let Some(handle) = studio_handle {
182+
handle.pause().await.map_err(|e| e.to_string())?;
170183
}
184+
Ok(())
171185
}
172186
DeepLinkAction::ResumeRecording => {
173187
let state = app.state::<ArcLock<App>>();
174-
let guard = state.read().await;
175-
if let Some(recording) = guard.current_recording() {
176-
recording.resume().await.map_err(|e| e.to_string())
177-
} else {
178-
Ok(())
188+
let (instant_handle, studio_handle) = {
189+
let guard = state.read().await;
190+
match guard.current_recording() {
191+
Some(crate::recording::InProgressRecording::Instant { handle, .. }) => {
192+
(Some(handle.clone()), None)
193+
}
194+
Some(crate::recording::InProgressRecording::Studio { handle, .. }) => {
195+
(None, Some(handle.clone()))
196+
}
197+
None => (None, None),
198+
}
199+
};
200+
201+
if let Some(handle) = instant_handle {
202+
handle.resume().await.map_err(|e| e.to_string())?;
203+
}
204+
if let Some(handle) = studio_handle {
205+
handle.resume().await.map_err(|e| e.to_string())?;
179206
}
207+
Ok(())
180208
}
181209
DeepLinkAction::SwitchMicrophone { mic_label } => {
182210
let state = app.state::<ArcLock<App>>();

0 commit comments

Comments
 (0)