Skip to content

Commit

Permalink
feat: embed font file into generated binary (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
danstis committed Jul 15, 2023
1 parent 38cc71f commit 6073b97
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
/.vscode
/dist
.aider.*
/Go-Bold.ttf
3 changes: 1 addition & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ builds:
archives:
- format: zip
files:
- "assets/*"
- "*.md"
- "LICENSE"
- "config.toml"
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` )
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
22 changes: 18 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package main

import (
"bytes"
_ "embed"
"fmt"
"log"
"os"
"time"

"fyne.io/systray"
Expand All @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6073b97

Please sign in to comment.