Skip to content

Commit d58d3d4

Browse files
committed
feat(deeplink): add pause, resume, and device switching actions (#1540)
1 parent 2c49c7d commit d58d3d4

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ pub enum DeepLinkAction {
3232
OpenSettings {
3333
page: Option<String>,
3434
},
35+
PauseRecording,
36+
ResumeRecording,
37+
SwitchMicrophone {
38+
mic_label: Option<String>,
39+
},
40+
SwitchCamera {
41+
camera: Option<DeviceOrModelID>,
42+
},
3543
}
3644

3745
pub fn handle(app_handle: &AppHandle, urls: Vec<Url>) {
@@ -152,6 +160,81 @@ impl DeepLinkAction {
152160
DeepLinkAction::OpenSettings { page } => {
153161
crate::show_window(app.clone(), ShowCapWindow::Settings { page }).await
154162
}
163+
DeepLinkAction::PauseRecording => {
164+
let state = app.state::<ArcLock<App>>();
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())?;
183+
}
184+
Ok(())
185+
}
186+
DeepLinkAction::ResumeRecording => {
187+
let state = app.state::<ArcLock<App>>();
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())?;
206+
}
207+
Ok(())
208+
}
209+
DeepLinkAction::SwitchMicrophone { mic_label } => {
210+
if let Some(ref label) = mic_label {
211+
let available_mics = cap_recording::feeds::microphone::MicrophoneFeed::list();
212+
if !available_mics.contains_key(label) {
213+
return Err(format!("Microphone with label \"{}\" not found", label));
214+
}
215+
}
216+
217+
let state = app.state::<ArcLock<App>>();
218+
crate::set_mic_input(state, mic_label).await
219+
}
220+
DeepLinkAction::SwitchCamera { camera } => {
221+
if let Some(ref id) = camera {
222+
let cameras: Vec<_> = cap_camera::list_cameras().collect();
223+
let exists = cameras.iter().any(|info| match id {
224+
DeviceOrModelID::DeviceID(device_id) => info.device_id() == device_id,
225+
DeviceOrModelID::ModelID(model_id) => {
226+
info.model_id().is_some_and(|existing| existing == model_id)
227+
}
228+
});
229+
230+
if !exists {
231+
return Err(format!("Camera with ID \"{:?}\" not found", id));
232+
}
233+
}
234+
235+
let state = app.state::<ArcLock<App>>();
236+
crate::set_camera_input(app.clone(), state, camera).await
237+
}
155238
}
156239
}
157240
}

0 commit comments

Comments
 (0)