From e6138cba1eb38dc85eb9260aeb960980b208c72c Mon Sep 17 00:00:00 2001 From: cyber-dream Date: Sun, 28 May 2023 04:28:48 +0300 Subject: [PATCH] Autostart list from backend --- res/dev-fs/apps/Finder/finder.js | 22 ++++++++++++++-------- res/dev-fs/wde/wde.js | 28 +++++++++++++++++++++++++++- routes/private.go | 3 +-- routes/public.go | 4 ++-- routewde/wde.go => wde/routes.go | 5 ++--- 5 files changed, 46 insertions(+), 16 deletions(-) rename routewde/wde.go => wde/routes.go (89%) diff --git a/res/dev-fs/apps/Finder/finder.js b/res/dev-fs/apps/Finder/finder.js index cac0c0f..8763a03 100644 --- a/res/dev-fs/apps/Finder/finder.js +++ b/res/dev-fs/apps/Finder/finder.js @@ -40,26 +40,32 @@ class FinderWindow{ fileView = undefined windowElem = undefined - async Init(args, runContext){ - if (args[1] === "-desktop"){ - //todo pass div id, not div in args[] + async Init(args, appContext){ + if (args[1] == "--desktop"){ + let desktopNode = document.body.querySelector(`#${args[2]}`) + if (desktopNode == null){ + WebDesktopEnvironment.Alert("Desktop node not found") + return + } + const params = new URLSearchParams({ - isMobile: WebDesktopEnvironment.isMobile, path: args[0] }) const response = await fetch(`/app/${Finder.AppId}/renderDesktop?` + params, { method: "POST", - body: JSON.stringify(runContext) + body: JSON.stringify(appContext) }) if (response.status != 200){ + console.log(response.status) WebDesktopEnvironment.Alert("Error in render desktop") //TODO + return } const html = await response.text() - args[2].innerHTML = html + desktopNode.innerHTML = html this.fileView = new FileView( - args[2].querySelector(".FileTileView"), (event) =>{this.Click(event)}, + desktopNode.querySelector(".FileTileView"), (event) =>{this.Click(event)}, (event) => { this.RightClick(event) }, (event, draggedElem) => { this.DropEvent(event, draggedElem)}, () => { this.ReRenderDir() } @@ -71,7 +77,7 @@ class FinderWindow{ const response = await fetch(`/app/${Finder.AppId}/render?` + params, { method: "POST", - body: JSON.stringify(runContext) + body: JSON.stringify(appContext) }) if (response.status != 200){ const error = await response.json() diff --git a/res/dev-fs/wde/wde.js b/res/dev-fs/wde/wde.js index 5c2bea2..800064a 100644 --- a/res/dev-fs/wde/wde.js +++ b/res/dev-fs/wde/wde.js @@ -34,9 +34,35 @@ class WebDesktopEnvironment{ } async loadWDE(){ + let autoStart = document.body.querySelector("wde-autostart") + if (autoStart == null){ + WebDesktopEnvironment.Alert("Error in loading DE") + return + } + for (const child of autoStart.children) { + if (child.nodeName != "APP") continue + let appPath = child.getAttribute("app-path") + if (appPath == null) continue + + let args = [] + let argsRaw = child.querySelector("args") + if (argsRaw == null) continue + + for (const argRaw of argsRaw.children) { + let arg = argRaw.getAttribute("string") + if (arg == null) continue + args.push(arg) + } + + // console.log(appPath, args) + await WebDesktopEnvironment.Open(appPath, args) + } + + autoStart.remove() + // await WebDesktopEnvironment.load2('/Applications/Finder.app', [ "desktop", document.querySelector('#desktop-layer')]) //FIXME // await WebDesktopEnvironment.Open('/Applications/Finder.app', ["/home/user/.desktop", "-desktop", document.querySelector('#desktop-layer')]) - await WebDesktopEnvironment.Open('/Applications/Finder.app', ["/home/user/Blogs",]) + // await WebDesktopEnvironment.Open('/Applications/Finder.app', ["/home/user/Blogs",]) // await WebDesktopEnvironment.Open('/Applications/Finder.app', ["/home/user",]) // await WebDesktopEnvironment.Open('/Applications/Finder.app', ["/home",]) // WebDesktopEnvironment.Open('/Applications/AboutMe.app', []) diff --git a/routes/private.go b/routes/private.go index 9b81766..26e897c 100644 --- a/routes/private.go +++ b/routes/private.go @@ -7,7 +7,6 @@ import ( "personalwebsite/apps" "personalwebsite/errormessage" "personalwebsite/libs" - "personalwebsite/routewde" "personalwebsite/wde" "personalwebsite/webfilesystem" "time" @@ -54,7 +53,7 @@ func PrivateRoutes(port string, webfs *webfilesystem.WebFileSystem, webde *wde.W wdeGroup := systemGroup.Group("wde") { - routewde.PublicRoutes(wdeGroup, webde) + wde.PublicRoutes(wdeGroup, webde) } fsGroup := systemGroup.Group("fs") diff --git a/routes/public.go b/routes/public.go index 443d9e7..3f7db17 100644 --- a/routes/public.go +++ b/routes/public.go @@ -6,7 +6,7 @@ import ( "path" "personalwebsite/apps" "personalwebsite/libs" - "personalwebsite/routewde" + "personalwebsite/wde" "personalwebsite/webfilesystem" @@ -45,7 +45,7 @@ func PublicRoutes(port string, webfs *webfilesystem.WebFileSystem, webde *wde.WD wdeGroup := systemGroup.Group("wde") { - routewde.PublicRoutes(wdeGroup, webde) + wde.PublicRoutes(wdeGroup, webde) } systemGroup.GET("/loadApp", func(ctx *gin.Context) { diff --git a/routewde/wde.go b/wde/routes.go similarity index 89% rename from routewde/wde.go rename to wde/routes.go index 6f92a2f..f507cdc 100644 --- a/routewde/wde.go +++ b/wde/routes.go @@ -1,14 +1,13 @@ -package routewde +package wde import ( "net/http" - "personalwebsite/wde" "github.com/gin-contrib/location" "github.com/gin-gonic/gin" ) -func PublicRoutes(route *gin.RouterGroup, wde *wde.WDE) { +func PublicRoutes(route *gin.RouterGroup, wde *WDE) { route.GET("/getbasicwindow", func(ctx *gin.Context) { //TODO Rename to renderGenericWindowFrame ctx.HTML(http.StatusOK, "basic-window.html", nil) })