Compare commits

..

No commits in common. "46ad190b2a9a156674bac651466887899d8e55db" and "5fe693f664b0f5e2c84207cf2abceee8eac672e7" have entirely different histories.

9 changed files with 106 additions and 169 deletions

View File

@ -32,27 +32,26 @@ func (f *FinderApplication) Render(isMobile bool) gin.H {
return gin.H{} return gin.H{}
} }
func (f *FinderApplication) RenderContextMenu(context string, filePath string, data string) gin.H { func (f *FinderApplication) RenderContextMenu(context string, data string) gin.H {
islands := [][]wde.ContexMenuRow{} islands := [][]wde.ContexMenuRow{}
islands = append(islands, []wde.ContexMenuRow{})
islands = append(islands, []wde.ContexMenuRow{
{Label: "Get Info", Action: "getInfo"},
{Label: "New Directory", Action: "createDir"},
})
if context == "FileTileView" { if context == "FileTileView" {
islands = append(islands, []wde.ContexMenuRow{
{Label: "Get Info", Action: "getInfo"},
{Label: "New Directory", Action: "createDir"},
})
return gin.H{ return gin.H{
"Islands": islands, "Islands": islands,
} }
} }
islands = append(islands, []wde.ContexMenuRow{
{Label: "Delete File", Action: "deleteFile"},
// {Label: "Get Info", Action: "getInfo"},
})
switch context { switch context {
case "directory": case "directory":
if f.fs.GetExtension(filePath) == "app" {
islands = append(islands, []wde.ContexMenuRow{
{Label: "Open as Directory", Action: "openAsDir"},
})
}
default: default:
islands = append(islands, []wde.ContexMenuRow{ islands = append(islands, []wde.ContexMenuRow{
{Label: "temp Menu 1", Action: ""}, {Label: "temp Menu 1", Action: ""},
@ -60,10 +59,6 @@ func (f *FinderApplication) RenderContextMenu(context string, filePath string, d
}) })
} }
islands = append(islands, []wde.ContexMenuRow{
{Label: "Delete File", Action: "deleteFile"},
})
return gin.H{ return gin.H{
"Islands": islands, "Islands": islands,
} }

View File

@ -36,17 +36,8 @@ func (f *FinderApplication) Routes(routes *gin.RouterGroup) {
routes.GET("contextMenu", func(ctx *gin.Context) { routes.GET("contextMenu", func(ctx *gin.Context) {
context := ctx.Query("context") context := ctx.Query("context")
// if context == "" {
// ctx.Status(http.StatusBadRequest)
// return
// }
filePath := ctx.Query("path")
if filePath == "" {
ctx.Status(http.StatusBadRequest)
return
}
data := ctx.Query("data") data := ctx.Query("data")
ginH := f.RenderContextMenu(context, filePath, data) ginH := f.RenderContextMenu(context, data)
ctx.HTML(http.StatusOK, "wde-widgets/context-menu.tmpl", ginH) ctx.HTML(http.StatusOK, "wde-widgets/context-menu.tmpl", ginH)
}) })

View File

@ -18,7 +18,7 @@ type WebDEApplication interface {
} }
type ApplicationManifest struct { type ApplicationManifest struct {
AppId string `bson:"appid" json:"appId"` AppId string `bson:"appid" json:"appid"`
Js []string `bson:"js" json:"js"` Js []string `bson:"js" json:"js"`
Css []string `bson:"css" json:"css"` Css []string `bson:"css" json:"css"`
} }
@ -38,19 +38,16 @@ type ApplicationsStorage struct {
func (as *ApplicationsStorage) createApp(appName string, appId string, appPath string) error { func (as *ApplicationsStorage) createApp(appName string, appId string, appPath string) error {
newAppData := ApplicationManifest{ newAppData := ApplicationManifest{
AppId: appId, AppId: appId,
Js: []string{},
Css: []string{},
} }
newAppFile := webfilesystem.FileHeader{ newAppFile := webfilesystem.FileHeader{
MongoId: primitive.NewObjectID(), MongoId: primitive.NewObjectID(),
Name: ".appmanifest", Name: appName + ".appmanifest",
Type: "application-manifest", Type: "application",
Icon: "", Icon: "",
Data: primitive.NewObjectID(), Data: primitive.NewObjectID(),
} }
//TODO: Create folder for app, etc
_, _, err := as.fs.Write(appPath+"/"+newAppFile.Name, &newAppFile, newAppData) _, _, err := as.fs.Write(appPath+"/"+newAppFile.Name, &newAppFile, newAppData)
if err != nil { if err != nil {
return err return err

View File

@ -128,13 +128,13 @@ func main() {
{ {
webfs.Route(fs) webfs.Route(fs)
} }
app := router.Group("app") app := router.Group("application")
{ {
persPropApp := app.Group("AboutMe") persPropApp := app.Group("personal-properties")
{ {
persPropsApp.Route(persPropApp) persPropsApp.Route(persPropApp)
} }
finderAppRoute := app.Group("Finder") finderAppRoute := app.Group("finder")
{ {
finderApp.Routes(finderAppRoute) finderApp.Routes(finderAppRoute)
} }

View File

@ -1,5 +1,5 @@
class Finder{ class Finder{
appId = "Finder" appId = "finder"
fileView = undefined fileView = undefined
path = "/" path = "/"
homePath = "/home/user" homePath = "/home/user"
@ -8,20 +8,22 @@ class Finder{
pathHistory = [] //FIXME Fixed length pathHistory = [] //FIXME Fixed length
constructor(){ constructor(){
// this.appElem = appElem // this.appElem = appElem
// WebDesktopEnvironment.RegisterApp(this)
} }
/** /**
* @param {string[]} args * @param {string[]} args
*/ */
async NewWindow(args){ NewWindow(args){
this.path = args[0] this.path = args[0]
if (args[1] == "desktop"){ if (args[1] == "desktop"){
this.NewDesktop(args) this.NewDesktop(args)
return return
} }
const params = new URLSearchParams({isMobile: WebDesktopEnvironment.isMobile}) fetch(`${window.location.origin}/application/${this.appId}/render?` + new URLSearchParams({
fetch(`/app/${this.appId}/render?` + params) isMobile: WebDesktopEnvironment.isMobile,
// path: this.path,
// bar: true,
})) //TODO Move to wde func. Or Not?
.then((response) => response.text()) .then((response) => response.text())
.then((html) => { .then((html) => {
let newWindow = WebDesktopEnvironment.CreateNewWindow(this.appId, 500, 350 ) let newWindow = WebDesktopEnvironment.CreateNewWindow(this.appId, 500, 350 )
@ -147,14 +149,9 @@ class Finder{
Click(event){ Click(event){
let fileType = event.target.getAttribute("fileType") let fileType = event.target.getAttribute("fileType")
let fileName = event.target.getAttribute("name") let fileName = event.target.getAttribute("name")
const fileExtension = fileName.split(".")[fileName.split(".").length - 1] //FIXME
switch (fileType) { switch (fileType) {
case "directory": case "directory":
if (fileExtension == "app"){ WebDesktopEnvironment.Open("finder", [`${this.path}/${fileName}`]) //FIXME this.path is shared for all windows
WebDesktopEnvironment.Open(`${this.path}/${fileName}`, [])
} else{
WebDesktopEnvironment.Open(`/Applications/Finder.app`, [`${this.path}/${fileName}`])
}
break break
case "blog": case "blog":
WebDesktopEnvironment.Open("blog-viewer", [`${this.path}/${fileName}`]) WebDesktopEnvironment.Open("blog-viewer", [`${this.path}/${fileName}`])
@ -179,16 +176,15 @@ class Finder{
CreateContextMenu(target, pos){ CreateContextMenu(target, pos){
let context = "" let context = ""
const fileName = target.getAttribute("name")
const fileType = target.getAttribute("fileType")
if (target.classList.contains("FileTileView")) if (target.classList.contains("FileTileView"))
{ {
context = "FileTileView" context = "FileTileView"
} else {
context = fileType
} }
const params = new URLSearchParams({context: context, path: `${this.path}/${fileName}`}) fetch(`${window.location.origin}/application/${this.appId}/contextMenu?` + new URLSearchParams({
fetch(`/app/${this.appId}/contextMenu?` + params) context: context
}))
.then((response) => response.text()) .then((response) => response.text())
.then((html) => { .then((html) => {
let overlay = document.createElement("div") //TODO Move to WDE.CreateOverlay() let overlay = document.createElement("div") //TODO Move to WDE.CreateOverlay()
@ -211,6 +207,8 @@ class Finder{
overlay.addEventListener('click', (event) => { overlay.addEventListener('click', (event) => {
if (event.target.classList.contains("Row")){ //TODO add uuid id to rows to more accurate checks?? if (event.target.classList.contains("Row")){ //TODO add uuid id to rows to more accurate checks??
let fileType = target.getAttribute("fileType")
let fileName = target.getAttribute("name")
switch (event.target.children[0].getAttribute("action")) { switch (event.target.children[0].getAttribute("action")) {
case "createDir": case "createDir":
fetch(`/fs/createDir?` + new URLSearchParams({ fetch(`/fs/createDir?` + new URLSearchParams({
@ -265,10 +263,6 @@ class Finder{
.catch((error) => { .catch((error) => {
WebDesktopEnvironment.Alert(error); WebDesktopEnvironment.Alert(error);
}) })
break
case "openAsDir":
WebDesktopEnvironment.Open(`/Applications/${this.appId}.app`,[`${this.path}/${fileName}`])
break
default: default:
break; break;
} }

View File

@ -1,5 +1,5 @@
class AboutMe{ class PersonalProperties{
appId = "AboutMe" appId = "personal-properties"
/** /**
* @param {HTMLElement} appElem * @param {HTMLElement} appElem
*/ */
@ -9,14 +9,12 @@ class AboutMe{
/** /**
* @param {string} path * @param {string} path
* @param {[]string} args
*/ */
NewWindow(path, args){ NewWindow(path){
if (path == ""){ fetch(`${window.location.origin}/application/personal-properties/render?`+ new URLSearchParams({
path = "/home/user/aboutme.props" //FIXME isMobile: WebDesktopEnvironment.isMobile,
} path: path
const params = new URLSearchParams({isMobile: WebDesktopEnvironment.isMobile, path: path}) }))
fetch(`/app/${this.appId}/render?`+ params)
.then((response) => response.text()) .then((response) => response.text())
.then((html) => { .then((html) => {
// console.log(document.body) // console.log(document.body)

View File

@ -2,14 +2,14 @@
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
// console.log(window.screen.width) // console.log(window.screen.width)
wde = new WebDesktopEnvironment() wde = new WebDesktopEnvironment
if (!WebDesktopEnvironment.isMobile){ if (!WebDesktopEnvironment.isMobile){
// WebDesktopEnvironment.Open("finder", ["/home/user"]) WebDesktopEnvironment.Open("finder", ["/home/user"])
WebDesktopEnvironment.fetchApp("/home/user/AboutMe.app")
// WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog1.blog"]) // WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog1.blog"])
// WebDesktopEnvironment.Open("personal-properties", ["/home/user/aboutme.props"]) // WebDesktopEnvironment.Open("personal-properties", ["/home/user/aboutme.props"])
} else { } else {
// WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"]) WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"])
} }
@ -20,18 +20,11 @@ class WebDesktopEnvironment{
static Applications = {}; static Applications = {};
static isMobile = false static isMobile = false
constructor(){ constructor(){
// WebDesktopEnvironment.Open("finder", ["/home/user", "desktop", document.querySelector('#desktop-layer')]) WebDesktopEnvironment.isMobile = WebDesktopEnvironment.CheckMobile()
//TODO create key -desktop-mode
this.wc = new WindowsCompositor()
this.loadWDE()
return
// WebDesktopEnvironment.isMobile = WebDesktopEnvironment.CheckMobile()
// let applications = document.createElement("div") let applications = document.createElement("div")
// applications.setAttribute('id', 'applications') applications.setAttribute('id', 'applications')
// document.body.appendChild(applications) document.body.appendChild(applications)
if( WebDesktopEnvironment.isMobile){ if( WebDesktopEnvironment.isMobile){
document.body.style.setProperty('--zoom', 3) document.body.style.setProperty('--zoom', 3)
@ -68,83 +61,17 @@ class WebDesktopEnvironment{
} else{ } else{
document.body.style.setProperty('--zoom', 1) document.body.style.setProperty('--zoom', 1)
// let desktopLayer = document.createElement("div") let desktopLayer = document.createElement("div")
// desktopLayer.setAttribute('id', 'desktop-layer') desktopLayer.setAttribute('id', 'desktop-layer')
// document.body.appendChild(desktopLayer) document.body.appendChild(desktopLayer)
WebDesktopEnvironment.Open("finder", ["/home/user", "desktop", desktopLayer]) WebDesktopEnvironment.Open("finder", ["/home/user", "desktop", desktopLayer])
// let windowsLayer = document.createElement("div") let windowsLayer = document.createElement("div")
// windowsLayer.setAttribute('id', 'windows-layer') windowsLayer.setAttribute('id', 'windows-layer')
// document.body.appendChild(windowsLayer) document.body.appendChild(windowsLayer)
this.Autoload()
} }
} this.wc = new WindowsCompositor
async loadWDE(){
// await WebDesktopEnvironment.load2('/Applications/Finder.app', [ "desktop", document.querySelector('#desktop-layer')])
// WebDesktopEnvironment.Open('/Applications/Finder.app', ["/home/user", "desktop", document.querySelector('#desktop-layer')])
WebDesktopEnvironment.Open('/Applications/Finder.app', ["/home/user",])
}
/**
* @param {string} appPath
* @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)
}
})
}
/**
* @param {string} appManifest
* @param {function} onload callback after script loading
*/
static async load2(appManifest, onload){
let appElem = document.createElement("div")
appElem.setAttribute("appId", appManifest.appId)
//TODO Render scripts nodes on server
//FIXME Not support more than one js now :)
let script = document.createElement("script")
script.setAttribute("src", appManifest.js[0]) //FIXME path by fs read
script.setAttribute("async", "false") //TODO Possible may creates a problems??
appElem.appendChild(script)
document.getElementById("applications").appendChild(appElem)
script.addEventListener('load', (event) => {
let newApp = eval(`new ${appManifest.appId}()`);
//TODO Check if newApp undefined
WebDesktopEnvironment.Applications[appManifest.appId] = newApp;
onload()
})
return //TODO return result
}
/**
* @param {string} path
* @returns {Object | undefined} //FIXME
*/
static async fetchApp(path){
const params = new URLSearchParams({path: path})
const response = await fetch(`/system/libs/apps/loadApp?` + params)
if (response.status != 200){
return undefined
}
const appManifest = response.json()
return appManifest
}
Autoload(){
// WebDesktopEnvironment.Open(["/home/user/AboutMe.app"])
// WebDesktopEnvironment.load2(["/home/user/AboutMe.app"])
} }
/** /**
* @param {string} appId * @param {string} appId
@ -189,7 +116,44 @@ class WebDesktopEnvironment{
}) })
} }
/**
* @param {string} path
* @param {function} callbackFunc callback after script loading
* @returns {Application | undefined}
*/
static loadApp2(path, callbackFunc){
//var myObject = window[classNameString]; to load random classes
}
/**
* @param {string} path
* @returns {Application | undefined} //FIXME
*/
static fetchApp(path){
fetch(`/system/libs/apps/loadApp?` + new URLSearchParams({
path: path,
})) .then(async (response) => {
console.log(await response.json())
})
.catch((error) => {
WebDesktopEnvironment.Alert(error);
})
}
/**
* @param {string} appId
* @param {string[]} args
*/
static Open(appId, args){
if (this.Applications[appId] == undefined){
console.log(`Application ${appId} is not loaded yet`)
WebDesktopEnvironment.LoadApp(appId, () =>{
this.Applications[appId].NewWindow(args)
})
} else {
this.Applications[appId].NewWindow(args)
}
}
/** /**
* @param {string} appId * @param {string} appId

View File

@ -24,9 +24,7 @@
</head> </head>
<body> <body>
<!-- <div id="WindowsLayer"></div> --> <!-- <div id="WindowsLayer"></div> -->
<div id="applications"></div> <!-- <div id="Applications"></div> -->
<div id="desktop-layer"></div>
<div id="windows-layer"></div>
<!-- <div id="TestWindow" style="width: 100px; height: 100px; background-color: darkkhaki; position: absolute;" > <!-- <div id="TestWindow" style="width: 100px; height: 100px; background-color: darkkhaki; position: absolute;" >
<div id="TestWindowHeader" class="VisualDragArea" style="width: 100%;height: 15px; background-color: cornflowerblue;"> <div id="TestWindowHeader" class="VisualDragArea" style="width: 100%;height: 15px; background-color: cornflowerblue;">
</div> --> </div> -->

View File

@ -106,21 +106,21 @@ func (fs *WebFileSystem) Route(route *gin.RouterGroup) {
ctx.JSON(http.StatusOK, &files) ctx.JSON(http.StatusOK, &files)
}) })
route.GET("read", func(ctx *gin.Context) { // route.GET("read", func(ctx *gin.Context) {
path := ctx.Query("path") // path := ctx.Query("path")
if path == "" { // if path == "" {
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct // ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
return // return
} // }
file, err := fs.Read(path, nil) // file, err := fs.NewReadDeprecated(path)
if err != nil { // if err != nil {
ctx.JSON(http.StatusInternalServerError, "TODO") //TODO json error struct // ctx.JSON(http.StatusInternalServerError, "TODO") //TODO json error struct
return // return
} // }
ctx.JSON(http.StatusOK, &file) // ctx.JSON(http.StatusOK, &file)
}) // })
route.GET("validate", func(ctx *gin.Context) { route.GET("validate", func(ctx *gin.Context) {
err := fs.Validate() err := fs.Validate()