1
1
use std:: { io:: BufReader , path:: Path , time:: Duration } ;
2
2
3
3
use anyhow:: { bail, Context , Result } ;
4
- use arboard:: { Clipboard , GetExtLinux } ;
4
+ use arboard:: Clipboard ;
5
+
6
+ #[ cfg( target_os = "linux" ) ]
7
+ use arboard:: GetExtLinux ;
8
+
5
9
use chinese_detection:: { classify, ClassificationResult } ;
6
10
use clap:: Parser ;
7
11
use db:: Answer ;
8
12
use explain:: YdcvResp ;
9
13
use once_cell:: sync:: Lazy ;
14
+
15
+ #[ cfg( target_os = "linux" ) ]
10
16
use parking_lot:: RwLock ;
11
17
use reqwest:: Client ;
12
18
// use tempdir::TempDir;
@@ -19,6 +25,7 @@ mod explain;
19
25
20
26
const REQUEST_BASE : & ' static str = "http://fanyi.youdao.com/openapi.do?keyfrom=ydcv-rust&key=379421805&type=data&doctype=json&version=1.1&q=" ;
21
27
28
+ #[ cfg( target_os = "linux" ) ]
22
29
static CACHED_CONTENT : RwLock < ( Option < String > , Option < String > ) > = RwLock :: new ( ( None , None ) ) ;
23
30
24
31
#[ derive( Parser , Debug ) ]
@@ -28,13 +35,15 @@ struct Args {
28
35
daemon_mode : bool ,
29
36
}
30
37
38
+ #[ cfg( target_os = "linux" ) ]
31
39
fn get_selected_text ( clip : & mut Clipboard ) -> Option < String > {
32
40
let g = clip. get ( ) ;
33
41
let g = g. clipboard ( arboard:: LinuxClipboardKind :: Primary ) ;
34
42
35
43
g. text ( ) . ok ( )
36
44
}
37
45
46
+ #[ cfg( target_os = "linux" ) ]
38
47
fn get_copied_text ( clip : & mut Clipboard ) -> Option < String > {
39
48
let g = clip. get ( ) ;
40
49
let g = g. clipboard ( arboard:: LinuxClipboardKind :: Clipboard ) ;
@@ -43,26 +52,29 @@ fn get_copied_text(clip: &mut Clipboard) -> Option<String> {
43
52
}
44
53
45
54
fn get_clipboard_content ( clip : & mut Clipboard ) -> Option < String > {
46
- let copied_text = get_copied_text ( clip) ;
47
- let selected_text = get_selected_text ( clip) ;
55
+ #[ cfg( target_os = "linux" ) ]
56
+ {
57
+ let copied_text = get_copied_text ( clip) ;
58
+ let selected_text = get_selected_text ( clip) ;
48
59
49
- if let Some ( copied_text) = copied_text {
50
- if CACHED_CONTENT . read ( ) . 0 . as_ref ( ) != Some ( & copied_text) {
51
- CACHED_CONTENT . write ( ) . 0 = Some ( copied_text. clone ( ) ) ;
60
+ if let Some ( copied_text) = copied_text {
61
+ if CACHED_CONTENT . read ( ) . 0 . as_ref ( ) != Some ( & copied_text) {
62
+ CACHED_CONTENT . write ( ) . 0 = Some ( copied_text. clone ( ) ) ;
52
63
53
- return Some ( copied_text) ;
64
+ return Some ( copied_text) ;
65
+ }
54
66
}
55
- }
56
67
57
- if let Some ( selected_text) = selected_text {
58
- if CACHED_CONTENT . read ( ) . 1 . as_ref ( ) != Some ( & selected_text) {
59
- CACHED_CONTENT . write ( ) . 1 = Some ( selected_text. clone ( ) ) ;
68
+ if let Some ( selected_text) = selected_text {
69
+ if CACHED_CONTENT . read ( ) . 1 . as_ref ( ) != Some ( & selected_text) {
70
+ CACHED_CONTENT . write ( ) . 1 = Some ( selected_text. clone ( ) ) ;
60
71
61
- return Some ( selected_text) ;
72
+ return Some ( selected_text) ;
73
+ }
62
74
}
63
75
}
64
76
65
- None
77
+ clip . get_text ( ) . ok ( )
66
78
}
67
79
68
80
fn main ( ) -> Result < ( ) > {
0 commit comments