diff --git a/main.go b/main.go index e143416..2d26e22 100644 --- a/main.go +++ b/main.go @@ -24,6 +24,7 @@ type prtap struct { cat string ex string desc string + wine bool } func main() { @@ -116,6 +117,18 @@ func processApp(fi *os.File) (out prtap) { } } } + for _, v := range fis { + fil, err := os.Open(wd + "/" + fi.Name() + "/" + v.Name()) + if err == nil { + stat, _ := fil.Stat() + if !stat.IsDir() && strings.HasSuffix(stat.Name(), "exe") { + out.wine = true + out.ex = wd + "/" + fi.Name() + "/" + v.Name() + out.name += " (Wine)" + return + } + } + } return prtap{} } diff --git a/prtapAdap.go b/prtapAdap.go index 17bd6ef..957d367 100644 --- a/prtapAdap.go +++ b/prtapAdap.go @@ -15,16 +15,39 @@ import ( type prtapAdap struct { gxui.AdapterBase - apps []prtap + wine bool + master []prtap + cur []prtap } func (p *prtapAdap) SetApps(apps []prtap) { - p.apps = apps + p.master = apps + if p.wine { + p.cur = p.master + } else { + p.cur = make([]prtap, 0) + for _, v := range p.master { + p.cur = append(p.cur, v) + } + } p.DataChanged(false) } func (p *prtapAdap) Count() int { - return len(p.apps) + return len(p.cur) +} + +func (p *prtapAdap) Wine(show bool) { + p.wine = show + if show { + p.cur = p.master + } else { + p.cur = make([]prtap, 0) + for _, v := range p.master { + p.cur = append(p.cur, v) + } + } + p.DataChanged(false) } func (p *prtapAdap) Create(th gxui.Theme, index int) gxui.Control { @@ -32,7 +55,7 @@ func (p *prtapAdap) Create(th gxui.Theme, index int) gxui.Control { box.SetPadding(math.CreateSpacing(2)) box.SetDirection(gxui.LeftToRight) box.SetVerticalAlignment(gxui.AlignMiddle) - dir := path.Dir(p.apps[index].ex) + dir := path.Dir(p.cur[index].ex) if fold, err := os.Open(dir + "/App/AppInfo"); err == nil { var pics []string fi, _ := fold.Readdirnames(-1) @@ -76,13 +99,13 @@ func (p *prtapAdap) Create(th gxui.Theme, index int) gxui.Control { box.AddChild(icon) } lbl := th.CreateLabel() - lbl.SetText(p.apps[index].name) + lbl.SetText(p.cur[index].name) box.AddChild(lbl) return box } func (p *prtapAdap) ItemAt(index int) gxui.AdapterItem { - return p.apps[index] + return p.cur[index] } func (p *prtapAdap) ItemIndex(item gxui.AdapterItem) int { @@ -90,7 +113,7 @@ func (p *prtapAdap) ItemIndex(item gxui.AdapterItem) int { if !ok { return -1 } - for i, v := range p.apps { + for i, v := range p.cur { if v == it { return i } diff --git a/ui.go b/ui.go index ffa551f..abedd07 100644 --- a/ui.go +++ b/ui.go @@ -44,17 +44,33 @@ func uiMain(dri gxui.Driver) { app := applist.Selected().(prtap) dir, fi := path.Split(app.ex) var cmd *exec.Cmd - if commEnbl { - cmd = exec.Command("/bin/sh", "-c", ". "+common+" || exit 1;cd \""+dir+"\"; \"./"+fi+"\"") + if app.wine { + cmd = exec.Command("/bin/sh", "-c", "cd \""+dir+"\"; wine \""+fi+"\"") } else { - cmd = exec.Command("/bin/sh", "-c", "cd \""+dir+"\"; \"./"+fi+"\"") + 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 - go cmd.Run() + cmd.Start() } }) + wine := th.CreateButton() + wine.SetType(gxui.ToggleButton) + wine.OnClick(func(gxui.MouseEvent) { + if wine.IsChecked() { + appAdap.Wine(true) + } else { + appAdap.Wine(false) + } + }) + wine.SetText("Show Windows apps") + wine.SetChecked(appAdap.wine) + but.AddChild(wine) but.AddChild(launch) top.AddChild(but) top.AddChild(spl)