Skip to content

Commit

Permalink
Fix clipboard translation
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronkinsella committed Apr 18, 2022
1 parent 6594847 commit 3e19f27
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
11 changes: 9 additions & 2 deletions cmd/manga-translator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,20 @@ func main() {
if !*clipImagePtr {
imgPath = flag.Args()
log.Infof("All Selected Image(s): %v", imgPath)
} else {
// Need a single element in the array so that it will try to open 1 image. The path itself is not used.
imgPath = append(imgPath, "clipboard")
}

if len(imgPath) == 0 {
log.Fatal("No images provided.")
}

var img []imageW.TranslatorImage

for _, imgPath := range imgPath {
for _, paths := range imgPath {
log.Debugf("Getting image info for: %v", imgPath)
newImage := imageW.Open(imgPath, *urlImagePtr, *clipImagePtr)
newImage := imageW.Open(paths, *urlImagePtr, *clipImagePtr)
img = append(img, newImage)
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ require (
github.com/inancgumus/screen v0.0.0-20190314163918-06e984b86ed3
github.com/sirupsen/logrus v1.8.1
github.com/spf13/viper v1.11.0
golang.design/x/clipboard v0.5.3
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d
golang.design/x/clipboard v0.6.2
golang.org/x/image v0.0.0-20211028202545-6944b10bf410
golang.org/x/text v0.3.7
google.golang.org/api v0.74.0
google.golang.org/genproto v0.0.0-20220414192740-2d67ff6cf2b4
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
golang.design/x/clipboard v0.5.3 h1:JUxlkxohMUtpFcwPu1JjsAlkndNq8UVVeOBDAGE/il8=
golang.design/x/clipboard v0.5.3/go.mod h1:ep0pB+/4DGJK3ayLxweWJFHhHGGv3npJJHMXAjtLTUM=
golang.design/x/clipboard v0.6.2 h1:a3Np4qfKnLWwfFJQhUWU3IDeRfmVuqWl+QPtP4CSYGw=
golang.design/x/clipboard v0.6.2/go.mod h1:kqBSweBP0/im4SZGGjLrppH0D400Hnfo5WbFKSNK8N4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand All @@ -282,6 +284,8 @@ golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMx
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/image v0.0.0-20211028202545-6944b10bf410 h1:hTftEOvwiOq2+O8k2D5/Q7COC7k5Qcrgc2TFURJYnvQ=
golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
9 changes: 8 additions & 1 deletion pkg/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ func Open(file string, url, clip bool) TranslatorImage {
var size int

if clip {
var err error

// Init returns an error if the package is not ready for use.
err = clipboard.Init()
if err != nil {
log.Fatal(err)
}

imgByte := clipboard.Read(clipboard.FmtImage)
if imgByte == nil {
log.Fatal("Image not found in clipboard")
Expand All @@ -48,7 +56,6 @@ func Open(file string, url, clip bool) TranslatorImage {
var buf bytes.Buffer
tee := io.TeeReader(bytes.NewReader(imgByte), &buf)

var err error
img, _, err = image.Decode(tee)
size = buf.Len()
if err != nil {
Expand Down

0 comments on commit 3e19f27

Please sign in to comment.