Sfoglia il codice sorgente

Implemented desktop file preview thumbnail

TC pushbot 5 4 anni fa
parent
commit
d00b259d5e
1 ha cambiato i file con 78 aggiunte e 2 eliminazioni
  1. 78 2
      web/desktop.system

+ 78 - 2
web/desktop.system

@@ -5107,14 +5107,90 @@
                 $(".launchIcon").remove();
             }
             if (callback == undefined) {
-                initDesktopFiles(launchOption);
+                initDesktopFiles(launchOption, function(){
+                    startThumbnailLoader();
+                });
             } else {
-                initDesktopFiles(launchOption, callback);
+                initDesktopFiles(launchOption, function(){
+                    startThumbnailLoader();
+                    callback()
+                });
             }
 
+            
+
             hideAllContextMenus();
         }
 
+        function startThumbnailLoader(){
+            let path = "user:/Desktop";
+            let protocol = "wss://";
+            if (location.protocol !== 'https:') {
+                protocol = "ws://";
+            }
+
+            var port = window.location.port;
+            if (window.location.port == ""){
+                port = "80";
+            }
+
+            thumbRenderWebSocket = new WebSocket(protocol + window.location.hostname + ":" + port + "/system/file_system/handleCacheRender?folder=" + path);
+
+            thumbRenderWebSocket.onopen = function(e) {
+
+            };
+
+            thumbRenderWebSocket.onmessage = function(event) {
+                //Find the correct file in the current directory and place its image
+                let thumbData = JSON.parse(event.data);
+                $(".launchIcon").each(function(){
+                    if (thumbData[1].length > 0){
+                        if ($(this).attr("filename") == thumbData[0]){
+                            let imageContainer = $(this).find(".launchIconImage");
+                            imageContainer.attr("src","data:image/jpg;base64," + thumbData[1]);
+                            imageContainer.css("padding", "0.6em");
+
+                            //Load the application icon on this file
+                            let filedata = $(this).attr("filedata");
+                            filedata = JSON.parse(decodeURIComponent(filedata));
+                            $.ajax({
+                                url: "system/modules/getDefault",
+                                data: {opr: "launch", ext: filedata.Ext},
+                                method: "GET",
+                                success: function(data){
+                                    if (data.error == undefined){
+                                        let iconSize = 20;
+                                        let topOffset = $(imageContainer).height() - iconSize/2 + 2;
+                                        $(imageContainer).parent().append(`<img src="${data.IconPath}" style="position: absolute; right: 0px; top: ${topOffset}px; width: ${iconSize}px; height: ${iconSize}px;"></img>`);
+                                        console.log(filedata.Filename, data);
+                                    }
+                                }
+                            })
+                        }
+                    }
+                });
+
+                /*
+                $(".fileObject").each(function(){
+                    if (thumbData[1].length > 0){
+                        if ($(this).attr("filename") == thumbData[0]){
+                            $(this).find("img").attr("src","data:image/jpg;base64," + thumbData[1]);
+                        }
+                    }
+                    
+                });
+                */
+            };
+
+            thumbRenderWebSocket.onclose = function(event) {
+                //Transfer ended
+            };
+
+            thumbRenderWebSocket.onerror = function(error) {
+                console.log(error);
+            };
+        }
+
 
         function openfm() {
             //Open file explorer on desktop