Skip to content

Commit

Permalink
Use notepad to print instead of printer library
Browse files Browse the repository at this point in the history
The printer library is currently not working (alexbrainman/printer#24)

Signed-off-by: Feggah <[email protected]>
  • Loading branch information
Feggah committed Apr 21, 2022
1 parent 03c1def commit be26df1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.18
require (
fyne.io/fyne/v2 v2.1.4
github.com/Knetic/govaluate v3.0.0+incompatible
github.com/alexbrainman/printer v0.0.0-20200912035444-f40f26f0bdeb
)

require (
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ github.com/Knetic/govaluate v3.0.0+incompatible h1:7o6+MAPhYTCF0+fdvoz1xDedhRb4f
github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/alexbrainman/printer v0.0.0-20200912035444-f40f26f0bdeb h1:OzF7h5OJLiB2QvpxfFdUFdSedYYsEKAXnE8BwsWQPmY=
github.com/alexbrainman/printer v0.0.0-20200912035444-f40f26f0bdeb/go.mod h1:aeB9oSJ1VNJXxBkCz6Krw3aW8lPx6rkWnW/hXcoujR4=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down Expand Up @@ -72,7 +70,6 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
28 changes: 16 additions & 12 deletions printer/printer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package printer

import (
"fmt"
"os"
"os/exec"
"time"

_ "time/tzdata"
Expand All @@ -11,7 +12,6 @@ import (
"fyne.io/fyne/v2/widget"

"github.com/Feggah/calculator/utils"
"github.com/alexbrainman/printer"
)

const (
Expand Down Expand Up @@ -65,28 +65,32 @@ func (p *Printer) ShowPrinterPopUp() {
}

func (p *Printer) print() {
parsedContent := parseContent(p.content)
name, err := printer.Default()
content := "Titulo: " + p.title + "\n" + "Horario: " + getLocalTimestamp() + "\n\n" + parseContent(p.content)

file, err := os.CreateTemp("", p.title)
if err != nil {
p.showErrorPopUp(err)
return
}

prt, err := printer.Open(name)
if err != nil {
defer func() {
file.Close()
if err := os.Remove(file.Name()); err != nil {
p.showErrorPopUp(err)
return
}
}()

if _, err := file.WriteString(content); err != nil {
p.showErrorPopUp(err)
return
}
defer prt.Close()

if err := prt.StartRawDocument(p.title); err != nil {
cmd := exec.Command("cmd.exe", "/C", "notepad", "/p", file.Name())
if err := cmd.Run(); err != nil {
p.showErrorPopUp(err)
return
}
defer prt.EndDocument()

content := "Titulo: " + p.title + "\n" + "Horario: " + getLocalTimestamp() + "\n\n" + parsedContent
fmt.Fprintf(prt, "%s", content)
}

func (p *Printer) showErrorPopUp(err error) {
Expand Down

0 comments on commit be26df1

Please sign in to comment.