-
-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Init() #18
Add Init() #18
Conversation
please check @changkun |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how useful this is. Is this PR relevant to #19 ?
I've just seen #13 for the first time, but the problem we want to solve is the same: changing the interface will cause problems for existing applications, so the implementation is backwards compatible.
Checking the implementation in init makes sense and is useful for some users. However, it also narrows down the use cases, and in my opinion, it would be great if the architecture was error-free in import. |
clipboard_linux.go
Outdated
@@ -77,6 +81,10 @@ func read(t Format) (buf []byte, err error) { | |||
} | |||
|
|||
func readc(t string) ([]byte, error) { | |||
if !canAccessClipbord && !test() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate more on why do we need this check at every call?
We believe that if you can access clipbord once, you can always access it a second time or later. Therefore, to eliminate the overhead, we use canAccessClipbord to manage it.
|
I think if one can pass Init(), then the system environment is sufficient to access clipboard information. However, indeed it may fail at some point for some reason. But as the current API is designed to behave: if there is an error when accessing the clipboard, it returns nothing and one may retry calling it afterward. Panic after the success of Init is an undesired behavior as discussed in #19. |
If you are using Linux without X11 enabled, an error will occur at the time of import.
Add Test() methods to check if the clipboard is accessible for conditional branching.
Fixes #19