-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
60 lines (48 loc) · 1.12 KB
/
main.go
File metadata and controls
60 lines (48 loc) · 1.12 KB
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
55
56
57
58
59
60
// source https://github.com/ndanilo8/razer-mic-keepalive
package main
import (
"fmt"
"os/exec"
"syscall"
"github.com/getlantern/systray"
"github.com/getlantern/systray/example/icon"
)
var ffmpegCmd *exec.Cmd
func onReady() {
systray.SetIcon(icon.Data)
systray.SetTitle("Mic Keep-Alive")
systray.SetTooltip("Keeping your mic alive with ffmpeg")
mQuit := systray.AddMenuItem("Quit", "Stop ffmpeg and exit")
// Start ffmpeg to keep mic alive
micName := `Microphone (Razer BlackShark V2 Pro 2.4)`
ffmpegCmd = exec.Command("ffmpeg",
"-f", "dshow",
"-i", "audio="+micName,
"-t", "86400",
"-f", "null", "-")
// hide ffmpeg terminal window
ffmpegCmd.SysProcAttr = &syscall.SysProcAttr{
HideWindow: true,
}
err := ffmpegCmd.Start()
if err != nil {
fmt.Println("Failed to start ffmpeg:", err)
systray.Quit()
}
go func() {
<-mQuit.ClickedCh
if ffmpegCmd != nil && ffmpegCmd.Process != nil {
ffmpegCmd.Process.Kill()
}
systray.Quit()
}()
}
func onExit() {
// Cleanup
if ffmpegCmd != nil && ffmpegCmd.Process != nil {
ffmpegCmd.Process.Kill()
}
}
func main() {
systray.Run(onReady, onExit)
}