File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -81,10 +81,14 @@ const (
8181	FmtImage 
8282)
8383
84- // Due to the limitation on operating systems (such as darwin), 
85- // concurrent read can even cause panic, use a global lock to 
86- // guarantee one read at a time. 
87- var  lock  =  sync.Mutex {}
84+ var  (
85+ 	// Due to the limitation on operating systems (such as darwin), 
86+ 	// concurrent read can even cause panic, use a global lock to 
87+ 	// guarantee one read at a time. 
88+ 	lock  =  sync.Mutex {}
89+ 	initOnce  sync.Once 
90+ 	initError  error 
91+ )
8892
8993// Init initializes the clipboard package. It returns an error 
9094// if the clipboard is not available to use. This may happen if the 
@@ -99,7 +103,10 @@ var lock = sync.Mutex{}
99103// If Init returns an error, any subsequent Read/Write/Watch call 
100104// may result in an unrecoverable panic. 
101105func  Init () error  {
102- 	return  initialize ()
106+ 	initOnce .Do (func () {
107+ 		initError  =  initialize ()
108+ 	})
109+ 	return  initError 
103110}
104111
105112// Read returns a chunk of bytes of the clipboard data if it presents 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments