Fix run of AboutMe.app

This commit is contained in:
cyber-dream 2023-05-17 16:57:55 +03:00
parent 56038cc284
commit 9cc2dc5a42
5 changed files with 61 additions and 35 deletions

View File

@ -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)

View File

@ -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

View File

@ -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){

View File

@ -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,
{

View File

@ -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(),