From 6073b9737ddb4987d6fe2644ff24d8bb6f0f4c71 Mon Sep 17 00:00:00 2001 From: Dan Anstis Date: Sat, 15 Jul 2023 17:25:35 +1000 Subject: [PATCH] feat: embed font file into generated binary (#95) --- .gitignore | 1 + .goreleaser.yml | 3 +-- README.md | 2 +- go.mod | 2 -- go.sum | 10 ---------- main.go | 22 ++++++++++++++++++---- 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index ca22fa7..f3f6b3f 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ /.vscode /dist .aider.* +/Go-Bold.ttf \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml index a406635..355024c 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -23,7 +23,6 @@ builds: archives: - format: zip files: - - "assets/*" - "*.md" - "LICENSE" - "config.toml" @@ -32,7 +31,7 @@ checksum: snapshot: name_template: "{{.Tag}}-snapshot#{{.Commit}}" release: - discussion_category_name: General + discussion_category_name: Releases mode: append prerelease: auto changelog: diff --git a/README.md b/README.md index b92296f..cffd968 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Want to contribute? Great! To fix a bug or add an enhancement: * Fork the repo -* Install development dependancies: +* Install development dependencies: * Install goversioninfo `go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo && go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo` * Install GitVersion `choco install gitversion.portable` * Create a new branch ( `git checkout -b improve-feature` ) diff --git a/go.mod b/go.mod index bf87468..38289dd 100644 --- a/go.mod +++ b/go.mod @@ -11,10 +11,8 @@ require ( ) require ( - github.com/akavel/rsrc v0.10.2 // indirect github.com/godbus/dbus/v5 v5.0.4 // indirect github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect - github.com/josephspurrier/goversioninfo v1.4.0 // indirect github.com/tevino/abool v1.2.0 // indirect golang.org/x/image v0.9.0 // indirect golang.org/x/net v0.12.0 // indirect diff --git a/go.sum b/go.sum index a7f4524..1609f9f 100644 --- a/go.sum +++ b/go.sum @@ -4,20 +4,12 @@ github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8 github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9 h1:1ltqoej5GtaWF8jaiA49HwsZD459jqm9YFz9ZtMFpQA= github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I= -github.com/akavel/rsrc v0.10.2 h1:Zxm8V5eI1hW4gGaYsJQUhxpjkENuG91ki8B4zCrvEsw= -github.com/akavel/rsrc v0.10.2/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8= github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/godbus/dbus/v5 v5.0.4 h1:9349emZab16e7zQvpmsbtjc18ykshndd8y2PG3sgJbA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= -github.com/josephspurrier/goversioninfo v1.4.0 h1:Puhl12NSHUSALHSuzYwPYQkqa2E1+7SrtAPJorKK0C8= -github.com/josephspurrier/goversioninfo v1.4.0/go.mod h1:JWzv5rKQr+MmW+LvM412ToT/IkYDZjaclF2pKDss8IY= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tevino/abool v1.2.0 h1:heAkClL8H6w+mK5md9dzsuohKeXHUpY7Vw0ZCKW+huA= github.com/tevino/abool v1.2.0/go.mod h1:qc66Pna1RiIsPa7O4Egxxs9OqkuxDX55zznh9K07Tzg= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= @@ -59,7 +51,5 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/resty.v1 v1.12.0 h1:CuXP0Pjfw9rOuY6EP+UvtNvt5DSqHpIxILZKT/quCZI= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index 8aa6a5c..e423778 100644 --- a/main.go +++ b/main.go @@ -3,8 +3,10 @@ package main import ( "bytes" + _ "embed" "fmt" "log" + "os" "time" "fyne.io/systray" @@ -16,7 +18,9 @@ import ( // Version info maintained by goreleaser: https://goreleaser.com/cookbooks/using-main.version/ var ( - version = "dev" + version = "0.0.0-dev" + //go:embed assets/fonts/Go-Bold.ttf + embeddedFont []byte ) const ( @@ -45,11 +49,21 @@ type Workspaces struct { Name string `json:"name"` } -// Main entry point for the app. func main() { + unpackFont() systray.Run(onReady, onExit) } +func unpackFont() { + log.Printf("Unpacking font file...") + fontPath := "Go-Bold.ttf" + if _, err := os.Stat(fontPath); os.IsNotExist(err) { + if err := os.WriteFile(fontPath, embeddedFont, 0644); err != nil { + log.Fatalf("Failed to write font file to disk: %v", err) + } + } +} + func onReady() { // Get the settings var config Settings @@ -220,7 +234,7 @@ func getOpenTimeEntry(c *Settings, w string) (time.Duration, error) { } // Calculate the number of seconds based on the input data. - // Unix epoc plus returned value of duration = seconds the current entry has been running for. + // Unix epoch plus returned value of duration = seconds the current entry has been running for. od := int32(time.Now().Unix()) + ot.Data.Duration return time.Duration(od) * time.Second, nil @@ -272,7 +286,7 @@ func createIcon(x, y, hours, threshold int) ([]byte, error) { } // Add Text dc.SetHexColor("#FFFFFF") - if err := dc.LoadFontFace("assets/fonts/Go-Bold.ttf", 14); err != nil { + if err := dc.LoadFontFace("Go-Bold.ttf", 14); err != nil { return []byte{}, err } dc.DrawStringAnchored(fmt.Sprintf("%v", hours), float64(x/2), float64(y/2), 0.5, 0.5)