From 9cc2dc5a42b81142f265503ca06bdd8ae8ecdc56 Mon Sep 17 00:00:00 2001 From: cyber-dream Date: Wed, 17 May 2023 16:57:55 +0300 Subject: [PATCH] Fix run of AboutMe.app --- apps/websiteapp.go | 25 +++++++++++-- .../apps/AboutMe/AboutMe.js} | 21 ++++++----- resources/dev-fs/apps/finder/finder.js | 6 +-- resources/wde.js | 37 +++++++++++-------- webfilesystem/routes.go | 7 ++-- 5 files changed, 61 insertions(+), 35 deletions(-) rename resources/{sys/personal-properties/personal-properties.js => dev-fs/apps/AboutMe/AboutMe.js} (60%) diff --git a/apps/websiteapp.go b/apps/websiteapp.go index 5d3dc24..4adae9d 100644 --- a/apps/websiteapp.go +++ b/apps/websiteapp.go @@ -39,6 +39,25 @@ type ApplicationsStorage struct { } func (as *ApplicationsStorage) createApp(appName string, appId string, appPath string) error { + appBundleName := appName + ".app" + newAppBundleHeader := webfilesystem.FileHeader{ + MongoId: primitive.NewObjectID(), + Name: appBundleName, + Type: "directory", + Icon: "", + Data: primitive.NewObjectID(), + } + newAppBundleData := webfilesystem.DirectoryData{ + MongoId: primitive.NewObjectID(), + Parent: primitive.NewObjectID(), + Children: []primitive.ObjectID{}, + } + + _, _, err := as.fs.Write(appPath+"/"+appBundleName, &newAppBundleHeader, &newAppBundleData) + if err != nil { + return err + } + newAppData := ApplicationManifest{ AppId: appId, Js: []string{}, @@ -52,9 +71,7 @@ func (as *ApplicationsStorage) createApp(appName string, appId string, appPath s Icon: "", Data: primitive.NewObjectID(), } - - //TODO: Create folder for app, etc - _, _, err := as.fs.Write(appPath+"/"+newAppFile.Name, &newAppFile, newAppData) + _, _, err = as.fs.Write(appPath+"/"+appBundleName+"/"+newAppFile.Name, &newAppFile, newAppData) if err != nil { return err } @@ -118,7 +135,7 @@ func (aStorage *ApplicationsStorage) PrivateRoute(route *gin.RouterGroup) { err := aStorage.createApp(appId, appName, appPath) if err != nil { - ctx.Status(http.StatusInternalServerError) + ctx.String(http.StatusInternalServerError, err.Error()) return } ctx.Status(http.StatusOK) diff --git a/resources/sys/personal-properties/personal-properties.js b/resources/dev-fs/apps/AboutMe/AboutMe.js similarity index 60% rename from resources/sys/personal-properties/personal-properties.js rename to resources/dev-fs/apps/AboutMe/AboutMe.js index 6fbd7d9..3222af9 100644 --- a/resources/sys/personal-properties/personal-properties.js +++ b/resources/dev-fs/apps/AboutMe/AboutMe.js @@ -1,5 +1,5 @@ class AboutMe{ - appId = "AboutMe" + static appID = "AboutMe" /** * @param {HTMLElement} appElem */ @@ -8,16 +8,17 @@ class AboutMe{ } /** - * @param {string} chroot - * @param {[]string} args + * @param {[]string} args + * @param {Object} runContext */ - async NewWindow(chroot, args){ - console.log(chroot) - if (chroot == ""){ - chroot = "/Applications" //FIXME - } - const params = new URLSearchParams({isMobile: WebDesktopEnvironment.isMobile, path: `${chroot}/AboutMe.app/aboutme.props`}) - const response = await fetch(`/app/${this.appId}/render?`+ params) + async NewWindow(args, runContext){ + console.log(runContext) + const params = new URLSearchParams({ + isMobile: WebDesktopEnvironment.isMobile, + path: `${runContext.bundlePath}/aboutme.props`, + runContext: 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 f27fc0a..1ea20a2 100644 --- a/resources/dev-fs/apps/finder/finder.js +++ b/resources/dev-fs/apps/finder/finder.js @@ -41,7 +41,7 @@ class FinderWindow{ windowElem = undefined async Init(args){ - // console.log(args) + console.log(args) if (args[1] === "-desktop"){ //todo pass div id, not div in args[] const params = new URLSearchParams({ @@ -131,11 +131,11 @@ class FinderWindow{ WebDesktopEnvironment.Alert("UWAGA TODO MOVE FILE ERROR") //TODO } } else { - console.log(event) + console.log(event, this.curPath) let files = event.dataTransfer.files for (let i = 0; i < files.length; i++) { const file = files[i]; - console.log("file:" + file) + console.log("file:" + file.name) const res = await WebFS.UploadFile(file, this.curPath) if (res){ diff --git a/resources/wde.js b/resources/wde.js index 42d76d7..78b8edc 100644 --- a/resources/wde.js +++ b/resources/wde.js @@ -36,7 +36,8 @@ class WebDesktopEnvironment{ async loadWDE(){ // await WebDesktopEnvironment.load2('/Applications/Finder.app', [ "desktop", document.querySelector('#desktop-layer')]) await WebDesktopEnvironment.Open('/Applications/Finder.app', ["/home/user/.desktop", "-desktop", document.querySelector('#desktop-layer')]) - WebDesktopEnvironment.Open('/Applications/Finder.app', ["/",]) + // WebDesktopEnvironment.Open('/Applications/Finder.app', ["/",]) + WebDesktopEnvironment.Open('/Applications/AboutMe.app', []) } /** @@ -44,16 +45,21 @@ class WebDesktopEnvironment{ * @param {string[]} args */ static async Open(appPath, args){ - WebDesktopEnvironment.fetchApp(appPath).then(async appManifest =>{ - if (appManifest === undefined) return //TODO return err - if (WebDesktopEnvironment.Applications[appManifest.appId] === undefined){ - WebDesktopEnvironment.load2(appManifest, () =>{ - WebDesktopEnvironment.Applications[appManifest.appId].NewWindow(args) - }) - } else { - WebDesktopEnvironment.Applications[appManifest.appId].NewWindow(args) - } - }) + const appManifest = await WebDesktopEnvironment.fetchApp(appPath) + + if (appManifest === undefined) return //TODO return err + const runContext = { + bundlePath: appPath, + runPath: "todo" //TODO + } + if (WebDesktopEnvironment.Applications[appManifest.appId] === undefined){ + WebDesktopEnvironment.load2(appManifest, () =>{ + WebDesktopEnvironment.Applications[appManifest.appId].NewWindow(args, runContext) + }) + } else { + WebDesktopEnvironment.Applications[appManifest.appId].NewWindow(args) + } + } @@ -70,7 +76,8 @@ 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}()`); @@ -372,15 +379,15 @@ class WebFS{ /** * @param {File} file - * @param {string} filePath + * @param {string} parentPath * @returns {boolean} */ - static async UploadFile(file, filePath){ + static async UploadFile(file, parentPath){ console.log('here') let formData = new FormData() formData.append("file", file) //FIXME Conn reset const params = new URLSearchParams({ - filePath: filePath, + parentPath: parentPath, }) const response = await fetch(`/system/fs/upload?` + params, { diff --git a/webfilesystem/routes.go b/webfilesystem/routes.go index f09a6e1..d83848e 100644 --- a/webfilesystem/routes.go +++ b/webfilesystem/routes.go @@ -2,6 +2,7 @@ package webfilesystem import ( "net/http" + "path" "personalwebsite/errormessage" "github.com/gin-gonic/gin" @@ -15,8 +16,8 @@ func (fs *WebFileSystem) PrivateRoutes(route *gin.RouterGroup) { // ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct // return // } - filePath := ctx.Query("filePath") - if filePath == "" { + parentPath := ctx.Query("parentPath") + if parentPath == "" { ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct return } @@ -34,7 +35,7 @@ func (fs *WebFileSystem) PrivateRoutes(route *gin.RouterGroup) { ctx.SaveUploadedFile(file, dst) //TODO: Not Save to disk - err := fs.UploadFile(dst, filePath) + err := fs.UploadFile(dst, path.Join(parentPath, file.Filename)) if err != nil { ctx.JSON(http.StatusInternalServerError, errormessage.ErrorMessage{ Message: err.Error(),