diff --git a/apps/appCtx/appContext.go b/apps/appCtx/appContext.go new file mode 100644 index 0000000..44c4f9a --- /dev/null +++ b/apps/appCtx/appContext.go @@ -0,0 +1,7 @@ +package appCtx + +type AppContext struct { + IsMobile bool `json:"isMobile"` + BundlePath string `json:"bundlePath"` + RunPath string `json:"runPath"` +} diff --git a/apps/personalprops/personalprops.go b/apps/personalprops/personalprops.go index 97fba46..387d5ef 100644 --- a/apps/personalprops/personalprops.go +++ b/apps/personalprops/personalprops.go @@ -2,6 +2,7 @@ package personalprops import ( "net/http" + "personalwebsite/apps/appCtx" "personalwebsite/webfilesystem" "github.com/gin-gonic/gin" @@ -23,20 +24,25 @@ func NewPersPropsApp(webFs *webfilesystem.WebFileSystem) *PersonalPropertiesApp } func (p *PersonalPropertiesApp) PublicRoutes(route *gin.RouterGroup) { - route.GET("render", func(ctx *gin.Context) { - isMobileParam := ctx.Query("isMobile") - isMobile := isMobileParam == "true" + route.POST("render", func(ctx *gin.Context) { filePath := ctx.Query("path") if filePath == "" { ctx.Status(http.StatusBadRequest) return } - ginH, err := p.Render(filePath) + appCtx := appCtx.AppContext{} + err := ctx.BindJSON(&appCtx) + if err != nil { + ctx.Status(http.StatusBadRequest) + return + } + + ginH, err := p.Render(appCtx, filePath) if err != nil { ctx.JSON(http.StatusInternalServerError, "TODO") //TODO return } - if isMobile { + if appCtx.IsMobile { ctx.HTML(http.StatusOK, "personal-properties/mobile-app.tmpl", ginH) } else { ctx.HTML(http.StatusOK, "personal-properties/app.tmpl", ginH) @@ -101,13 +107,14 @@ func (p *PersonalPropertiesApp) WriteMock() error { return err } -func (p *PersonalPropertiesApp) Render(filePath string) (gin.H, error) { +func (p *PersonalPropertiesApp) Render(appCtx appCtx.AppContext, filePath string) (gin.H, error) { propsData := PropertiesFileData{} + filePath = p.fs.RelativeToAbsolute(appCtx, filePath) _, err := p.fs.Read(filePath, &propsData) if err != nil { return nil, err } - + propsData.Header.IconPath = p.fs.RelativeToAbsolute(appCtx, propsData.Header.IconPath) return gin.H{ "headerProps": propsData.Header, "allprops": propsData.Props, diff --git a/go.mod b/go.mod index ae8c503..9303a2a 100644 --- a/go.mod +++ b/go.mod @@ -40,6 +40,7 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 github.com/pelletier/go-toml/v2 v2.0.6 // indirect + github.com/thinkerou/favicon v0.2.0 github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.9 // indirect go.mongodb.org/mongo-driver v1.11.4 diff --git a/go.sum b/go.sum index e5c2bdf..562566e 100644 --- a/go.sum +++ b/go.sum @@ -98,6 +98,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/thinkerou/favicon v0.2.0 h1:/qO//fFevzhx68pAAPjuiOwB2ykoKwLcZW9luMZ8PEU= +github.com/thinkerou/favicon v0.2.0/go.mod h1:PM31DMRkXDVi9/sGwb/a/evMB536N9VfVNC+Dtf4iDQ= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= diff --git a/resources/dev-fs/apps/AboutMe/AboutMe.js b/resources/dev-fs/apps/AboutMe/AboutMe.js index 3222af9..d993b57 100644 --- a/resources/dev-fs/apps/AboutMe/AboutMe.js +++ b/resources/dev-fs/apps/AboutMe/AboutMe.js @@ -12,13 +12,13 @@ class AboutMe{ * @param {Object} runContext */ async NewWindow(args, runContext){ - console.log(runContext) const params = new URLSearchParams({ - isMobile: WebDesktopEnvironment.isMobile, - path: `${runContext.bundlePath}/aboutme.props`, - runContext: runContext, + path: `:/aboutme.props`, + }) + const response = await fetch(`/app/${AboutMe.appID}/render?`+ params,{ + method: "POST", + body: JSON.stringify(runContext) }) - const response = await fetch(`/app/${AboutMe.appID}/render?`+ params) if (response.status != 200){ WebDesktopEnvironment.Alert("Error TODO") //TODO return diff --git a/resources/dev-fs/apps/finder/finder.js b/resources/dev-fs/apps/finder/finder.js index 1ea20a2..329e84f 100644 --- a/resources/dev-fs/apps/finder/finder.js +++ b/resources/dev-fs/apps/finder/finder.js @@ -41,7 +41,6 @@ class FinderWindow{ windowElem = undefined async Init(args){ - console.log(args) if (args[1] === "-desktop"){ //todo pass div id, not div in args[] const params = new URLSearchParams({ diff --git a/resources/wde.js b/resources/wde.js index 78b8edc..ee3c97e 100644 --- a/resources/wde.js +++ b/resources/wde.js @@ -49,6 +49,7 @@ class WebDesktopEnvironment{ if (appManifest === undefined) return //TODO return err const runContext = { + isMobile: false, bundlePath: appPath, runPath: "todo" //TODO } @@ -76,8 +77,7 @@ class WebDesktopEnvironment{ script.setAttribute("src", appManifest.js[0]) //FIXME path by fs read script.setAttribute("async", "false") //TODO Possible may creates a problems?? appElem.appendChild(script) - - console.log(appElem) + document.getElementById("applications").appendChild(appElem) script.addEventListener('load', (event) => { let newApp = eval(`new ${appManifest.appId}()`); diff --git a/routes/private.go b/routes/private.go index a4fff29..c0ed386 100644 --- a/routes/private.go +++ b/routes/private.go @@ -15,11 +15,13 @@ import ( "github.com/gin-contrib/cors" "github.com/gin-contrib/location" "github.com/gin-gonic/gin" + "github.com/thinkerou/favicon" ) func PrivateRoutes(webfs *webfilesystem.WebFileSystem, webde *wde.WDE, appsStorage *apps.ApplicationsStorage) { router := gin.New() router.Use(location.Default()) + router.Use(favicon.New("./resources/sys/wde/icons/ohno.png")) // set favicon middleware router.LoadHTMLGlob("templates/**/*") router.Static("/res", "resources") // Set a lower memory limit for multipart forms (default is 32 MiB) diff --git a/routes/public.go b/routes/public.go index be1be0e..262a93b 100644 --- a/routes/public.go +++ b/routes/public.go @@ -12,12 +12,14 @@ import ( "github.com/gin-contrib/location" "github.com/gin-gonic/gin" + "github.com/thinkerou/favicon" ) func PublicRoutes(webfs *webfilesystem.WebFileSystem, webde *wde.WDE, appsStorage *apps.ApplicationsStorage) { router := gin.New() router.Use(location.Default()) router.LoadHTMLGlob("templates/**/*") + router.Use(favicon.New("./resources/sys/wde/icons/ohno.png")) // set favicon middleware router.Static("/res", "resources") router.GET("/", func(ctx *gin.Context) { diff --git a/webfilesystem/webfilesystem.go b/webfilesystem/webfilesystem.go index 6136bcd..1f4cdf0 100644 --- a/webfilesystem/webfilesystem.go +++ b/webfilesystem/webfilesystem.go @@ -3,6 +3,8 @@ package webfilesystem import ( "context" "errors" + "path" + "personalwebsite/apps/appCtx" "strings" "go.mongodb.org/mongo-driver/bson" @@ -361,3 +363,15 @@ func (fs *WebFileSystem) CheckFileExist(filePath string) bool { } return false } + +func (fs *WebFileSystem) RelativeToAbsolute(appCtx appCtx.AppContext, filePath string) string { + switch filePath[0] { + case '.': + return path.Join(appCtx.RunPath, filePath) + case ':': + filePath = strings.ReplaceAll(filePath, ":", "") + return path.Join(appCtx.BundlePath, filePath) + default: + return filePath + } +}