1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Properly scope Config to the wtf package and remove it as a dependency from everywhere else

This commit is contained in:
Chris Cummer
2018-06-16 14:59:22 -07:00
parent 966b2df52a
commit eb5f09e65c
42 changed files with 128 additions and 254 deletions

View File

@@ -16,8 +16,8 @@ import (
"os"
"os/user"
"path/filepath"
"time"
"sort"
"time"
"github.com/senorprogrammer/wtf/wtf"
"golang.org/x/oauth2"
@@ -30,7 +30,7 @@ import (
func Fetch() (*calendar.Events, error) {
ctx := context.Background()
secretPath, _ := wtf.ExpandHomeDir(Config.UString("wtf.mods.gcal.secretFile"))
secretPath, _ := wtf.ExpandHomeDir(wtf.Config.UString("wtf.mods.gcal.secretFile"))
b, err := ioutil.ReadFile(secretPath)
if err != nil {
@@ -70,7 +70,7 @@ func Fetch() (*calendar.Events, error) {
var events calendar.Events
startTime := fromMidnight().Format(time.RFC3339)
eventLimit := int64(Config.UInt("wtf.mods.gcal.eventCount", 10))
eventLimit := int64(wtf.Config.UInt("wtf.mods.gcal.eventCount", 10))
for _, calendarId := range calendarIds {
calendarEvents, err := srv.Events.List(calendarId).ShowDeleted(false).TimeMin(startTime).MaxResults(eventLimit).SingleEvents(true).OrderBy("startTime").Do()
@@ -94,10 +94,9 @@ func Fetch() (*calendar.Events, error) {
sort.Slice(events.Items, func(i, j int) bool {
dateA, _ := timeDateChooser(events.Items[i])
dateB, _ := timeDateChooser(events.Items[j])
return dateA.Before(dateB)
return dateA.Before(dateB)
})
return &events, err
}

View File

@@ -6,14 +6,10 @@ import (
"strings"
"time"
"github.com/olebedev/config"
"github.com/senorprogrammer/wtf/wtf"
"google.golang.org/api/calendar/v3"
)
// Config is a pointer to the global config object
var Config *config.Config
type Widget struct {
wtf.TextWidget
}
@@ -105,10 +101,10 @@ func (widget *Widget) dayDivider(event, prevEvent *calendar.Event) string {
}
func (widget *Widget) descriptionColor(event *calendar.Event) string {
color := Config.UString("wtf.mods.gcal.colors.description", "white")
color := wtf.Config.UString("wtf.mods.gcal.colors.description", "white")
if widget.eventIsPast(event) {
color = Config.UString("wtf.mods.gcal.colors.past", "gray")
color = wtf.Config.UString("wtf.mods.gcal.colors.past", "gray")
}
return color
@@ -120,13 +116,13 @@ func (widget *Widget) eventSummary(event *calendar.Event, conflict bool) string
if widget.eventIsNow(event) {
summary = fmt.Sprintf(
"%s %s",
Config.UString("wtf.mods.gcal.currentIcon", "🔸"),
wtf.Config.UString("wtf.mods.gcal.currentIcon", "🔸"),
event.Summary,
)
}
if conflict {
return fmt.Sprintf("%s %s", Config.UString("wtf.mods.gcal.conflictIcon", "🚨"), summary)
return fmt.Sprintf("%s %s", wtf.Config.UString("wtf.mods.gcal.conflictIcon", "🚨"), summary)
} else {
return summary
}
@@ -156,9 +152,9 @@ func (widget *Widget) eventIsPast(event *calendar.Event) bool {
}
func (widget *Widget) titleColor(event *calendar.Event) string {
color := Config.UString("wtf.mods.gcal.colors.title", "white")
color := wtf.Config.UString("wtf.mods.gcal.colors.title", "white")
for _, untypedArr := range Config.UList("wtf.mods.gcal.colors.highlights") {
for _, untypedArr := range wtf.Config.UList("wtf.mods.gcal.colors.highlights") {
highlightElements := wtf.ToStrs(untypedArr.([]interface{}))
match, _ := regexp.MatchString(
@@ -172,14 +168,14 @@ func (widget *Widget) titleColor(event *calendar.Event) string {
}
if widget.eventIsPast(event) {
color = Config.UString("wtf.mods.gcal.colors.past", "gray")
color = wtf.Config.UString("wtf.mods.gcal.colors.past", "gray")
}
return color
}
func (widget *Widget) location(event *calendar.Event) string {
if Config.UBool("wtf.mods.gcal.displayLocation", true) == false {
if wtf.Config.UBool("wtf.mods.gcal.displayLocation", true) == false {
return ""
}
@@ -195,14 +191,14 @@ func (widget *Widget) location(event *calendar.Event) string {
}
func (widget *Widget) responseIcon(event *calendar.Event) string {
if false == Config.UBool("wtf.mods.gcal.displayResponseStatus", true) {
if false == wtf.Config.UBool("wtf.mods.gcal.displayResponseStatus", true) {
return ""
}
response := ""
for _, attendee := range event.Attendees {
if attendee.Email == Config.UString("wtf.mods.gcal.email") {
if attendee.Email == wtf.Config.UString("wtf.mods.gcal.email") {
response = attendee.ResponseStatus
break
}