From 73a679d10bf09a965b5afd3d0e81f51813325c67 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Thu, 24 Nov 2022 17:36:25 -0800 Subject: [PATCH] Move mpris out of pkg directory and run gofumpt --- calls.go | 3 +-- config.go | 2 +- maps.go | 2 +- {pkg/mpris => mpris}/mpris.go | 42 +++++++++++++++++------------------ music.go | 14 ++++++------ notifs.go | 4 ++-- socket.go | 2 +- 7 files changed, 33 insertions(+), 36 deletions(-) rename {pkg/mpris => mpris}/mpris.go (86%) diff --git a/calls.go b/calls.go index 5efc2f4..14886d2 100644 --- a/calls.go +++ b/calls.go @@ -7,8 +7,7 @@ import ( "github.com/godbus/dbus/v5" "github.com/rs/zerolog/log" "go.arsenm.dev/infinitime" - "go.arsenm.dev/itd/internal/utils" - + "go.arsenm.dev/itd/internal/utils" ) func initCallNotifs(ctx context.Context, dev *infinitime.Device) error { diff --git a/config.go b/config.go index eebb0d9..1d95a50 100644 --- a/config.go +++ b/config.go @@ -29,7 +29,7 @@ func init() { // If config dir is not readable if _, err = os.ReadDir(cfgDir); err != nil { // Create config dir with 700 permissions - err = os.MkdirAll(cfgDir, 0700) + err = os.MkdirAll(cfgDir, 0o700) if err != nil { panic(err) } diff --git a/maps.go b/maps.go index 0555de8..60a4c14 100644 --- a/maps.go +++ b/maps.go @@ -37,7 +37,7 @@ func initPureMaps(ctx context.Context, dev *infinitime.Device) error { } // Define rules to listen for - var rules = []string{ + rules := []string{ "type='signal',interface='io.github.rinigus.PureMaps.navigator'", } var flag uint = 0 diff --git a/pkg/mpris/mpris.go b/mpris/mpris.go similarity index 86% rename from pkg/mpris/mpris.go rename to mpris/mpris.go index 50571bf..740d61a 100644 --- a/pkg/mpris/mpris.go +++ b/mpris/mpris.go @@ -109,42 +109,40 @@ func Prev() error { } func VolUp(percent uint) error { - player, err := getPlayerObj() if err != nil { return err } if player != nil { - currentVal, err := player.GetProperty("org.mpris.MediaPlayer2.Player.Volume") - if err != nil { - return err - } - newVal := currentVal.Value().(float64) + (float64(percent) / 100) - err = player.SetProperty("org.mpris.MediaPlayer2.Player.Volume", newVal) - if err != nil { - return err - } - } + currentVal, err := player.GetProperty("org.mpris.MediaPlayer2.Player.Volume") + if err != nil { + return err + } + newVal := currentVal.Value().(float64) + (float64(percent) / 100) + err = player.SetProperty("org.mpris.MediaPlayer2.Player.Volume", newVal) + if err != nil { + return err + } + } return nil } func VolDown(percent uint) error { - player, err := getPlayerObj() if err != nil { return err } if player != nil { - currentVal, err := player.GetProperty("org.mpris.MediaPlayer2.Player.Volume") - if err != nil { - return err - } - newVal := currentVal.Value().(float64) - (float64(percent) / 100) - err = player.SetProperty("org.mpris.MediaPlayer2.Player.Volume", newVal) - if err != nil { - return err - } - } + currentVal, err := player.GetProperty("org.mpris.MediaPlayer2.Player.Volume") + if err != nil { + return err + } + newVal := currentVal.Value().(float64) - (float64(percent) / 100) + err = player.SetProperty("org.mpris.MediaPlayer2.Player.Volume", newVal) + if err != nil { + return err + } + } return nil } diff --git a/music.go b/music.go index 5e1e4d6..ee76461 100644 --- a/music.go +++ b/music.go @@ -19,30 +19,30 @@ package main import ( - "context" + "context" "github.com/rs/zerolog/log" "go.arsenm.dev/infinitime" + "go.arsenm.dev/itd/mpris" "go.arsenm.dev/itd/translit" - "go.arsenm.dev/itd/pkg/mpris" ) func initMusicCtrl(ctx context.Context, dev *infinitime.Device) error { - mpris.Init(ctx) + mpris.Init(ctx) maps := k.Strings("notifs.translit.use") translit.Transliterators["custom"] = translit.Map(k.Strings("notifs.translit.custom")) - mpris.OnChange(func(ct mpris.ChangeType, val string) { + mpris.OnChange(func(ct mpris.ChangeType, val string) { newVal := translit.Transliterate(val, maps...) if !firmwareUpdating { switch ct { case mpris.ChangeTypeStatus: - dev.Music.SetStatus(val == "Playing") + dev.Music.SetStatus(val == "Playing") case mpris.ChangeTypeTitle: - dev.Music.SetTrack(newVal) + dev.Music.SetTrack(newVal) case mpris.ChangeTypeAlbum: - dev.Music.SetAlbum(newVal) + dev.Music.SetAlbum(newVal) case mpris.ChangeTypeArtist: dev.Music.SetArtist(newVal) } diff --git a/notifs.go b/notifs.go index a3e8e36..7945954 100644 --- a/notifs.go +++ b/notifs.go @@ -25,8 +25,8 @@ import ( "github.com/godbus/dbus/v5" "github.com/rs/zerolog/log" "go.arsenm.dev/infinitime" - "go.arsenm.dev/itd/translit" "go.arsenm.dev/itd/internal/utils" + "go.arsenm.dev/itd/translit" ) func initNotifRelay(ctx context.Context, dev *infinitime.Device) error { @@ -37,7 +37,7 @@ func initNotifRelay(ctx context.Context, dev *infinitime.Device) error { } // Define rules to listen for - var rules = []string{ + rules := []string{ "type='method_call',member='Notify',path='/org/freedesktop/Notifications',interface='org.freedesktop.Notifications'", } var flag uint = 0 diff --git a/socket.go b/socket.go index 6fcba5c..017712e 100644 --- a/socket.go +++ b/socket.go @@ -43,7 +43,7 @@ var ( func startSocket(ctx context.Context, dev *infinitime.Device) error { // Make socket directory if non-existant - err := os.MkdirAll(filepath.Dir(k.String("socket.path")), 0755) + err := os.MkdirAll(filepath.Dir(k.String("socket.path")), 0o755) if err != nil { return err }