Skip to content

Commit 99859b7

Browse files
authored
Merge pull request #7 from jms-guy/wakapi
Wakapi
2 parents bce0bec + 2a7c4a5 commit 99859b7

11 files changed

Lines changed: 336 additions & 87 deletions

File tree

README.md

Lines changed: 72 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A process activity tracker, it runs as a background service recording start/stop
1212
- [How It Works](#how-it-works)
1313
- [Usage](#usage)
1414
- [Installation](#installation)
15-
- [WakaTime](#wakatime)
15+
- [WakaTime/Wakapi](#wakatimewakapi)
1616
- [File Locations](#file-locations)
1717
- [Current Limitations](#current-limitations)
1818
- [Contributing & Issues](#contributing--issues)
@@ -91,11 +91,35 @@ sc.exe start timekeep
9191
Get-Service -Name "timekeep"
9292
```
9393

94+
9495
Test using CLI:
9596
```powershell
9697
.\timekeep.exe status # Check if the service is responsive
9798
```
9899

100+
##### To include shell completion:
101+
102+
```powershell
103+
New-Item -Force -ItemType Directory (Split-Path $PROFILE) | Out-Null
104+
$comp = Join-Path (Split-Path $PROFILE) 'timekeep.ps1'
105+
timekeep completion powershell > $comp
106+
if (-not (Select-String -Path $PROFILE -SimpleMatch $comp -Quiet)) { Add-Content $PROFILE "`n. $comp" }
107+
. $PROFILE
108+
```
109+
110+
If you encounter issues running scripts in PowerShell, bypass the ExecutionPolicy with:
111+
112+
```powershell
113+
powershell -ExecutionPolicy Bypass
114+
```
115+
116+
for a single terminal session, or loosen restrictions with:
117+
118+
```powershell
119+
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
120+
```
121+
122+
99123
#### Linux
100124
```bash
101125
# Clone and build
@@ -158,54 +182,13 @@ Test using CLI:
158182
timekeep status # Check if the service is responsive
159183
```
160184

161-
### Shell Completion
162-
To include Tab-completion for Shell commands, run the completion commands specific for your Shell.
163-
164-
**Bash**
185+
##### To include shell completion:
165186

166187
```bash
167188
timekeep completion bash | sudo tee /etc/bash_completion.d/timekeep >/dev/null
168189
source /etc/bash_completion
169190
```
170191

171-
**PowerShell**
172-
173-
```powershell
174-
New-Item -Force -ItemType Directory (Split-Path $PROFILE) | Out-Null
175-
$comp = Join-Path (Split-Path $PROFILE) 'timekeep.ps1'
176-
timekeep completion powershell > $comp
177-
if (-not (Select-String -Path $PROFILE -SimpleMatch $comp -Quiet)) { Add-Content $PROFILE "`n. $comp" }
178-
. $PROFILE
179-
```
180-
181-
If you encounter issues running scripts in PowerShell, bypass the ExecutionPolicy with:
182-
183-
```powershell
184-
powershell -ExecutionPolicy Bypass
185-
```
186-
187-
for a single terminal session, or with:
188-
189-
```powershell
190-
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
191-
```
192-
193-
to loosen restrictions.
194-
195-
196-
**Untested** - **Zsh**
197-
```zsh
198-
timekeep completion zsh | sudo tee /usr/local/share/zsh/site-functions/_timekeep >/dev/null
199-
autoload -U compinit && compinit
200-
```
201-
202-
**Untested** - **Fish**
203-
```fish
204-
mkdir -p ~/.config/fish/completions
205-
timekeep completion fish > ~/.config/fish/completions/timekeep.fish
206-
# open a new fish session
207-
```
208-
209192
## Uninstalling
210193

211194
### Windows
@@ -222,7 +205,10 @@ sudo rm /usr/local/bin/timekeepd /usr/local/bin/timekeep
222205
sudo systemctl daemon-reload
223206
```
224207

225-
## WakaTime
208+
## WakaTime/Wakapi
209+
210+
### WakaTime
211+
226212
Timekeep now integrates with [WakaTime](https://wakatime.com), allowing users to track external program usage alongside their IDE and web-browsing stats. **Timekeep does not track activity within these programs, only when these programs are running.**
227213

228214
To enable WakaTime integration, users must:
@@ -231,13 +217,13 @@ To enable WakaTime integration, users must:
231217

232218
Enable integration through timekeep. Retrieve your API key from your [WakaTime profile settings](https://wakatime.com/settings/account). Set your WakaTime API key and wakatime-cli path either directly in the Timekeep [config](https://github.com/jms-guy/timekeep?tab=readme-ov-file#file-locations) file, or provide them through flags:
233219

234-
`timekeep wakatime enable --api_key "YOUR-KEY" --cli_path "wakatime-cli-PATH"`
220+
`timekeep wakatime enable --api_key "YOUR_KEY" --cli_path "wakatime-cli_PATH"`
235221

236222
```json
237223
{
238224
"wakatime": {
239225
"enabled": true,
240-
"api_key": "APIKEY",
226+
"api_key": "API_KEY",
241227
"cli_path": "PATH",
242228
"global_project": "PROJECT"
243229
}
@@ -246,11 +232,11 @@ Enable integration through timekeep. Retrieve your API key from your [WakaTime p
246232

247233
**The wakatime-cli path must be an absolute path.**: *C:\Path\To\\.wakatime\wakatime-cli.exe*
248234

249-
### Complete WakaTime setup example
235+
#### Complete WakaTime setup example
250236

251-
`timekeep wakatime enable --api_key YOUR-KEY --cli_path wakatime-cli-PATH`
237+
`timekeep wakatime enable --api_key "YOUR_KEY" --cli_path "wakatime-cli_PATH"`
252238

253-
`timekeep add photoshop.exe --category designing --project "UI Design"`
239+
`timekeep add photoshop.exe --category "designing" --project "UI Design"`
254240

255241
Check WakaTime current enabled/disabled status:
256242

@@ -260,10 +246,10 @@ Disable integration with:
260246

261247
`timekeep wakatime disable`
262248

263-
### Categories
249+
#### Categories
264250
After enabling, wakatime-cli heartbeats will be sent containing tracking data for given programs. Note, that only programs added to Timekeep with a given category will have data sent to WakaTime.
265251

266-
`timekeep add notepad.exe --category notes`
252+
`timekeep add notepad.exe --category "notes"`
267253

268254
If no category is set for a program, it will still be tracked locally, but no data for it will be sent out.
269255

@@ -277,20 +263,44 @@ List of categories accepted(defined [here](https://github.com/wakatime/wakatime-
277263
" \"translating\", or \"designing\".
278264
```
279265
280-
### Projects
266+
#### Projects
281267
Timekeep has no automatic project detection for WakaTime. Users may set a global project for all programs to use in the config, or via the command:
282268
283269
`timekeep config --global_project "YOUR-PROJECT"`
284270
285271
Users can also set project variables on a per-program basis:
286272
287-
`timekeep add notepad.exe --category notes --project Timekeep`
273+
`timekeep add notepad.exe --category "notes" --project "Timekeep"`
288274
289275
Program-set project variables will take precedence over a set Global Project. If no project variable is set via the global_project config or when adding programs, WakaTime will fall back to default "Unknown Project".
290276
291277
Users can update a program's category or project with the **update** command:
292278
293-
`timekeep update notepad.exe --category planning --project Timekeep2`
279+
`timekeep update notepad.exe --category "planning" --project "Timekeep2"`
280+
281+
### Wakapi
282+
283+
Similar to WakaTime, users can also allow their program activity to be tracked via [Wakapi](https://github.com/muety/wakapi). The commands and structures are very similar, to enable integration you need your Wakapi API key as well as the address to your running Wakapi server, provided through either command flags or editing the config file.
284+
285+
`timekeep wakapi enable --api_key "YOUR_KEY" --server "127.0.0.1:3000/api"`
286+
287+
`timekeep wakapi disable`
288+
289+
`timekeep wakapi status`
290+
291+
```json
292+
{
293+
"wakapi": {
294+
"enabled": true,
295+
"api_key": "API_KEY",
296+
"server": "ADDRESS",
297+
"global_project": "PROJECT"
298+
}
299+
}
300+
```
301+
302+
The global project variable for Wakapi can be altered manually in the config file, otherwise setting it via the `config` command will by default set it to the same value as the WakaTime global project variable.
303+
294304
295305
## File Locations
296306
- **Logs**
@@ -300,16 +310,22 @@ Users can update a program's category or project with the **update** command:
300310
- **Config**
301311
- **Windows**: *C:\ProgramData\Timekeep\config*
302312
- **Linux**: *~/.config/timekeep*
303-
- **Config struct**:
313+
- **Config structure**:
304314
305315
```json
306316
{
307317
"wakatime": {
308318
"enabled": true,
309-
"api_key": "APIKEY",
319+
"api_key": "API_KEY",
310320
"cli_path": "PATH",
311321
"global_project": "PROJECT"
312322
},
323+
"wakapi": {
324+
"enabled": true,
325+
"api_key": "API_KEY",
326+
"server": "ADDRESS",
327+
"global_project": "PROJECT"
328+
},
313329
"poll_interval": "1s",
314330
"poll_grace": 3,
315331
}

cmd/cli/commands.go

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func (s *CLIService) GetVersion() error {
339339
return nil
340340
}
341341

342-
// Changes config to enable WakaTime with API key
342+
// Changes config to enable WakaTime
343343
func (s *CLIService) EnableWakaTime(apiKey, path string) error {
344344
if s.Config.WakaTime.Enabled {
345345
return nil
@@ -385,13 +385,63 @@ func (s *CLIService) DisableWakaTime() error {
385385
return nil
386386
}
387387

388+
// Changes config to enable Wakapi
389+
func (s *CLIService) EnableWakapi(apiKey, server string) error {
390+
if s.Config.Wakapi.Enabled {
391+
return nil
392+
}
393+
394+
if apiKey != "" {
395+
s.Config.Wakapi.APIKey = apiKey
396+
}
397+
398+
if s.Config.Wakapi.APIKey == "" {
399+
return fmt.Errorf("WakaTime API key required. Use flag: --api_key <key>")
400+
}
401+
402+
if server != "" {
403+
s.Config.Wakapi.Server = server
404+
}
405+
406+
if s.Config.Wakapi.Server == "" {
407+
return fmt.Errorf("wakapi server address required. Use flag: --server <address>")
408+
}
409+
410+
s.Config.Wakapi.Enabled = true
411+
412+
if err := s.saveAndNotify(); err != nil {
413+
return err
414+
}
415+
416+
return nil
417+
}
418+
419+
// Disables Wakapi in config
420+
func (s *CLIService) DisableWakapi() error {
421+
if !s.Config.Wakapi.Enabled {
422+
return nil
423+
}
424+
425+
s.Config.Wakapi.Enabled = false
426+
427+
if err := s.saveAndNotify(); err != nil {
428+
return err
429+
}
430+
431+
return nil
432+
}
433+
388434
// Set various config values
389-
func (s *CLIService) SetConfig(cliPath, project, interval string, grace int) error {
435+
func (s *CLIService) SetConfig(cliPath, server, project, interval string, grace int) error {
390436
if cliPath != "" {
391437
s.Config.WakaTime.CLIPath = cliPath
392438
}
439+
if server != "" {
440+
s.Config.Wakapi.Server = server
441+
}
393442
if project != "" {
394443
s.Config.WakaTime.GlobalProject = project
444+
s.Config.Wakapi.GlobalProject = project
395445
}
396446
if interval != "" {
397447
s.Config.PollInterval = interval
@@ -417,3 +467,14 @@ func (s *CLIService) StatusWakatime() error {
417467

418468
return nil
419469
}
470+
471+
// Returns Wakapi enabled/disabled status for user
472+
func (s *CLIService) StatusWakapi() error {
473+
if s.Config.Wakapi.Enabled {
474+
fmt.Println("enabled")
475+
} else {
476+
fmt.Println("disabled")
477+
}
478+
479+
return nil
480+
}

cmd/cli/root.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ func (s *CLIService) RootCmd() *cobra.Command {
2424
wCmd.AddCommand(s.wakatimeEnable())
2525
wCmd.AddCommand(s.wakatimeDisable())
2626

27+
wpCmd := s.wakapiIntegration()
28+
wpCmd.AddCommand(s.wakapiStatus())
29+
wpCmd.AddCommand(s.wakapiEnable())
30+
wpCmd.AddCommand(s.wakapiDisable())
31+
2732
rootCmd.AddCommand(wCmd)
33+
rootCmd.AddCommand(wpCmd)
2834
rootCmd.AddCommand(s.addProgramsCmd())
2935
rootCmd.AddCommand(s.updateCmd())
3036
rootCmd.AddCommand(s.removeProgramsCmd())

0 commit comments

Comments
 (0)