Skip to content

Commit

Permalink
feat: Add highlight threshold to enable highlighting when exceeding X…
Browse files Browse the repository at this point in the history
… hours (#18)

closes #13
  • Loading branch information
danstis authored Feb 12, 2019
1 parent 0d77026 commit b89009a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions config.toml.default
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ email = "" # Your Email address to send with requests to teh toggl API
userId = "" # Get from URL segment when selecting the individual user in this report: https://toggl.com/app/reports/weekly
workspaceId = "" # Get from URL segment when opening settings of the workspace from this page: https://toggl.com/app/workspaces
syncInterval = 5 # Sync interval in minutes. This controls how often the app checks for updates
highlightThreshold = 40 # Threshold in hours to control highlighting
32 changes: 17 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"bytes"
"fmt"
"image/color"
"log"
"time"

Expand All @@ -26,11 +25,12 @@ type togglTime struct {

// Settings contains the application configuration
type Settings struct {
Token string `toml:"token"`
UserID string `toml:"userId"`
WorkspaceID string `toml:"workspaceId"`
Email string `toml:"email"`
SyncInterval int `toml:"syncInterval"`
Token string `toml:"token"`
UserID string `toml:"userId"`
WorkspaceID string `toml:"workspaceId"`
Email string `toml:"email"`
SyncInterval int `toml:"syncInterval"`
HighlightThreshold int `toml:"highlightThreshold"`
}

// Main entry point for the app.
Expand All @@ -45,7 +45,7 @@ func onReady() {
if err != nil {
log.Fatalf("Failed to read configuration file: %v", err)
}
updateIcon("00")
updateIcon(0, config.HighlightThreshold)
mVersion := systray.AddMenuItem(fmt.Sprintf("Toggl Weekly Tracker v%v", Version), "Version")
mVersion.Disable()
systray.AddSeparator()
Expand All @@ -65,7 +65,7 @@ func onReady() {
log.Printf("Failed to get Toggl details: %v\n", err)
}
log.Printf("- Got new time %d:%02d\n", t.hours, t.minutes) // TODO: remove this when logging goes away
updateIcon(fmt.Sprintf("%v", t.hours))
updateIcon(int(t.hours), config.HighlightThreshold)
mTime.SetTitle(fmt.Sprintf("This week: %d:%02d", t.hours, t.minutes))
systray.SetTooltip(fmt.Sprintf("Toggl time tracker: %d:%02d", t.hours, t.minutes))
time.Sleep(time.Duration(config.SyncInterval) * time.Minute)
Expand Down Expand Up @@ -169,25 +169,27 @@ func getMinutes(t time.Duration) int {
return int(m)
}

func updateIcon(hours string) {
icon, err := createIcon(16, 16, hours)
func updateIcon(hours, threshold int) {
icon, err := createIcon(16, 16, hours, threshold)
if err != nil {
log.Fatalf("Error generating icon: %v", err)
}
systray.SetIcon(icon)
}

func createIcon(x, y int, label string) ([]byte, error) {
func createIcon(x, y, hours, threshold int) ([]byte, error) {
dc := gg.NewContext(x, y)
// Create a trasparant background
dc.SetColor(color.Transparent)
dc.Clear()
if hours >= threshold {
// Create a red background
dc.SetHexColor("#9E0000")
dc.Clear()
}
// Add Text
dc.SetHexColor("#FFFFFF")
if err := dc.LoadFontFace("assets/fonts/Go-Bold.ttf", 14); err != nil {
return []byte{}, err
}
dc.DrawStringAnchored(label, float64(x/2), float64(y/2), 0.5, 0.5)
dc.DrawStringAnchored(fmt.Sprintf("%v", hours), float64(x/2), float64(y/2), 0.5, 0.5)

buf := new(bytes.Buffer)
err := ico.Encode(buf, dc.Image())
Expand Down

0 comments on commit b89009a

Please sign in to comment.