feat: add possibility to track time in timewarrior as well
Some checks failed
Go CI Pipeline / ci (push) Has been cancelled

This commit is contained in:
Patryk Hegenberg 2025-10-10 09:07:15 +02:00
parent 127018b565
commit c0a83b5892
4 changed files with 44 additions and 15 deletions

View file

@ -113,7 +113,7 @@ func (ts *TimeStore) stopCurrentEntry(now time.Time) (bool, error) {
return rowsAffected > 0, nil
}
func (ts *TimeStore) StartTracking(tag string) error {
func (ts *TimeStore) StartTracking(tag string, withoutTimew bool) error {
if tag == "" {
return fmt.Errorf("cannot start tracking with an empty tag")
}
@ -126,6 +126,9 @@ func (ts *TimeStore) StartTracking(tag string) error {
if stopped {
slog.Info("Stopped previous time entry.")
}
if !withoutTimew {
runCommand("timew", "start", "work")
}
query := `INSERT INTO time_entries (tag, start_time, end_time) VALUES (?, ?, NULL);`
_, err = ts.db.Exec(query, tag, now)
@ -136,12 +139,15 @@ func (ts *TimeStore) StartTracking(tag string) error {
return nil
}
func (ts *TimeStore) StopTracking() error {
func (ts *TimeStore) StopTracking(withoutTimew bool) error {
now := time.Now()
stopped, err := ts.stopCurrentEntry(now)
if err != nil {
return err
}
if !withoutTimew {
runCommand("timew", "stop", "work")
}
if stopped {
slog.Info(fmt.Sprintf("Stopped tracking at %s", now.Format(time.RFC3339)))
} else {