@@ -13,6 +13,7 @@ import (
1313 "os"
1414 "os/exec"
1515 "path/filepath"
16+ "runtime"
1617 "strings"
1718 "time"
1819
@@ -198,13 +199,12 @@ func (e *EventController) sendWakapiHeartbeat(ctx context.Context, program, cate
198199 }
199200
200201 type Heartbeat struct {
201- Entity string `json:"entity"`
202- Type string `json:"type"`
203- Category string `json:"category"`
204- Project string `json:"project"`
205- Time int64 `json:"time"`
206- IsWrite bool `json:"is_write"`
207- OperatingSystem string `json:"operating_system"`
202+ Entity string `json:"entity"`
203+ Type string `json:"type"`
204+ Category string `json:"category"`
205+ Project string `json:"project"`
206+ Time int64 `json:"time"`
207+ IsWrite bool `json:"is_write"`
208208 }
209209
210210 heartbeat := Heartbeat {
@@ -229,6 +229,9 @@ func (e *EventController) sendWakapiHeartbeat(ctx context.Context, program, cate
229229 req .Header .Set ("Content-Type" , "application/json" )
230230 req .Header .Set ("Authorization" , "Basic " + base64 .StdEncoding .EncodeToString ([]byte (e .Config .Wakapi .APIKey )))
231231
232+ userAgent := e .getUserAgent ()
233+ req .Header .Set ("User-Agent" , userAgent )
234+
232235 resp , err := e .Client .Do (req )
233236 if err != nil {
234237 return err
@@ -277,3 +280,21 @@ func (e *EventController) validateAndFormatWakapiURL(server string) (string, err
277280
278281 return strings .TrimRight (formatted , "/" ) + "/api/heartbeat" , nil
279282}
283+
284+ // Create User Agent header for Wakapi request
285+ func (e * EventController ) getUserAgent () string {
286+ app := "Timekeep"
287+ version := e .version
288+ os := runtime .GOOS
289+
290+ switch os {
291+ case "windows" :
292+ return fmt .Sprintf ("%s/%s (Windows NT 10.0; Win64; x64)" , app , version )
293+ case "linux" :
294+ return fmt .Sprintf ("%s/%s (X11; Linux x86_64)" , app , version )
295+ case "darwin" :
296+ return fmt .Sprintf ("%s/%s (Macintosh; Intel Mac OS X 10_15_7)" , app , version )
297+ default :
298+ return fmt .Sprintf ("%s/%s (%s)" , app , version , os )
299+ }
300+ }
0 commit comments