From 2f2ad23fd6d4619e4871eba8b7729d48341f377a Mon Sep 17 00:00:00 2001 From: cyber-dream Date: Sun, 30 Apr 2023 00:01:23 +0300 Subject: [PATCH] Desktop with files and background --- main.go | 8 +++++++ resources/sys/finder/finder.js | 41 +++++++++++++++++++++++++++++----- resources/wde.js | 10 +++++++-- resources/wdeUI.css | 7 ++++++ templates/finder/desktop.tmpl | 6 +++++ 5 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 templates/finder/desktop.tmpl diff --git a/main.go b/main.go index 5a25850..0713d37 100644 --- a/main.go +++ b/main.go @@ -213,6 +213,14 @@ func main() { finderAppRoute.GET("renderMobileDesktop", func(ctx *gin.Context) { ctx.HTML(http.StatusOK, "finder/mobile-desktop.tmpl", gin.H{}) }) + finderAppRoute.GET("renderDesktop", func(ctx *gin.Context) { + path := ctx.Query("path") + if path == "" { + ctx.JSON(http.StatusBadRequest, "no path provided") + return + } + ctx.HTML(http.StatusOK, "finder/desktop.tmpl", gin.H{}) + }) } imgViewerRoute := app.Group("img-viewer") { diff --git a/resources/sys/finder/finder.js b/resources/sys/finder/finder.js index a63bd04..095deef 100644 --- a/resources/sys/finder/finder.js +++ b/resources/sys/finder/finder.js @@ -10,10 +10,14 @@ class Finder{ } /** - * @param {string} path + * @param {string[]} args */ NewWindow(args){ this.path = args[0] + if (args[1] == "desktop"){ + this.NewDesktop(args) + return + } fetch(`${window.location.origin}/application/${this.appId}/render?` + new URLSearchParams({ isMobile: WebDesktopEnvironment.isMobile, // path: this.path, @@ -25,7 +29,7 @@ class Finder{ newWindow.innerHTML = html this.fileView = new FileView(newWindow.querySelector(".FileTileView"), (event) =>{ - this.Click(event, this.path) + this.Click(event, false) }) this.OpenDir(this.path) @@ -39,7 +43,7 @@ class Finder{ if (!WebDesktopEnvironment.isMobile){ // let scrollBar = new WdeScrollBar(newWindow.children[1].children[1], newWindow.children[1].children[0])// TODO to querry selector - console.log(newWindow.querySelector("#closeWindowButton")) + // console.log(newWindow.querySelector("#closeWindowButton")) newWindow.querySelector("#closeWindowButton").addEventListener('click', function (params) { WebDesktopEnvironment.CloseWindow(newWindow) @@ -52,6 +56,29 @@ class Finder{ }) } + /** + * @param {string[]} args + */ + NewDesktop(args){ + fetch(`${window.location.origin}/application/${this.appId}/renderDesktop?` + new URLSearchParams({ + isMobile: WebDesktopEnvironment.isMobile, + path: args[0] + })) + .then((response) => response.text()) + .then((html) => { + // console.log(args) + args[2].innerHTML = html + + this.fileView = new FileView(args[2].querySelector(".FileTileView"), (event) =>{ + this.Click(event, true) + }) + this.OpenDir(this.path) + }) + .catch((error) => { + WebDesktopEnvironment.Alert(error); + }) + } + OpenPreviousDir(){ if (this.pathHistory.length > 0){ // console.log(this.pathHistory) @@ -66,7 +93,6 @@ class Finder{ * @param {string} path */ OpenDir(path){ - console.log() this.pathHistory += this.path this.path = path this.fileView.OpenFolder(this.path) @@ -74,12 +100,17 @@ class Finder{ /** * @param {MouseEvent} event + * @param {boolean} inNewWindow */ - Click(event){ + Click(event, inNewWindow){ let fileType = event.target.getAttribute("fileType") let fileName = event.target.getAttribute("name") switch (fileType) { case "directory": + if (inNewWindow){ + WebDesktopEnvironment.Open("finder", ["/home/user/" + fileName]) //FIXME this.path is shared for all windows + break + } this.OpenDir(this.path +"/" + fileName) break case "blog-page": diff --git a/resources/wde.js b/resources/wde.js index 9972160..df0157e 100644 --- a/resources/wde.js +++ b/resources/wde.js @@ -2,9 +2,9 @@ document.addEventListener('DOMContentLoaded', function() { // console.log(window.screen.width) wde = new WebDesktopEnvironment if (!WebDesktopEnvironment.isMobile){ - WebDesktopEnvironment.Open("finder", ["/home/user"]) + // WebDesktopEnvironment.Open("finder", ["/home/user"]) // WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"]) - WebDesktopEnvironment.Open("personal-properties", ["kek"]) + // WebDesktopEnvironment.Open("personal-properties", ["kek"]) } else { WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"]) } @@ -58,6 +58,12 @@ class WebDesktopEnvironment{ } else{ document.body.style.setProperty('--zoom', 1) + let desktopLayer = document.createElement("div") + desktopLayer.setAttribute('id', 'desktop-layer') + desktopLayer.setAttribute('class', 'DesktopBackground') + document.body.appendChild(desktopLayer) + WebDesktopEnvironment.Open("finder", ["/home/user", "desktop", desktopLayer]) + let windowsLayer = document.createElement("div") windowsLayer.setAttribute('id', 'windows-layer') document.body.appendChild(windowsLayer) diff --git a/resources/wdeUI.css b/resources/wdeUI.css index f47219e..f555449 100644 --- a/resources/wdeUI.css +++ b/resources/wdeUI.css @@ -349,3 +349,10 @@ width: 0; height: 0; } + +.DesktopBackground{ + position: absolute; + width: 100%; + height: 100%; + background-color: #9999CC; +} \ No newline at end of file diff --git a/templates/finder/desktop.tmpl b/templates/finder/desktop.tmpl new file mode 100644 index 0000000..0bccf73 --- /dev/null +++ b/templates/finder/desktop.tmpl @@ -0,0 +1,6 @@ +{{ define "finder/desktop.tmpl" }} +
+
+{{ end }} + + \ No newline at end of file