Skip to content

Commit 5b948e2

Browse files
fix(web)!: replace current clipboard logic with auto and manual clipboard modes (#935)
Adds: - auto clipboard mode. When it's enabled, the clipboard will be automatically monitored for changes, and updates from the server will be automatically saved to the local clipboard (this is the old logic; nothing has changed). - manual clipboard mode. One calls dedicated functions to interact with the clipboard.
1 parent 303bee0 commit 5b948e2

File tree

14 files changed

+405
-484
lines changed

14 files changed

+405
-484
lines changed

crates/iron-remote-desktop/src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,16 +267,6 @@ macro_rules! make_bridge {
267267
))
268268
}
269269

270-
#[wasm_bindgen(js_name = remoteReceivedFormatListCallback)]
271-
pub fn remote_received_format_list_callback(
272-
&self,
273-
callback: $crate::internal::web_sys::js_sys::Function,
274-
) -> Self {
275-
Self($crate::SessionBuilder::remote_received_format_list_callback(
276-
&self.0, callback,
277-
))
278-
}
279-
280270
#[wasm_bindgen(js_name = forceClipboardUpdateCallback)]
281271
pub fn force_clipboard_update_callback(
282272
&self,

crates/iron-remote-desktop/src/session.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ pub trait SessionBuilder {
4545
#[must_use]
4646
fn remote_clipboard_changed_callback(&self, callback: js_sys::Function) -> Self;
4747

48-
#[must_use]
49-
fn remote_received_format_list_callback(&self, callback: js_sys::Function) -> Self;
50-
5148
#[must_use]
5249
fn force_clipboard_update_callback(&self, callback: js_sys::Function) -> Self;
5350

crates/ironrdp-cliprdr/src/backend.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,6 @@ pub trait CliprdrBackend: AsAny + core::fmt::Debug + Send {
7373
/// client's clipboard prior to `CLIPRDR` SVC initialization.
7474
fn on_request_format_list(&mut self);
7575

76-
/// Called by [crate::Cliprdr] when copy sequence is finished.
77-
/// This method is called after remote returns format list response.
78-
///
79-
/// Useful for the backend implementations which need to know when remote is ready to paste
80-
/// previously advertised formats from the client. E.g. Web client uses this for
81-
/// Firefox-specific logic to delay sending keyboard key events to prevent pasting the old
82-
/// data from the clipboard.
83-
///
84-
/// This method has default implementation which does nothing because it is not required for
85-
/// most of the backends.
86-
fn on_format_list_received(&mut self) {}
87-
8876
/// Adjusts [crate::Cliprdr] backend capabilities based on capabilities negotiated with a server.
8977
///
9078
/// Called by [crate::Cliprdr] when capability negotiation is finished and server capabilities are

crates/ironrdp-cliprdr/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ impl<R: Role> Cliprdr<R> {
166166
info!("CLIPRDR(clipboard) Remote has received format list successfully");
167167
}
168168
}
169-
170-
self.backend.on_format_list_received();
171169
}
172170
FormatListResponse::Fail => {
173171
return self.handle_error_transition(ClipboardError::FormatListRejected);

crates/ironrdp-web/src/clipboard.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ pub(crate) enum WasmClipboardBackendMessage {
105105
RemoteClipboardChanged(Vec<ClipboardFormat>),
106106
RemoteDataResponse(FormatDataResponse<'static>),
107107

108-
FormatListReceived,
109108
ForceClipboardUpdate,
110109
}
111110

@@ -125,7 +124,6 @@ pub(crate) struct WasmClipboard {
125124
/// Callbacks, required to interact with JS code from within the backend.
126125
pub(crate) struct JsClipboardCallbacks {
127126
pub(crate) on_remote_clipboard_changed: js_sys::Function,
128-
pub(crate) on_remote_received_format_list: Option<js_sys::Function>,
129127
pub(crate) on_force_clipboard_update: Option<js_sys::Function>,
130128
}
131129

@@ -496,11 +494,6 @@ impl WasmClipboard {
496494
}
497495
}
498496
}
499-
WasmClipboardBackendMessage::FormatListReceived => {
500-
if let Some(callback) = self.js_callbacks.on_remote_received_format_list.as_mut() {
501-
callback.call0(&JsValue::NULL).expect("failed to call JS callback");
502-
}
503-
}
504497
WasmClipboardBackendMessage::ForceClipboardUpdate => {
505498
if let Some(callback) = self.js_callbacks.on_force_clipboard_update.as_mut() {
506499
callback.call0(&JsValue::NULL).expect("failed to call JS callback");
@@ -548,10 +541,6 @@ impl CliprdrBackend for WasmClipboardBackend {
548541
self.send_event(WasmClipboardBackendMessage::ForceClipboardUpdate);
549542
}
550543

551-
fn on_format_list_received(&mut self) {
552-
self.send_event(WasmClipboardBackendMessage::FormatListReceived);
553-
}
554-
555544
fn on_process_negotiated_capabilities(&mut self, _: ClipboardGeneralCapabilityFlags) {
556545
// No additional capabilities yet
557546
}

crates/ironrdp-web/src/session.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ struct SessionBuilderInner {
6565
set_cursor_style_callback: Option<js_sys::Function>,
6666
set_cursor_style_callback_context: Option<JsValue>,
6767
remote_clipboard_changed_callback: Option<js_sys::Function>,
68-
remote_received_format_list_callback: Option<js_sys::Function>,
6968
force_clipboard_update_callback: Option<js_sys::Function>,
7069

7170
use_display_control: bool,
@@ -94,7 +93,6 @@ impl Default for SessionBuilderInner {
9493
set_cursor_style_callback: None,
9594
set_cursor_style_callback_context: None,
9695
remote_clipboard_changed_callback: None,
97-
remote_received_format_list_callback: None,
9896
force_clipboard_update_callback: None,
9997

10098
use_display_control: false,
@@ -198,12 +196,6 @@ impl iron_remote_desktop::SessionBuilder for SessionBuilder {
198196
self.clone()
199197
}
200198

201-
/// Optional
202-
fn remote_received_format_list_callback(&self, callback: js_sys::Function) -> Self {
203-
self.0.borrow_mut().remote_received_format_list_callback = Some(callback);
204-
self.clone()
205-
}
206-
207199
/// Optional
208200
fn force_clipboard_update_callback(&self, callback: js_sys::Function) -> Self {
209201
self.0.borrow_mut().force_clipboard_update_callback = Some(callback);
@@ -253,7 +245,6 @@ impl iron_remote_desktop::SessionBuilder for SessionBuilder {
253245
set_cursor_style_callback,
254246
set_cursor_style_callback_context,
255247
remote_clipboard_changed_callback,
256-
remote_received_format_list_callback,
257248
force_clipboard_update_callback,
258249
outbound_message_size_limit,
259250
);
@@ -283,7 +274,6 @@ impl iron_remote_desktop::SessionBuilder for SessionBuilder {
283274
.clone()
284275
.context("set_cursor_style_callback_context missing")?;
285276
remote_clipboard_changed_callback = inner.remote_clipboard_changed_callback.clone();
286-
remote_received_format_list_callback = inner.remote_received_format_list_callback.clone();
287277
force_clipboard_update_callback = inner.force_clipboard_update_callback.clone();
288278
outbound_message_size_limit = inner.outbound_message_size_limit;
289279
}
@@ -302,7 +292,6 @@ impl iron_remote_desktop::SessionBuilder for SessionBuilder {
302292
clipboard::WasmClipboardMessageProxy::new(input_events_tx.clone()),
303293
clipboard::JsClipboardCallbacks {
304294
on_remote_clipboard_changed: callback,
305-
on_remote_received_format_list: remote_received_format_list_callback,
306295
on_force_clipboard_update: force_clipboard_update_callback,
307296
},
308297
)

web-client/iron-remote-desktop/src/enums/SessionEventType.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
STARTED,
33
TERMINATED,
44
ERROR,
5+
6+
// Clipboard events
7+
CLIPBOARD_REMOTE_UPDATE,
58
}

web-client/iron-remote-desktop/src/interfaces/UserInteraction.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,11 @@ export interface UserInteraction {
3131

3232
setEnableClipboard(enable: boolean): void;
3333

34+
setEnableAutoClipboard(enable: boolean): void;
35+
36+
saveRemoteClipboardData(): Promise<boolean>;
37+
38+
sendClipboardData(): Promise<boolean>;
39+
3440
invokeExtension(ext: Extension): void;
3541
}

0 commit comments

Comments
 (0)