Initial Upload
Has basic functionality, still need to work on some stuff though
This commit is contained in:
@@ -0,0 +1,110 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/nelsam/gxui/drivers/gl"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
appMaster map[string][]prtap
|
||||||
|
cats []string
|
||||||
|
)
|
||||||
|
|
||||||
|
type prtap struct {
|
||||||
|
name string
|
||||||
|
cat string
|
||||||
|
ex string
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
appMaster = make(map[string][]prtap)
|
||||||
|
os.Mkdir("PortableApps", 0777)
|
||||||
|
pa, err := os.Open("PortableApps")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
appstmp, _ := pa.Readdir(-1)
|
||||||
|
var folds []string
|
||||||
|
for _, v := range appstmp {
|
||||||
|
if v.IsDir() {
|
||||||
|
folds = append(folds, v.Name())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Strings(folds)
|
||||||
|
for _, v := range folds {
|
||||||
|
fi, _ := os.Open("PortableApps/" + v)
|
||||||
|
pat := processApp(fi)
|
||||||
|
if (pat != prtap{}) {
|
||||||
|
if _, ok := appMaster[pat.cat]; !ok {
|
||||||
|
cats = append(cats, pat.cat)
|
||||||
|
}
|
||||||
|
appMaster[pat.cat] = append(appMaster[pat.cat], pat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gl.StartDriver(uiMain)
|
||||||
|
}
|
||||||
|
|
||||||
|
func processApp(fi *os.File) (out prtap) {
|
||||||
|
var hasEx bool
|
||||||
|
out.cat = "other"
|
||||||
|
fis, _ := fi.Readdir(-1)
|
||||||
|
for _, v := range fis {
|
||||||
|
if v.IsDir() && v.Name() == "App" {
|
||||||
|
fild, err := os.Open(fi.Name() + "/App/AppInfo/appinfo.ini")
|
||||||
|
fmt.Println(fi.Name() + "/App/AppInfo/appinfo.ini")
|
||||||
|
if err == nil {
|
||||||
|
fmt.Println("working!")
|
||||||
|
out.cat = getCat(fild)
|
||||||
|
out.name = getName(fild)
|
||||||
|
}
|
||||||
|
} else if !v.IsDir() {
|
||||||
|
//do os check here
|
||||||
|
if strings.HasSuffix(v.Name(), ".sh") {
|
||||||
|
hasEx = true
|
||||||
|
out.ex = fi.Name() + "/" + v.Name()
|
||||||
|
if out.name == "" {
|
||||||
|
out.name = strings.TrimSuffix(v.Name(), ".sh")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hasEx {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return prtap{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCat(fi *os.File) (out string) {
|
||||||
|
rdr := bufio.NewReader(fi)
|
||||||
|
var err error
|
||||||
|
var ln []byte
|
||||||
|
for err == nil {
|
||||||
|
ln, _, err = rdr.ReadLine()
|
||||||
|
str := string(ln)
|
||||||
|
if strings.HasPrefix(str, "Category=") {
|
||||||
|
out = strings.TrimPrefix(str, "Category=")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func getName(fi *os.File) (out string) {
|
||||||
|
rdr := bufio.NewReader(fi)
|
||||||
|
var err error
|
||||||
|
var ln []byte
|
||||||
|
for err == nil {
|
||||||
|
ln, _, err = rdr.ReadLine()
|
||||||
|
str := string(ln)
|
||||||
|
if strings.HasPrefix(str, "Name=") {
|
||||||
|
out = strings.TrimPrefix(str, "Name=")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/nelsam/gxui"
|
||||||
|
"github.com/nelsam/gxui/math"
|
||||||
|
)
|
||||||
|
|
||||||
|
type prtapAdap struct {
|
||||||
|
gxui.AdapterBase
|
||||||
|
apps []prtap
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *prtapAdap) SetApps(apps []prtap) {
|
||||||
|
p.apps = apps
|
||||||
|
p.DataChanged(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *prtapAdap) Count() int {
|
||||||
|
return len(p.apps)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *prtapAdap) Create(th gxui.Theme, index int) gxui.Control {
|
||||||
|
box := th.CreateLinearLayout()
|
||||||
|
box.SetDirection(gxui.LeftToRight)
|
||||||
|
// pic := th.CreateImage()
|
||||||
|
// dr.CreateTexture()
|
||||||
|
//add image support
|
||||||
|
lbl := th.CreateLabel()
|
||||||
|
lbl.SetText(p.apps[index].name)
|
||||||
|
// box.AddChild(pic)
|
||||||
|
box.AddChild(lbl)
|
||||||
|
return box
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *prtapAdap) ItemAt(index int) gxui.AdapterItem {
|
||||||
|
return p.apps[index]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *prtapAdap) ItemIndex(item gxui.AdapterItem) int {
|
||||||
|
it, ok := item.(prtap)
|
||||||
|
if !ok {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
for i, v := range p.apps {
|
||||||
|
if v == it {
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *prtapAdap) Size(gxui.Theme) math.Size {
|
||||||
|
return math.Size{W: math.MaxSize.W, H: 20}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gxuiCustom"
|
||||||
|
"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 := &gxuiCustom.StrList{}
|
||||||
|
catAdap.SetStrings(cats)
|
||||||
|
appAdap := &prtapAdap{}
|
||||||
|
th := dark.CreateTheme(dr)
|
||||||
|
win := th.CreateWindow(500, 500, "LinuxPA")
|
||||||
|
top := th.CreateSplitterLayout()
|
||||||
|
top.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)
|
||||||
|
applist.OnItemClicked(func(_ gxui.MouseEvent, it gxui.AdapterItem) {
|
||||||
|
app := it.(prtap)
|
||||||
|
dir, fi := path.Split(app.ex)
|
||||||
|
cmd := exec.Command("/bin/sh", "-c", "cd \""+dir+"\"; \"./"+fi+"\"")
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Start()
|
||||||
|
})
|
||||||
|
top.AddChild(catlist)
|
||||||
|
top.AddChild(applist)
|
||||||
|
win.AddChild(top)
|
||||||
|
win.OnClose(dr.Terminate)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user