@@ -13,33 +13,45 @@ const detectRouteData = (value: string) => {
13
13
14
14
// Json
15
15
try {
16
- JSON . parse ( value ) ;
17
- return { route : '/json-formatter' , state : { input1 : value } } ;
16
+ if ( typeof JSON . parse ( value ) === 'object' ) {
17
+ return { route : '/json-formatter' , state : { input1 : value } } ;
18
+ }
18
19
} catch ( e ) {
19
20
// ignore
20
21
}
21
22
22
23
return { } ;
23
24
} ;
24
25
26
+ interface LocationState {
27
+ auto : boolean ;
28
+ }
29
+
25
30
const Auto = ( ) => {
26
31
const [ value , setValue ] = useState ( '' ) ;
27
32
const [ hotkey , setHotkey ] = useState ( '' ) ;
28
33
const history = useHistory ( ) ;
29
- const location = useLocation ( ) ;
34
+ const location = useLocation < LocationState > ( ) ;
30
35
31
36
useEffect ( ( ) => {
32
- setValue ( clipboard . readText ( ) ) ;
37
+ if ( location . state && location . state . auto ) {
38
+ setValue ( clipboard . readText ( ) ) ;
39
+ }
33
40
} , [ location ] ) ;
34
41
35
42
useEffect ( ( ) => {
43
+ let isMounted = true ;
36
44
ipcRenderer
37
45
. invoke ( 'get-store' , { key : 'hotkey' } )
38
46
. then ( ( v : string ) => {
39
- setHotkey ( v ) ;
47
+ if ( isMounted ) setHotkey ( v ) ;
40
48
return null ;
41
49
} )
42
50
. catch ( ( ) => { } ) ;
51
+
52
+ return ( ) => {
53
+ isMounted = false ;
54
+ } ;
43
55
} ) ;
44
56
45
57
useEffect ( ( ) => {
@@ -70,12 +82,29 @@ const Auto = () => {
70
82
) }
71
83
</ section >
72
84
< div className = "flex items-center justify-between w-full my-1" >
73
- < span > No tools was detected for this content:</ span >
74
- < button type = "button" className = "w-16 btn" onClick = { ( ) => setValue ( '' ) } >
75
- Clear
76
- </ button >
85
+ < section className = "flex items-center space-x-2" >
86
+ < button
87
+ type = "button"
88
+ className = "btn"
89
+ onClick = { ( ) => setValue ( clipboard . readText ( ) ) }
90
+ >
91
+ Clipboard
92
+ </ button >
93
+ < button
94
+ type = "button"
95
+ className = "w-16 btn"
96
+ onClick = { ( ) => setValue ( '' ) }
97
+ >
98
+ Clear
99
+ </ button >
100
+ </ section >
101
+ { value ? < span > No tools was detected for this content</ span > : < span /> }
77
102
</ div >
78
- < textarea className = "flex w-full p-2 h-1/3" value = { value } readOnly />
103
+ < textarea
104
+ className = "flex w-full p-2 h-1/3"
105
+ value = { value }
106
+ onChange = { ( e ) => setValue ( e . target . value ) }
107
+ />
79
108
</ div >
80
109
) ;
81
110
} ;
0 commit comments