Skip to content

Instantly share code, notes, and snippets.

@jrabbit
Created January 31, 2018 05:24
Show Gist options
  • Save jrabbit/223db587c681ad7e815a1fcaf5a67f6a to your computer and use it in GitHub Desktop.
Save jrabbit/223db587c681ad7e815a1fcaf5a67f6a to your computer and use it in GitHub Desktop.
package adormit
import (
"fmt"
"github.com/godbus/dbus"
"github.com/gotk3/gotk3/glib"
"reflect"
"time"
)
type Alarm struct {
name string
early bool
time time.Time
active bool
id string
}
type Timer struct {
name string
start time.Time
duration time.Duration
end time.Time
}
func MakeAlarm() {
alarm := Alarm{name: "my-alarm", active: true}
SetAlarm(alarm)
}
func SetAlarm(alarm Alarm) {
insert := make(map[string]interface{})
insert["name"] = alarm.name
insert["active"] = alarm.active
existing_alarms := GetGnomeAlarms().([]map[string]interface{})
total_update := make([]map[string]interface{}, 10)
total_update = append(total_update, insert)
total_update = append(total_update, existing_alarms)
// total_update[2] = insert
sig, _ := dbus.ParseSignature("aa{sv}")
vari := dbus.MakeVariantWithSignature(total_update, sig)
fmt.Println(vari)
}
func debug(ty interface{}) {
fooType := reflect.TypeOf(ty)
fmt.Println(fooType)
for i := 0; i < fooType.NumMethod(); i++ {
method := fooType.Method(i)
fmt.Println(method.Name)
}
}
func GetGnomeAlarms() []map[string]dbus.Variant {
//gsettings get org.gnome.clocks alarms
settings := glib.SettingsNew("org.gnome.clocks")
alarms := settings.GetValue("alarms")
// debug(settings)
sig, _ := dbus.ParseSignature("aa{sv}")
v, _ := dbus.ParseVariant(alarms.String(), sig)
val := v.Value()
alarmMaps := val.([]map[string]dbus.Variant)
fmt.Println(alarmMaps)
return alarmMaps
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment