personal-website/apps/sunboard/sunboard.go

87 lines
1.9 KiB
Go
Raw Permalink Normal View History

2023-07-19 01:35:17 +00:00
package sunboard
import (
"net/http"
2023-07-23 03:12:17 +00:00
"path"
2023-07-19 16:38:28 +00:00
"personalwebsite/apps"
2023-07-23 03:12:17 +00:00
"personalwebsite/wde"
2023-07-19 01:35:17 +00:00
"personalwebsite/webfilesystem"
"github.com/gin-gonic/gin"
)
type SunboardApp struct {
2023-07-19 16:38:28 +00:00
fs *webfilesystem.WebFileSystem
2023-07-23 03:12:17 +00:00
wde *wde.WDE
2023-07-19 16:38:28 +00:00
appID string
appStorage *apps.ApplicationsStorage
2023-07-23 03:12:17 +00:00
path string
manifest apps.ApplicationManifest
2023-07-19 01:35:17 +00:00
}
2023-07-23 03:12:17 +00:00
func NewSunboardApp(webFs *webfilesystem.WebFileSystem, wde *wde.WDE, appStorage *apps.ApplicationsStorage) *SunboardApp {
manifest := apps.ApplicationManifest{}
_, err := webFs.Read(path.Join("/Applications/Sunboard.app", ".appmanifest"), &manifest)
if err != nil {
panic(err)
}
2023-07-19 01:35:17 +00:00
newApp := SunboardApp{
2023-07-19 16:38:28 +00:00
fs: webFs,
2023-07-23 03:12:17 +00:00
wde: wde,
2023-07-19 16:38:28 +00:00
appID: "Sunboard",
appStorage: appStorage,
2023-07-23 03:12:17 +00:00
path: "/Applications/Sunboard.app",
manifest: manifest,
2023-07-19 01:35:17 +00:00
}
return &newApp
}
func (a *SunboardApp) GetAppID() string {
return a.appID
}
func (a *SunboardApp) PublicRoutes(route *gin.RouterGroup) {
}
2023-07-23 03:12:17 +00:00
func (a *SunboardApp) GetPath() string {
return a.path
}
func (a *SunboardApp) GetManifest() apps.ApplicationManifest {
return a.manifest
}
2023-07-19 01:35:17 +00:00
2023-07-23 03:12:17 +00:00
func (a *SunboardApp) PrivateRoutes(router *gin.RouterGroup) {
2023-07-19 01:35:17 +00:00
router.POST("render", func(ctx *gin.Context) {
2023-07-19 16:38:28 +00:00
appIcons := []appIcon{}
for _, app := range a.appStorage.Apps {
2023-07-23 03:12:17 +00:00
if app.GetAppID() == "Sunboard" { //FIXME
2023-07-19 16:38:28 +00:00
continue
}
2023-07-23 03:12:17 +00:00
if app.GetManifest().Iconpath == "" {
continue
}
println(app.GetAppID() + " : " + app.GetPath())
// iconPath := path.Join(, "icon.icn")
2023-07-19 16:38:28 +00:00
appIcons = append(appIcons, appIcon{
Type: "Icon",
2023-07-23 03:12:17 +00:00
Icon: "/system/libs/img/icon/get?path=" + app.GetManifest().Iconpath + "&size=32",
2023-07-19 16:38:28 +00:00
Lable: app.GetAppID(),
AppId: app.GetAppID(),
2023-07-23 03:12:17 +00:00
Path: app.GetPath(),
2023-07-19 16:38:28 +00:00
})
}
ctx.HTML(http.StatusOK, "sunboard/sunboard.html", gin.H{
"AppsIcons": appIcons,
})
2023-07-19 01:35:17 +00:00
})
}
2023-07-19 16:38:28 +00:00
type appIcon struct {
AppId string
Type string
Icon string
Lable string
2023-07-21 01:42:12 +00:00
Path string
2023-07-19 16:38:28 +00:00
}