-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Deeplinks: pause/resume/restart recording + switch mic/camera #1621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
38b9afb
e02ac71
7bd37b3
cf8787f
b6264a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,6 +26,16 @@ pub enum DeepLinkAction { | |||||||||||||||||||||||||||||||||||||||||||||
| mode: RecordingMode, | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| StopRecording, | ||||||||||||||||||||||||||||||||||||||||||||||
| PauseRecording, | ||||||||||||||||||||||||||||||||||||||||||||||
| ResumeRecording, | ||||||||||||||||||||||||||||||||||||||||||||||
| TogglePauseRecording, | ||||||||||||||||||||||||||||||||||||||||||||||
| RestartRecording, | ||||||||||||||||||||||||||||||||||||||||||||||
| SwitchMicrophone { | ||||||||||||||||||||||||||||||||||||||||||||||
| mic_label: Option<String>, | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| SwitchCamera { | ||||||||||||||||||||||||||||||||||||||||||||||
| camera: Option<DeviceOrModelID>, | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| OpenEditor { | ||||||||||||||||||||||||||||||||||||||||||||||
| project_path: PathBuf, | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -146,6 +156,42 @@ impl DeepLinkAction { | |||||||||||||||||||||||||||||||||||||||||||||
| DeepLinkAction::StopRecording => { | ||||||||||||||||||||||||||||||||||||||||||||||
| crate::recording::stop_recording(app.clone(), app.state()).await | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| DeepLinkAction::PauseRecording => { | ||||||||||||||||||||||||||||||||||||||||||||||
| let state = app.state::<ArcLock<App>>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| if state.read().await.current_recording().is_none() { | ||||||||||||||||||||||||||||||||||||||||||||||
| return Err("Recording not in progress".to_string()); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| crate::recording::pause_recording(app.clone(), state).await | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| DeepLinkAction::ResumeRecording => { | ||||||||||||||||||||||||||||||||||||||||||||||
| let state = app.state::<ArcLock<App>>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| if state.read().await.current_recording().is_none() { | ||||||||||||||||||||||||||||||||||||||||||||||
| return Err("Recording not in progress".to_string()); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| crate::recording::resume_recording(app.clone(), state).await | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| DeepLinkAction::TogglePauseRecording => { | ||||||||||||||||||||||||||||||||||||||||||||||
| let state = app.state::<ArcLock<App>>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| if state.read().await.current_recording().is_none() { | ||||||||||||||||||||||||||||||||||||||||||||||
| return Err("Recording not in progress".to_string()); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| crate::recording::toggle_pause_recording(app.clone(), state).await | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| DeepLinkAction::RestartRecording => { | ||||||||||||||||||||||||||||||||||||||||||||||
| crate::recording::restart_recording(app.clone(), app.state()) | ||||||||||||||||||||||||||||||||||||||||||||||
| .await | ||||||||||||||||||||||||||||||||||||||||||||||
| .map(|_| ()) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| DeepLinkAction::SwitchMicrophone { mic_label } => { | ||||||||||||||||||||||||||||||||||||||||||||||
| crate::set_mic_input( | ||||||||||||||||||||||||||||||||||||||||||||||
| app.state::<ArcLock<App>>(), | ||||||||||||||||||||||||||||||||||||||||||||||
| mic_label.filter(|label| !label.trim().is_empty()), | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| .await | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| DeepLinkAction::SwitchCamera { camera } => { | ||||||||||||||||||||||||||||||||||||||||||||||
| crate::set_camera_input(app.clone(), app.state(), camera, None).await | ||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor robustness: mirror the mic label handling and treat an empty
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| DeepLinkAction::OpenEditor { project_path } => { | ||||||||||||||||||||||||||||||||||||||||||||||
| crate::open_project_from_path(Path::new(&project_path), app.clone()) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -155,3 +201,46 @@ impl DeepLinkAction { | |||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #[cfg(test)] | ||||||||||||||||||||||||||||||||||||||||||||||
| mod tests { | ||||||||||||||||||||||||||||||||||||||||||||||
| use super::{ActionParseFromUrlError, DeepLinkAction}; | ||||||||||||||||||||||||||||||||||||||||||||||
| use tauri::Url; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| fn action_url(payload: &str) -> Url { | ||||||||||||||||||||||||||||||||||||||||||||||
| let mut url = Url::parse("cap-desktop://action").expect("valid action url"); | ||||||||||||||||||||||||||||||||||||||||||||||
| url.query_pairs_mut().append_pair("value", payload); | ||||||||||||||||||||||||||||||||||||||||||||||
| url | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||
| fn parses_pause_recording_action() { | ||||||||||||||||||||||||||||||||||||||||||||||
| let url = action_url(r#""pause_recording""#); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| let action = DeepLinkAction::try_from(&url).expect("parse pause action"); | ||||||||||||||||||||||||||||||||||||||||||||||
| assert!(matches!(action, DeepLinkAction::PauseRecording)); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||
| fn parses_switch_microphone_action() { | ||||||||||||||||||||||||||||||||||||||||||||||
| let url = action_url(r#"{"switch_microphone":{"mic_label":"Studio Mic"}}"#); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| let action = DeepLinkAction::try_from(&url).expect("parse switch microphone action"); | ||||||||||||||||||||||||||||||||||||||||||||||
| match action { | ||||||||||||||||||||||||||||||||||||||||||||||
| DeepLinkAction::SwitchMicrophone { mic_label } => { | ||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!(mic_label.as_deref(), Some("Studio Mic")); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| other => panic!("unexpected action: {other:?}"), | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||
| fn rejects_non_action_domain() { | ||||||||||||||||||||||||||||||||||||||||||||||
| let mut url = Url::parse("cap-desktop://signin").expect("valid signin url"); | ||||||||||||||||||||||||||||||||||||||||||||||
| url.query_pairs_mut() | ||||||||||||||||||||||||||||||||||||||||||||||
| .append_pair("value", r#""stop_recording""#); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| let error = DeepLinkAction::try_from(&url).expect_err("signin deeplink is not action"); | ||||||||||||||||||||||||||||||||||||||||||||||
| assert!(matches!(error, ActionParseFromUrlError::NotAction)); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice to have: quick parse smoke tests for the other new actions, just to guard the serde rename plumbing.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For deeplinks, do you want pause/resume/toggle to behave like
StopRecordingand error when there’s no active recording? Right now these will succeed silently when nothing is recording.