diff --git a/assets/notify.mp3 b/assets/notify.mp3 deleted file mode 100644 index a1571a4..0000000 Binary files a/assets/notify.mp3 and /dev/null differ diff --git a/assets/notify.wav b/assets/notify.wav new file mode 100644 index 0000000..df30c37 Binary files /dev/null and b/assets/notify.wav differ diff --git a/cmd/jira-notificator-gui/main.go b/cmd/jira-notificator-gui/main.go index bb6cde2..6454d09 100644 --- a/cmd/jira-notificator-gui/main.go +++ b/cmd/jira-notificator-gui/main.go @@ -11,7 +11,7 @@ import ( ) const ( - notificationSound = "assets/notify.mp3" + notificationSound = "assets/notify.wav" icon = "assets/icon.ico" interval = 15 ) @@ -54,6 +54,11 @@ func makeBasicControlsPage() ui.Control { button := ui.NewButton("Přihlásit se") button.OnClicked(func(*ui.Button) { + if host.Text() == "" || username.Text() == "" || password.Text() == "" { + ui.MsgBoxError(mainwin, "Chyba", "Vyplňte všechny údaje") + return + } + host.Disable() username.Disable() password.Disable() @@ -64,6 +69,10 @@ func makeBasicControlsPage() ui.Control { if err != nil { ui.QueueMain(func() { ui.MsgBoxError(window, "Chyba", err.Error()) + host.Enable() + username.Enable() + password.Enable() + button.Enable() }) return } @@ -72,6 +81,10 @@ func makeBasicControlsPage() ui.Control { if err != nil { ui.QueueMain(func() { ui.MsgBoxError(window, "Chyba", err.Error()) + host.Enable() + username.Enable() + password.Enable() + button.Enable() }) return } @@ -83,6 +96,10 @@ func makeBasicControlsPage() ui.Control { if err != nil { ui.QueueMain(func() { ui.MsgBoxError(window, "Chyba", err.Error()) + host.Enable() + username.Enable() + password.Enable() + button.Enable() }) return } diff --git a/pkg/jira/audio.go b/pkg/jira/audio.go deleted file mode 100644 index 8cdd52b..0000000 --- a/pkg/jira/audio.go +++ /dev/null @@ -1,35 +0,0 @@ -package jira - -import ( - "bytes" - "github.com/200sc/klangsynthese/audio" - "github.com/200sc/klangsynthese/mp3" -) - -type reader struct { - *bytes.Reader -} - -func (*reader) Close() error { - return nil -} - -type Player struct { - audio audio.Audio -} - -func NewPlayer(data []byte) (*Player, error) { - reader := &reader{bytes.NewReader(data)} - a, err := mp3.Load(reader) - if err != nil { - return nil, err - } - - return &Player{ - a, - }, nil -} - -func (p Player) Play() error { - return <-p.audio.Play() -} diff --git a/pkg/jira/notification.go b/pkg/jira/notification.go index 4eefcdc..b92fc61 100644 --- a/pkg/jira/notification.go +++ b/pkg/jira/notification.go @@ -2,6 +2,8 @@ package jira import ( "github.com/gen2brain/beeep" + "github.com/hajimehoshi/oto" + "github.com/pkg/errors" "log" "time" ) @@ -33,14 +35,14 @@ func FetchNewNotifications(c Client, data NotificationData) error { channel := make(chan []Notification) finished := make(chan bool) - player, err := NewPlayer(data.Sound) + player, err := oto.NewPlayer(44100, 2, 2, 40000) if err != nil { - return err + return errors.Wrap(err, "Chyba při inicializaci zvukového zařízení") } worker, err := NewWorker(c, channel, finished) if err != nil { - return err + return errors.Wrap(err, "Chyba navázání připojení na data notifikací") } notificator := ¬ificator{beeep.Alert} @@ -51,16 +53,17 @@ func FetchNewNotifications(c Client, data NotificationData) error { case notifications := <-channel: log.Println(data.Text) - if err := player.Play(); err != nil { - return err + _, err := player.Write(data.Sound) + if err != nil { + return errors.Wrap(err, "Chyba při přehrávání tónu notifikace") } - err := notificator.notify(notifications) + err = notificator.notify(notifications) if err != nil { - return err + return errors.Wrap(err, "Chyba při vytváření notifikace") } case <-finished: - return worker.e + return errors.Wrap(worker.e, "Chyba při provádění aktualizace dat") } } }