forked from jason0x43/alfred-toggl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
76 lines (64 loc) · 1.88 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"path"
"time"
"github.com/jason0x43/go-alfred"
"github.com/jason0x43/go-toggl"
)
var dlog = log.New(os.Stderr, "[toggl] ", log.LstdFlags)
var cacheFile string
var configFile string
var config struct {
APIKey string `desc:"Toggl API key"`
AskForProject bool `desc:"If true, ask for a project if a default isn't set"`
DefaultProjectID int `desc:"Optional default project ID for new time entries; set to 0 to clear"`
DurationOnly bool `desc:"If true, extend time entries instead of starting copies"`
HoursMinutes bool `desc:"If true, show hh:mm instead of fractional hours"`
Rounding int `desc:"Minutes to round to, 0 to disable rounding"`
NewTimerFirst bool `desc:"If true, show new timer before restart timer"`
TestMode bool `desc:"If true, disable auto refresh"`
}
var cache struct {
Workspace int
Account toggl.Account
Time time.Time
}
var workflow alfred.Workflow
func main() {
if !alfred.IsDebugging() {
dlog.SetOutput(ioutil.Discard)
dlog.SetFlags(0)
}
var err error
if workflow, err = alfred.OpenWorkflow(".", true); err != nil {
fmt.Printf("Error: %s", err)
os.Exit(1)
}
workflow.UpdateIcon = "running.png"
configFile = path.Join(workflow.DataDir(), "config.json")
cacheFile = path.Join(workflow.CacheDir(), "cache.json")
dlog.Printf("Using config file: %s", configFile)
dlog.Printf("Using cache file: %s", cacheFile)
if err := alfred.LoadJSON(configFile, &config); err != nil {
dlog.Println("Error loading config:", err)
}
if err := alfred.LoadJSON(cacheFile, &cache); err != nil {
dlog.Println("Error loading cache:", err)
}
workflow.Run([]alfred.Command{
StatusFilter{},
LoginCommand{},
TokenCommand{},
TimeEntryCommand{},
ProjectCommand{},
TagCommand{},
ReportFilter{},
OptionsCommand{},
LogoutCommand{},
ResetCommand{},
})
}