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 abedee0ce0
commit 66b69471d0
42 changed files with 126 additions and 251 deletions

View File

@@ -29,7 +29,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 {
@@ -48,7 +48,7 @@ func Fetch() (*calendar.Events, error) {
}
startTime := fromMidnight().Format(time.RFC3339)
eventLimit := int64(Config.UInt("wtf.mods.gcal.eventCount", 10))
eventLimit := int64(wtf.Config.UInt("wtf.mods.gcal.eventCount", 10))
events, err := srv.Events.List("primary").ShowDeleted(false).SingleEvents(true).TimeMin(startTime).MaxResults(eventLimit).OrderBy("startTime").Do()
if err != nil {
return nil, 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
}
@@ -151,9 +147,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(
@@ -167,14 +163,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 ""
}
@@ -190,14 +186,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
}