Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
| 6745dba616 |
1 changed files with 145 additions and 123 deletions
268
threenis/ui.go
268
threenis/ui.go
|
|
@ -1,123 +1,145 @@
|
||||||
package threenis
|
package threenis
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/app"
|
"fyne.io/fyne/v2/app"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/layout"
|
"fyne.io/fyne/v2/layout"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"layeh.com/gumble/gumble"
|
"layeh.com/gumble/gumble"
|
||||||
"layeh.com/gumble/gumbleffmpeg"
|
"layeh.com/gumble/gumbleffmpeg"
|
||||||
"layeh.com/gumble/gumbleutil"
|
"layeh.com/gumble/gumbleutil"
|
||||||
_ "layeh.com/gumble/opus"
|
_ "layeh.com/gumble/opus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Threenis struct {
|
type Threenis struct {
|
||||||
stream *gumbleffmpeg.Stream
|
stream *gumbleffmpeg.Stream
|
||||||
process *exec.Cmd
|
process *exec.Cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
type SourceStream string
|
type SourceStream string
|
||||||
|
|
||||||
func ThreenisSource(filename string) gumbleffmpeg.Source {
|
func ThreenisSource(filename string) gumbleffmpeg.Source {
|
||||||
return SourceStream(filename)
|
return SourceStream(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SourceStream) Arguments() []string {
|
func (s SourceStream) Arguments() []string {
|
||||||
return []string{"-fflags", "nobuffer", "-flags", "low_delay", "-f", "s16le", "-ac", "2", "-i", "udp://127.0.0.1:2888"}
|
return []string{"-fflags", "nobuffer", "-flags", "low_delay", "-f", "s16le", "-ac", "2", "-i", "udp://127.0.0.1:2888"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (SourceStream) Start(*exec.Cmd) error {
|
func (SourceStream) Start(*exec.Cmd) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (SourceStream) Done() {
|
func (SourceStream) Done() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Threenis) Mumble(server string, username string, password string, channel string) {
|
func (t *Threenis) Mumble(server string, username string, password string, channel string) {
|
||||||
MumbleClient(server, username, password, gumbleutil.AutoBitrate, gumbleutil.Listener{
|
MumbleClient(server, username, password, gumbleutil.AutoBitrate, gumbleutil.Listener{
|
||||||
Connect: func(e *gumble.ConnectEvent) {
|
Connect: func(e *gumble.ConnectEvent) {
|
||||||
c := e.Client.Channels.Find(channel)
|
c := e.Client.Channels.Find(channel)
|
||||||
if c != nil {
|
if c != nil {
|
||||||
e.Client.Self.Move(c)
|
e.Client.Self.Move(c)
|
||||||
}
|
}
|
||||||
t.stream = gumbleffmpeg.New(e.Client, ThreenisSource(""))
|
t.stream = gumbleffmpeg.New(e.Client, ThreenisSource(""))
|
||||||
if err := t.stream.Play(); err != nil {
|
if err := t.stream.Play(); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func Ui() {
|
func Ui() {
|
||||||
myApp := app.New()
|
threenisApp := app.NewWithID("threenis")
|
||||||
myWindow := myApp.NewWindow("Threenis")
|
window := threenisApp.NewWindow("Threenis")
|
||||||
myWindow.Resize(fyne.NewSize(800, 400))
|
window.Resize(fyne.NewSize(800, 400))
|
||||||
myWindow.SetFixedSize(true)
|
|
||||||
|
processes := GetProcessStrings()
|
||||||
processes := GetProcessStrings()
|
threenis := Threenis{}
|
||||||
threenis := Threenis{}
|
|
||||||
|
defer func() {
|
||||||
defer func() {
|
threenis.stream.Stop()
|
||||||
threenis.stream.Stop()
|
if threenis.process != nil && threenis.process.Process != nil {
|
||||||
if threenis.process != nil && threenis.process.Process != nil {
|
threenis.process.Process.Kill()
|
||||||
threenis.process.Process.Kill()
|
}
|
||||||
}
|
}()
|
||||||
}()
|
|
||||||
|
list := widget.NewList(
|
||||||
list := widget.NewList(
|
func() int {
|
||||||
func() int {
|
return len(processes)
|
||||||
return len(processes)
|
},
|
||||||
},
|
func() fyne.CanvasObject {
|
||||||
func() fyne.CanvasObject {
|
return widget.NewLabel("template")
|
||||||
return widget.NewLabel("template")
|
},
|
||||||
},
|
func(i widget.ListItemID, o fyne.CanvasObject) {
|
||||||
func(i widget.ListItemID, o fyne.CanvasObject) {
|
o.(*widget.Label).SetText(processes[i])
|
||||||
o.(*widget.Label).SetText(processes[i])
|
})
|
||||||
})
|
|
||||||
|
list.OnSelected = func(id widget.ListItemID) {
|
||||||
list.OnSelected = func(id widget.ListItemID) {
|
if threenis.process != nil && threenis.process.Process != nil {
|
||||||
if threenis.process != nil && threenis.process.Process != nil {
|
threenis.process.Process.Kill()
|
||||||
threenis.process.Process.Kill()
|
}
|
||||||
}
|
threenis.process = exec.Command("./ApplicationLoopback.exe", strings.Split(processes[id], " - ")[0], "includetree")
|
||||||
threenis.process = exec.Command("./ApplicationLoopback.exe", strings.Split(processes[id], " - ")[0], "includetree")
|
log.Println(strings.Split(processes[id], " - ")[0])
|
||||||
log.Println(strings.Split(processes[id], " - ")[0])
|
err := threenis.process.Start()
|
||||||
err := threenis.process.Start()
|
if err != nil {
|
||||||
if err != nil {
|
log.Println(err)
|
||||||
log.Println(err)
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
serverLabel := widget.NewLabel("Server")
|
||||||
serverLabel := widget.NewLabel("Server")
|
server := widget.NewEntry()
|
||||||
server := widget.NewEntry()
|
server.SetText(threenisApp.Preferences().StringWithFallback("server", ""))
|
||||||
|
|
||||||
usernameLabel := widget.NewLabel("Username")
|
usernameLabel := widget.NewLabel("Username")
|
||||||
username := widget.NewEntry()
|
username := widget.NewEntry()
|
||||||
passwordLabel := widget.NewLabel("Password")
|
username.SetText(threenisApp.Preferences().StringWithFallback("username", ""))
|
||||||
password := widget.NewEntry()
|
|
||||||
|
passwordLabel := widget.NewLabel("Password")
|
||||||
channelLabel := widget.NewLabel("Channel")
|
password := widget.NewEntry()
|
||||||
channel := widget.NewEntry()
|
password.SetText(threenisApp.Preferences().StringWithFallback("password", ""))
|
||||||
|
|
||||||
refresh := widget.NewButton("Refresh", func() {
|
channelLabel := widget.NewLabel("Channel")
|
||||||
processes = GetProcessStrings()
|
channel := widget.NewEntry()
|
||||||
list.Refresh()
|
channel.SetText(threenisApp.Preferences().StringWithFallback("channel", ""))
|
||||||
})
|
|
||||||
|
refresh := widget.NewButton("Refresh", func() {
|
||||||
connect := widget.NewButton("Connect", func() {
|
processes = GetProcessStrings()
|
||||||
go threenis.Mumble(server.Text, username.Text, password.Text, channel.Text)
|
list.Refresh()
|
||||||
})
|
})
|
||||||
|
|
||||||
form := container.New(layout.NewFormLayout(), serverLabel, server, usernameLabel, username, passwordLabel, password, channelLabel, channel, refresh, connect)
|
connect := widget.NewButton("Connect", func() {
|
||||||
|
threenisApp.Preferences().SetString("server", server.Text)
|
||||||
grid := container.New(layout.NewGridLayout(2), list, form)
|
threenisApp.Preferences().SetString("username", username.Text)
|
||||||
|
threenisApp.Preferences().SetString("password", password.Text)
|
||||||
myWindow.SetContent(grid)
|
threenisApp.Preferences().SetString("channel", channel.Text)
|
||||||
myWindow.ShowAndRun()
|
go threenis.Mumble(server.Text, username.Text, password.Text, channel.Text)
|
||||||
}
|
})
|
||||||
|
|
||||||
|
search := widget.NewEntry()
|
||||||
|
search.OnChanged = func(s string) {
|
||||||
|
procs := GetProcessStrings()
|
||||||
|
processes = make([]string, 0)
|
||||||
|
for _, proc := range procs {
|
||||||
|
if strings.Contains(strings.ToLower(proc), strings.ToLower(s)) {
|
||||||
|
processes = append(processes, proc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.Refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
content := container.NewBorder(nil, search, nil, nil, list)
|
||||||
|
|
||||||
|
form := container.New(layout.NewFormLayout(), serverLabel, server, usernameLabel, username, passwordLabel, password, channelLabel, channel, refresh, connect)
|
||||||
|
|
||||||
|
grid := container.New(layout.NewGridLayout(2), content, form)
|
||||||
|
|
||||||
|
window.SetContent(grid)
|
||||||
|
window.ShowAndRun()
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue