combine all code into a single binary

This commit is contained in:
cuu 2018-12-08 22:43:20 +08:00
parent 1826b16bee
commit 6ef7260d1f
9 changed files with 190 additions and 141 deletions

View File

@ -1,4 +1,4 @@
package main
package Settings
import (
"github.com/veandco/go-sdl2/ttf"
@ -58,14 +58,6 @@ func (self *SettingsPageSelector) Draw() {
}
}
type SettingPlugin struct{
Type int
SoFile string
FolderName string
LabelText string
EmbInterface UI.PluginInterface
}
//##############################################//
type SettingsPage struct {
@ -93,17 +85,17 @@ func NewSettingsPage() *SettingsPage {
return p
}
func (self *SettingsPage) GenList() []*SettingPlugin {
alist := []*SettingPlugin{
func (self *SettingsPage) GenList() []*UI.UIPlugin {
alist := []*UI.UIPlugin{
&SettingPlugin{0,"", "Wifi", "Wi-Fi",&Wifi.APIOBJ},
&UI.UIPlugin{0,"", "Wifi", "Wi-Fi",&Wifi.APIOBJ},
&SettingPlugin{0,"", "Sound", "Sound Volume" , &Sound.APIOBJ},
&SettingPlugin{0,"", "Brightness", "BackLight Brightness", &Brightness.APIOBJ},
&SettingPlugin{0,"", "Update", "Update", &Update.APIOBJ},
&SettingPlugin{0,"", "About", "About", &About.APIOBJ},
&UI.UIPlugin{0,"", "Sound", "Sound Volume" , &Sound.APIOBJ},
&UI.UIPlugin{0,"", "Brightness", "BackLight Brightness", &Brightness.APIOBJ},
&UI.UIPlugin{0,"", "Update", "Update", &Update.APIOBJ},
&UI.UIPlugin{0,"", "About", "About", &About.APIOBJ},
&SettingPlugin{1,"", "LauncherPy", "Switch to Launcher", &LauncherPy.APIOBJ},
&UI.UIPlugin{1,"", "LauncherPy", "Switch to Launcher", &LauncherPy.APIOBJ},
}

View File

@ -1,5 +1,5 @@
{
"SO_FILE":"Settings.so",
"SO_FILE":"",
"NAME":"Settings"
}

View File

@ -1,5 +1,9 @@
package main
/*
* Creating functionality in this way is not recommended
* cause every .so file is about the size of an executable file(like main)
* Referring to the Settings code, write all the functions directly into main
*/
import (
"github.com/veandco/go-sdl2/ttf"

View File

@ -1,6 +1,6 @@
#!/bin/bash
go build main.go
go build main.go mainscreen.go
##HelloWorld
cd Menu/GameShell/HelloWorld/
@ -8,7 +8,4 @@ go build -ldflags="-s -w" -o HelloWorld.so -buildmode=plugin
cd -
cd Menu/GameShell/10_Settings
go build -o Settings.so -buildmode=plugin
cd -

View File

@ -11,7 +11,7 @@ import (
"runtime"
"path/filepath"
"os/exec"
//"encoding/json"
gotime "time"
"github.com/veandco/go-sdl2/sdl"
"github.com/cuu/gogame"
@ -24,6 +24,8 @@ import (
"github.com/cuu/LauncherGoDev/sysgo"
"github.com/cuu/LauncherGoDev/sysgo/UI"
)
var (
@ -35,6 +37,7 @@ var (
everytime_keydown = gotime.Now()
)
// flash the Led1 on the GS back
func FlashLed1(main_screen *UI.MainScreen) {
@ -253,7 +256,8 @@ func run() int {
main_screen.TitleBar = title_bar
main_screen.FootBar = foot_bar
main_screen.ReadTheDirIntoPages("Menu",0,nil)
ReadTheDirIntoPages(main_screen,"Menu",0,nil)
main_screen.FartherPages()
main_screen.Draw()

144
mainscreen.go Normal file
View File

@ -0,0 +1,144 @@
package main
import (
//"os"
"fmt"
"log"
"io/ioutil"
// "strconv"
"strings"
// "runtime"
"path/filepath"
//os/exec"
"encoding/json"
"github.com/cuu/LauncherGoDev/sysgo/UI"
"github.com/cuu/LauncherGoDev/Menu/GameShell/10_Settings"
)
var (
UIPluginList = []*UI.UIPlugin {
&UI.UIPlugin{1,"", "Menu/GameShell/10_Settings", "Settings", &Settings.APIOBJ},
}
)
func ReadTheDirIntoPages(self *UI.MainScreen, _dir string, pglevel int, cur_page UI.PageInterface) {
if UI.FileExists(_dir) == false && UI.IsDirectory(_dir) == false {
return
}
files,err := ioutil.ReadDir(_dir)
if err != nil {
log.Fatal(err)
return
}
for _,f := range files { // already sorted
if UI.IsDirectory( _dir +"/"+f.Name()) {
if pglevel == 0 {
page := UI.NewPage()
page.Name = self.ExtraName(f.Name())
self.Pages = append(self.Pages, page)
ReadTheDirIntoPages(self,_dir+"/"+f.Name(),pglevel+1, self.Pages[ len(self.Pages) - 1] )
}else{ // on cur_page now
i2:= self.ExtraName(f.Name())
iconitem := UI.NewIconItem()
iconitem.AddLabel(i2,self.IconFont)
if UI.FileExists( UI.SkinMap(_dir+"/"+i2+".png")) {
iconitem.ImageName = UI.SkinMap(_dir+"/"+i2+".png")
}else {
fmt.Println( UI.SkinMap(_dir+"/"+i2+".png") )
untitled := UI.NewUntitledIcon()
untitled.Init()
if len(i2) > 1 {
untitled.SetWords(string(i2[0]),string(i2[1]))
}else if len(i2) == 1 {
untitled.SetWords(string(i2[0]),string(i2[0]))
}else {
untitled.SetWords("G","s")
}
iconitem.ImgSurf = untitled.Surface()
iconitem.ImageName = ""
}
if self.IsPluginPackage(_dir+"/"+f.Name()) {
p_c := UI.PluginConfig{}
dat, err := ioutil.ReadFile(_dir+"/"+f.Name()+"/" +UI.Plugin_flag)
UI.ShowErr(err)
err = json.Unmarshal(dat, &p_c)
if err == nil {
if p_c.NAME == "" {
p_c.NAME = f.Name()
}
so_file := filepath.Join(_dir,f.Name(),p_c.SO_FILE)
if UI.FileExists(so_file) && UI.IsAFile(so_file) {
pi,err := UI.LoadPlugin(_dir+"/"+f.Name()+"/"+p_c.SO_FILE)
UI.Assert(err)
iconitem.CmdInvoke = UI.InitPlugin(pi,self)
if iconitem.CmdInvoke != nil {
iconitem.MyType = UI.ICON_TYPES["FUNC"]
iconitem.CmdPath = f.Name()
cur_page.AppendIcon(iconitem)
}
} else {
for _,v := range UIPluginList {
if v.LabelText == p_c.NAME {
v.EmbInterface.Init(self)
iconitem.CmdInvoke = v.EmbInterface
if iconitem.CmdInvoke != nil {
iconitem.MyType = UI.ICON_TYPES["FUNC"]
iconitem.CmdPath = f.Name()
cur_page.AppendIcon(iconitem)
}
}
}
}
}
//Init it
}else {
iconitem.MyType = UI.ICON_TYPES["DIR"]
linkpage := UI.NewPage()
linkpage.Name = i2
iconitem.LinkPage = linkpage
cur_page.AppendIcon(iconitem)
ReadTheDirIntoPages(self,_dir+"/"+f.Name(),pglevel+1, iconitem.LinkPage)
}
}
} else if UI.IsAFile(_dir+"/"+f.Name()) && (pglevel > 0) {
if strings.HasSuffix(strings.ToLower(f.Name()),UI.IconExt) {
i2 := self.ExtraName(f.Name())
iconitem := UI.NewIconItem()
iconitem.CmdPath = _dir+"/"+f.Name()
UI.MakeExecutable( iconitem.CmdPath )
iconitem.MyType = UI.ICON_TYPES["EXE"]
if UI.FileExists( UI.SkinMap( _dir+"/"+ UI.ReplaceSuffix(i2,"png"))) {
iconitem.ImageName = UI.SkinMap( _dir+"/"+ UI.ReplaceSuffix(i2,"png"))
}else {
untitled:= UI.NewUntitledIcon()
untitled.Init()
if len(i2) > 1 {
untitled.SetWords(string(i2[0]),string(i2[1]))
}else if len(i2) == 1 {
untitled.SetWords(string(i2[0]),string(i2[0]))
}else {
untitled.SetWords("G","s")
}
iconitem.ImgSurf = untitled.Surface()
iconitem.ImageName = ""
}
iconitem.AddLabel(strings.Split(i2,".")[0], self.IconFont)
iconitem.LinkPage = nil
cur_page.AppendIcon(iconitem)
}
}
}
}

View File

@ -14,3 +14,8 @@ var (
DT = 50
)
var (
Emulator_flag = "action.json"
Plugin_flag = "plugin.json"
)

View File

@ -1,12 +1,13 @@
package UI
import (
"fmt"
//"fmt"
"io/ioutil"
"strings"
"log"
"encoding/json"
//"encoding/json"
//"path/filepath"
"github.com/veandco/go-sdl2/sdl"
"github.com/veandco/go-sdl2/ttf"
@ -19,13 +20,10 @@ import (
"github.com/cuu/gogame/time"
"github.com/cuu/gogame/event"
"github.com/cuu/LauncherGoDev/sysgo/DBUS"
)
var (
emulator_flag = "action.json"
plugin_flag = "plugin.json"
)
type PluginConfig struct {
@ -159,6 +157,8 @@ type MainScreen struct {
DBusManager *DBUS.DBus
CounterScreen *CounterScreen
Closed bool
UIPluginList []*UIPlugin
}
@ -191,6 +191,7 @@ func (self *MainScreen) Init() {
self.CounterScreen.HWND = self.HWND
self.CounterScreen.Init()
//self.GenList() // load predefined plugin list,ready to be injected ,or ,as a .so for dynamic loading
}
@ -275,7 +276,7 @@ func (self *MainScreen) IsPluginPackage(dirname string ) bool {
if f.IsDir() {
//pass
}else {
if strings.HasSuffix(f.Name(),plugin_flag) == true {
if strings.HasSuffix(f.Name(),Plugin_flag) == true {
ret = true
break
}
@ -297,7 +298,7 @@ func (self *MainScreen) IsEmulatorPackage(dirname string ) bool {
if f.IsDir() {
//pass
}else {
if strings.HasSuffix(f.Name(),emulator_flag) == true {
if strings.HasSuffix(f.Name(),Emulator_flag) == true {
ret = true
break
}
@ -307,112 +308,6 @@ func (self *MainScreen) IsEmulatorPackage(dirname string ) bool {
return ret
}
func (self *MainScreen) ReadTheDirIntoPages(_dir string, pglevel int, cur_page PageInterface) {
if FileExists(_dir) == false && IsDirectory(_dir) == false {
return
}
files,err := ioutil.ReadDir(_dir)
if err != nil {
log.Fatal(err)
return
}
for _,f := range files { // already sorted
if IsDirectory( _dir +"/"+f.Name()) {
if pglevel == 0 {
page := NewPage()
page.Name = self.ExtraName(f.Name())
self.Pages = append(self.Pages, page)
self.ReadTheDirIntoPages(_dir+"/"+f.Name(),pglevel+1, self.Pages[ len(self.Pages) - 1] )
}else{ // on cur_page now
i2:= self.ExtraName(f.Name())
iconitem := NewIconItem()
iconitem.AddLabel(i2,self.IconFont)
if FileExists( SkinMap(_dir+"/"+i2+".png")) {
iconitem.ImageName = SkinMap(_dir+"/"+i2+".png")
}else {
fmt.Println( SkinMap(_dir+"/"+i2+".png") )
untitled := NewUntitledIcon()
untitled.Init()
if len(i2) > 1 {
untitled.SetWords(string(i2[0]),string(i2[1]))
}else if len(i2) == 1 {
untitled.SetWords(string(i2[0]),string(i2[0]))
}else {
untitled.SetWords("G","s")
}
iconitem.ImgSurf = untitled.Surface()
iconitem.ImageName = ""
}
if self.IsPluginPackage(_dir+"/"+f.Name()) {
p_c := PluginConfig{}
dat, err := ioutil.ReadFile(_dir+"/"+f.Name()+"/" +plugin_flag)
ShowErr(err)
err = json.Unmarshal(dat, &p_c)
if err == nil {
if p_c.NAME == "" {
p_c.NAME = f.Name()
}
pi,err := LoadPlugin(_dir+"/"+f.Name()+"/"+p_c.SO_FILE)
Assert(err)
iconitem.CmdInvoke = InitPlugin(pi,self)
if iconitem.CmdInvoke != nil {
iconitem.MyType = ICON_TYPES["FUNC"]
iconitem.CmdPath = f.Name()
cur_page.AppendIcon(iconitem)
}
}
//Init it
}else {
iconitem.MyType = ICON_TYPES["DIR"]
linkpage := NewPage()
linkpage.Name = i2
iconitem.LinkPage = linkpage
cur_page.AppendIcon(iconitem)
self.ReadTheDirIntoPages(_dir+"/"+f.Name(),pglevel+1, iconitem.LinkPage)
}
}
} else if IsAFile(_dir+"/"+f.Name()) && (pglevel > 0) {
if strings.HasSuffix(strings.ToLower(f.Name()),IconExt) {
i2 := self.ExtraName(f.Name())
iconitem := NewIconItem()
iconitem.CmdPath = _dir+"/"+f.Name()
MakeExecutable( iconitem.CmdPath )
iconitem.MyType = ICON_TYPES["EXE"]
if FileExists( SkinMap( _dir+"/"+ ReplaceSuffix(i2,"png"))) {
iconitem.ImageName = SkinMap( _dir+"/"+ ReplaceSuffix(i2,"png"))
}else {
untitled:= NewUntitledIcon()
untitled.Init()
if len(i2) > 1 {
untitled.SetWords(string(i2[0]),string(i2[1]))
}else if len(i2) == 1 {
untitled.SetWords(string(i2[0]),string(i2[0]))
}else {
untitled.SetWords("G","s")
}
iconitem.ImgSurf = untitled.Surface()
iconitem.ImageName = ""
}
iconitem.AddLabel(strings.Split(i2,".")[0], self.IconFont)
iconitem.LinkPage = nil
cur_page.AppendIcon(iconitem)
}
}
}
}
func (self *MainScreen) RunEXE( cmdpath string) {
self.DrawRun()
self.SwapAndShow()

View File

@ -4,6 +4,7 @@ import (
"log"
goplugin "plugin"
)
var PluginPool = NewPluginPool()
type PluginInterface interface {
@ -90,3 +91,10 @@ func RunPlugin(p *goplugin.Plugin, main_screen *MainScreen) {
pi.Run(main_screen)
}
type UIPlugin struct{ //Loadable and injectable
Type int
SoFile string
FolderName string
LabelText string
EmbInterface PluginInterface
}