-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
poc: add customized format register for darwin
See #17
- Loading branch information
Showing
5 changed files
with
146 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
/* | ||
#cgo CFLAGS: -x objective-c | ||
#cgo LDFLAGS: -framework Foundation -framework Cocoa | ||
#import <Foundation/Foundation.h> | ||
#import <Cocoa/Cocoa.h> | ||
*/ | ||
import "C" | ||
import ( | ||
"os" | ||
"unsafe" | ||
|
||
"golang.design/x/clipboard" | ||
) | ||
|
||
var f = unsafe.Pointer(C.NSPasteboardTypePDF) | ||
|
||
type audioHandler struct{} | ||
|
||
func (ah *audioHandler) Format() interface{} { return f } | ||
|
||
func main() { | ||
err := clipboard.Init() | ||
if err != nil { | ||
panic(err) | ||
} | ||
clipboard.Register(&audioHandler{}) | ||
|
||
content, err := os.ReadFile("~/test.pdf") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clipboard.Write(f, content) | ||
b := clipboard.Read(clipboard.FmtText) | ||
os.WriteFile("x.txt", b, os.ModePerm) | ||
} |