Skip to content

Commit

Permalink
Handle error from the file watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
naspeh committed Apr 25, 2024
1 parent 55cc22f commit 62b360b
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions timefor.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ func Daemon(
}
if lastHook != cmd {
lastHook = cmd
fmt.Printf("running hook command: %s\n", cmd)
log.Printf("running hook command: %s\n", cmd)
err = exec.Command("sh", "-c", cmd).Run()
if err != nil {
return fmt.Errorf("cannot run hook command: %v", err)
Expand All @@ -528,7 +528,7 @@ func Daemon(
}
err := exec.Command("notify-send", args...).Run()
if err != nil {
fmt.Printf("cannot send notification: %v", err)
log.Printf("cannot send notification: %v\n", err)
}
notified = time.Now()
}
Expand All @@ -540,10 +540,13 @@ func Daemon(
select {
case c := <-change:
log.Println("change", c)
if c.Error != nil {
return c.Error
}

case <-time.After(nextUpdate):
if activity.Active() && time.Since(activity.Updated()) > time.Minute {
fmt.Printf("updating time for %s\n", activity.Name)
log.Printf("updating time for %s\n", activity.Name)
_, err := UpdateIfExists(db, "", false)
if err != nil {
return err
Expand Down Expand Up @@ -680,14 +683,6 @@ func Report(db *sqlx.DB) (title, desc string, err error) {
return title, buf.String(), nil
}

func formatDuration(d time.Duration) string {
d = d.Truncate(time.Minute)
h := d / time.Hour
d -= h * time.Hour
m := d / time.Minute
return fmt.Sprintf("%02d:%02d", h, m)
}

// Select selects new activity using rofi menu
func Select(db *sqlx.DB) (string, error) {
var names []string
Expand Down Expand Up @@ -726,6 +721,14 @@ func Select(db *sqlx.DB) (string, error) {
return string(selectedName), nil
}

func formatDuration(d time.Duration) string {
d = d.Truncate(time.Minute)
h := d / time.Hour
d -= h * time.Hour
m := d / time.Minute
return fmt.Sprintf("%02d:%02d", h, m)
}

// Activity represents a named activity
type Activity struct {
ID int64
Expand Down

0 comments on commit 62b360b

Please sign in to comment.