-
-
Notifications
You must be signed in to change notification settings - Fork 218
feat: add leave_hook symmetric to enter_hook #448
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
0492006
fa50a41
02d6ed1
3313b2e
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 |
|---|---|---|
|
|
@@ -37,6 +37,13 @@ pub(crate) enum ICaptureEvent { | |
| /// either the remote client leaving its device region, | ||
| /// a new device entering the screen or the release bind. | ||
| ClientEntered(u64), | ||
| /// The previously active client was left, i.e. capture | ||
| /// was released for the given handle. Mirrors | ||
| /// [`ICaptureEvent::ClientEntered`] for the leave side | ||
| /// and fires on every release path (release-bind chord, | ||
| /// remote `Leave`, explicit `Release` request, send | ||
| /// failure, or destroy of the active capture). | ||
| ClientLeft(u64), | ||
| } | ||
|
|
||
| #[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
|
|
@@ -301,6 +308,16 @@ impl CaptureTask { | |
| capture.create(h, p).await?; | ||
| } | ||
| CaptureRequest::Destroy(h) => { | ||
| // If the capture we're tearing down is the | ||
| // currently-active one, treat this as a | ||
| // release for hook purposes. The release_capture | ||
| // path also clears active_client and flushes | ||
| // pressed-key state to the peer; without this, | ||
| // `cli deactivate` (or a hostname change | ||
| // re-creating the client) would skip leave_hook. | ||
| if self.active_client == Some(h) { | ||
| self.release_capture(capture).await?; | ||
| } | ||
| self.remove_capture(h); | ||
| capture.destroy(h).await?; | ||
| } | ||
|
|
@@ -368,14 +385,25 @@ impl CaptureTask { | |
| if let Err(e) = self.conn.send(event, handle).await { | ||
| const DUR: Duration = Duration::from_millis(500); | ||
| debounce!(PREV_LOG, DUR, log::warn!("releasing capture: {e}")); | ||
| capture.release().await?; | ||
| // Funnel through release_capture so the leave_hook | ||
| // fires and active_client is cleared (without this the | ||
| // active_client field would stay stale until the next | ||
| // Begin from a different handle). | ||
| self.release_capture(capture).await?; | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| async fn release_capture(&mut self, capture: &mut InputCapture) -> Result<(), CaptureError> { | ||
| // If we have an active client, notify them we're leaving | ||
| if let Some(handle) = self.active_client.take() { | ||
| // Surface the leave to the service layer so it can fire | ||
| // the per-client leave_hook. Sent before the network | ||
| // teardown below so we never race against the peer | ||
| // disappearing. | ||
| self.event_tx | ||
| .send(ICaptureEvent::ClientLeft(handle)) | ||
| .expect("channel closed"); | ||
|
Comment on lines
+404
to
+406
Contributor
Author
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. Leaving this as-is to stay consistent with the surrounding pattern: the two pre-existing |
||
| // Synthesize key-up events for every key still held in the | ||
| // capture's pressed_keys set BEFORE sending Leave. Without | ||
| // this, pressing the release-bind chord (typically all four | ||
|
|
||
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.
The error-propagation surface doesn't actually change here. Inside
release_capture()everything is either infallible-or-logged (theevent_tx.sendpanics on closed channel like its siblings; theconn.sendcalls for key-up/modifier-reset/Leave all useif let Err(e) = ... { log::warn!(...) }— they never propagate). The only?-propagated error is the finalcapture.release().awaitat the end, which is exactly what the oldcapture.release().await?returned. So this site propagates the sameCaptureErroras before — it just additionally fires the leave_hook and clearsactive_clientalong the way, both of which we want in this code path.