1+ //! Windows clipboard implementation using clipboard-win crate
2+ //!
3+ //! Provides clipboard functionality on Windows using the clipboard-win crate,
4+ //! which wraps the Windows clipboard API.
5+
16use crate :: clipboard:: manager:: ClipboardManager ;
27use crate :: error:: KeyringError ;
8+ use clipboard_win:: { get_clipboard_string, set_clipboard_string, empty_clipboard} ;
39use std:: time:: Duration ;
410
511pub struct WindowsClipboard ;
612
713impl ClipboardManager for WindowsClipboard {
814 fn set_content ( & mut self , content : & str ) -> Result < ( ) , KeyringError > {
9- // In a real implementation, this would use Windows clipboard API
10- // For now, we'll simulate it
11- println ! ( "[MOCK] Setting Windows clipboard content: {}" , content) ;
12- Ok ( ( ) )
15+ set_clipboard_string ( content)
16+ . map_err ( |e| KeyringError :: Clipboard { context : format ! ( "Failed to set clipboard: {}" , e) } )
1317 }
1418
1519 fn get_content ( & mut self ) -> Result < String , KeyringError > {
16- // In a real implementation, this would read from Windows clipboard
17- println ! ( "[MOCK] Reading from Windows clipboard" ) ;
18- Ok ( "mock_clipboard_content" . to_string ( ) )
20+ get_clipboard_string ( )
21+ . map_err ( |e| KeyringError :: Clipboard { context : format ! ( "Failed to get clipboard: {}" , e) } )
1922 }
2023
2124 fn clear ( & mut self ) -> Result < ( ) , KeyringError > {
22- // In a real implementation, this would clear the Windows clipboard
23- println ! ( "[MOCK] Clearing Windows clipboard" ) ;
24- Ok ( ( ) )
25+ empty_clipboard ( )
26+ . map_err ( |e| KeyringError :: Clipboard { context : format ! ( "Failed to clear clipboard: {}" , e) } )
2527 }
2628
2729 fn is_supported ( & self ) -> bool {
@@ -32,3 +34,49 @@ impl ClipboardManager for WindowsClipboard {
3234 Duration :: from_secs ( 30 )
3335 }
3436}
37+
38+ #[ cfg( test) ]
39+ mod tests {
40+ use super :: * ;
41+
42+ #[ test]
43+ fn test_set_and_get_clipboard ( ) {
44+ let mut clipboard = WindowsClipboard ;
45+
46+ // Set clipboard content
47+ let test_content = "Test clipboard content" ;
48+ clipboard. set_content ( test_content) . unwrap ( ) ;
49+
50+ // Get clipboard content
51+ let retrieved = clipboard. get_content ( ) . unwrap ( ) ;
52+ assert_eq ! ( retrieved, test_content) ;
53+ }
54+
55+ #[ test]
56+ fn test_clear_clipboard ( ) {
57+ let mut clipboard = WindowsClipboard ;
58+
59+ // Set content
60+ clipboard. set_content ( "Temporary content" ) . unwrap ( ) ;
61+
62+ // Clear
63+ clipboard. clear ( ) . unwrap ( ) ;
64+
65+ // Verify it's empty or different
66+ let content = clipboard. get_content ( ) . unwrap ( ) ;
67+ // After clearing, clipboard might be empty or contain previous content from other apps
68+ // We just verify the operation didn't error
69+ }
70+
71+ #[ test]
72+ fn test_is_supported ( ) {
73+ let clipboard = WindowsClipboard ;
74+ assert ! ( clipboard. is_supported( ) ) ;
75+ }
76+
77+ #[ test]
78+ fn test_timeout ( ) {
79+ let clipboard = WindowsClipboard ;
80+ assert_eq ! ( clipboard. timeout( ) , Duration :: from_secs( 30 ) ) ;
81+ }
82+ }
0 commit comments