@@ -223,6 +223,40 @@ pub async fn copy_image_to_clipboard(
223223 . map_err ( |_| "clipboard result channel closed unexpectedly" . to_string ( ) ) ?
224224}
225225
226+ /// Write text to the system clipboard through the native shell.
227+ ///
228+ /// WebKit can revoke browser clipboard permission after a user action awaits a
229+ /// long-running operation such as snapshot encoding and upload. Keeping the
230+ /// delayed write in the native layer makes that flow reliable on macOS.
231+ #[ tauri:: command]
232+ pub async fn copy_text_to_clipboard (
233+ text : String ,
234+ html : Option < String > ,
235+ app : tauri:: AppHandle ,
236+ ) -> Result < ( ) , String > {
237+ let ( tx, rx) = std:: sync:: mpsc:: sync_channel :: < Result < ( ) , String > > ( 1 ) ;
238+ app. run_on_main_thread ( move || {
239+ let result = arboard:: Clipboard :: new ( )
240+ . map_err ( |e| format ! ( "clipboard error: {e}" ) )
241+ . and_then ( |mut clipboard| {
242+ if let Some ( html) = html {
243+ clipboard
244+ . set_html ( html, Some ( text) )
245+ . map_err ( |e| format ! ( "clipboard error: {e}" ) )
246+ } else {
247+ clipboard
248+ . set_text ( text)
249+ . map_err ( |e| format ! ( "clipboard error: {e}" ) )
250+ }
251+ } ) ;
252+ let _ = tx. send ( result) ;
253+ } )
254+ . map_err ( |e| format ! ( "main thread dispatch failed: {e}" ) ) ?;
255+
256+ rx. recv ( )
257+ . map_err ( |_| "clipboard result channel closed unexpectedly" . to_string ( ) ) ?
258+ }
259+
226260/// Fetch blob bytes from a (pre-validated) relay media URL through the app's
227261/// HTTP client, enforcing the download size cap. The caller is responsible for
228262/// validating the URL origin and for any content-type checks on the result.
0 commit comments