forked from ugjka/bt_profile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (47 loc) · 1.14 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//go:generate go run gen/main.go
package main
import (
"flag"
"os/exec"
"github.com/getlantern/systray"
)
var sink string
var codec string
var showQuit bool
func main() {
s := flag.String("sink", "1", "headset's pulseaudio sink")
q := flag.Bool("quit", false, "show the quit item")
c := flag.String("codec", "", "custom codec e.g. aac, ldac")
flag.Parse()
sink = *s
showQuit = *q
if *c != "" {
codec = "-" + *c
}
systray.Run(onready, nil)
}
const hifi = "A2DP"
const headset = "HSP/HFP"
func onready() {
systray.SetIcon(icon)
a2dp := systray.AddMenuItem(hifi+" 🎧", "Switch to A2DP mode")
hsphfp := systray.AddMenuItem(headset, "Switch to HSP/HFP mode")
quit := systray.AddMenuItem("Quit", "Quit the app")
if !showQuit {
quit.Hide()
}
for {
select {
case <-quit.ClickedCh:
systray.Quit()
case <-a2dp.ClickedCh:
exec.Command("pactl", "set-card-profile", sink, "a2dp-sink"+codec).Run()
a2dp.SetTitle(hifi + " 🎧")
hsphfp.SetTitle(headset)
case <-hsphfp.ClickedCh:
exec.Command("pactl", "set-card-profile", sink, "headset-head-unit").Run()
hsphfp.SetTitle(headset + " 🎧")
a2dp.SetTitle(hifi)
}
}
}