@@ -3,6 +3,7 @@ use sha2::{Digest, Sha256};
33use tauri:: State ;
44
55use crate :: app_state:: AppState ;
6+ use crate :: commands:: clipboard:: with_clipboard;
67use crate :: commands:: export_util:: save_bytes_with_dialog;
78use crate :: commands:: media:: { detect_and_validate_mime, mint_media_get_auth, sanitize_filename} ;
89use crate :: commands:: {
@@ -201,18 +202,15 @@ pub async fn copy_image_to_clipboard(
201202 // arboard requires main-thread access on macOS. Use a sync channel so the
202203 // async command can await the result.
203204 let ( tx, rx) = std:: sync:: mpsc:: sync_channel :: < Result < ( ) , String > > ( 1 ) ;
205+ let clipboard_app = app. clone ( ) ;
204206 app. run_on_main_thread ( move || {
205- let result = arboard:: Clipboard :: new ( )
206- . map_err ( |e| format ! ( "clipboard error: {e}" ) )
207- . and_then ( |mut clipboard| {
208- clipboard
209- . set_image ( arboard:: ImageData {
210- width,
211- height,
212- bytes : std:: borrow:: Cow :: Owned ( raw) ,
213- } )
214- . map_err ( |e| format ! ( "clipboard error: {e}" ) )
215- } ) ;
207+ let result = with_clipboard ( & clipboard_app, |clipboard| {
208+ clipboard. set_image ( arboard:: ImageData {
209+ width,
210+ height,
211+ bytes : std:: borrow:: Cow :: Owned ( raw) ,
212+ } )
213+ } ) ;
216214 // Ignore send errors — the receiver dropped only if the command was
217215 // cancelled, in which case nobody is waiting for the result.
218216 let _ = tx. send ( result) ;
@@ -235,20 +233,15 @@ pub async fn copy_text_to_clipboard(
235233 app : tauri:: AppHandle ,
236234) -> Result < ( ) , String > {
237235 let ( tx, rx) = std:: sync:: mpsc:: sync_channel :: < Result < ( ) , String > > ( 1 ) ;
236+ let clipboard_app = app. clone ( ) ;
238237 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- } ) ;
238+ let result = with_clipboard ( & clipboard_app, |clipboard| {
239+ if let Some ( html) = html {
240+ clipboard. set_html ( html, Some ( text) )
241+ } else {
242+ clipboard. set_text ( text)
243+ }
244+ } ) ;
252245 let _ = tx. send ( result) ;
253246 } )
254247 . map_err ( |e| format ! ( "main thread dispatch failed: {e}" ) ) ?;
0 commit comments