91 lines
2.1 KiB
Go
91 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"path"
|
|
|
|
"github.com/nelsam/gxui"
|
|
"github.com/nelsam/gxui/themes/dark"
|
|
)
|
|
|
|
var (
|
|
dr gxui.Driver
|
|
)
|
|
|
|
func uiMain(dri gxui.Driver) {
|
|
dr = dri
|
|
catAdap := &StrList{}
|
|
catAdap.SetStrings(linOnly)
|
|
appAdap := &prtapAdap{}
|
|
appAdap.Wine(false)
|
|
th := dark.CreateTheme(dr)
|
|
win := th.CreateWindow(500, 500, "LinuxPA")
|
|
top := th.CreateLinearLayout()
|
|
top.SetDirection(gxui.BottomToTop)
|
|
top.SetHorizontalAlignment(gxui.AlignRight)
|
|
spl := th.CreateSplitterLayout()
|
|
spl.SetOrientation(gxui.Horizontal)
|
|
catlist := th.CreateList()
|
|
catlist.SetAdapter(catAdap)
|
|
catlist.OnItemClicked(func(_ gxui.MouseEvent, it gxui.AdapterItem) {
|
|
str := it.(string)
|
|
appAdap.SetApps(appMaster[str])
|
|
})
|
|
applist := th.CreateList()
|
|
applist.SetAdapter(appAdap)
|
|
spl.AddChild(catlist)
|
|
spl.AddChild(applist)
|
|
but := th.CreateLinearLayout()
|
|
but.SetDirection(gxui.RightToLeft)
|
|
launch := th.CreateButton()
|
|
launch.SetText("Launch!")
|
|
launch.OnClick(func(gxui.MouseEvent) {
|
|
if appAdap.ItemIndex(applist.Selected()) != -1 {
|
|
app := applist.Selected().(prtap)
|
|
dir, fi := path.Split(app.ex)
|
|
var cmd *exec.Cmd
|
|
if app.wine {
|
|
cmd = exec.Command("/bin/sh", "-c", "cd \""+dir+"\"; wine \""+fi+"\"")
|
|
} else {
|
|
if commEnbl {
|
|
cmd = exec.Command("/bin/sh", "-c", ". "+common+" || exit 1;cd \""+dir+"\"; \"./"+fi+"\"")
|
|
} else {
|
|
cmd = exec.Command("/bin/sh", "-c", "cd \""+dir+"\"; \"./"+fi+"\"")
|
|
}
|
|
}
|
|
cmd.Stdin = os.Stdin
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
cmd.Start()
|
|
}
|
|
})
|
|
if _, err := exec.LookPath("wine"); err == nil {
|
|
fmt.Println("Wine found!")
|
|
wine := th.CreateButton()
|
|
wine.SetType(gxui.ToggleButton)
|
|
wine.OnClick(func(gxui.MouseEvent) {
|
|
if wine.IsChecked() {
|
|
catAdap.SetStrings(cats)
|
|
appAdap.Wine(true)
|
|
} else {
|
|
catAdap.SetStrings(linOnly)
|
|
appAdap.Wine(false)
|
|
}
|
|
})
|
|
wine.SetText("Show Windows Apps")
|
|
wine.SetChecked(appAdap.wine)
|
|
but.AddChild(wine)
|
|
} else {
|
|
fmt.Println("Wine not found!")
|
|
}
|
|
but.AddChild(launch)
|
|
top.AddChild(but)
|
|
top.AddChild(spl)
|
|
win.AddChild(top)
|
|
win.OnClose(func() {
|
|
dr.Terminate()
|
|
})
|
|
}
|