瀏覽代碼

Added cache processing racing retry logic

Toby Chui 3 年之前
父節點
當前提交
07f7212572
共有 2 個文件被更改,包括 75 次插入12 次删除
  1. 25 3
      mod/filesystem/metadata/metadata.go
  2. 50 9
      web/desktop.system

+ 25 - 3
mod/filesystem/metadata/metadata.go

@@ -266,9 +266,8 @@ func (rh *RenderHandler) HandleLoadCache(w http.ResponseWriter, r *http.Request,
 	files = fssort.SortFileList(pendingFiles, sortmode)
 
 	//Updated implementation 24/12/2020: Load image with cache first before rendering those without
-
 	for _, file := range files {
-		if CacheExists(file) == false {
+		if !CacheExists(file) {
 			//Cache not exists. Render this later
 			filesWithoutCache = append(filesWithoutCache, file)
 		} else {
@@ -288,12 +287,15 @@ func (rh *RenderHandler) HandleLoadCache(w http.ResponseWriter, r *http.Request,
 		}
 	}
 
+	retryList := []string{}
+
 	//Render the remaining cache files
 	for _, file := range filesWithoutCache {
 		//Load the image cache
 		cachedImage, err := rh.LoadCache(file, false)
 		if err != nil {
-
+			//Unable to load this file's cache. Push it to retry list
+			retryList = append(retryList, file)
 		} else {
 			jsonString, _ := json.Marshal([]string{filepath.Base(file), cachedImage})
 			err := c.WriteMessage(1, jsonString)
@@ -305,6 +307,26 @@ func (rh *RenderHandler) HandleLoadCache(w http.ResponseWriter, r *http.Request,
 		}
 	}
 
+	//Process the retry list after some wait time
+	if len(retryList) > 0 {
+		time.Sleep(1000 * time.Millisecond)
+		for _, file := range retryList {
+			//Load the image cache
+			cachedImage, err := rh.LoadCache(file, false)
+			if err != nil {
+
+			} else {
+				jsonString, _ := json.Marshal([]string{filepath.Base(file), cachedImage})
+				err := c.WriteMessage(1, jsonString)
+				if err != nil {
+					//Connection closed
+					errorExists = true
+					break
+				}
+			}
+		}
+	}
+
 	//Clear record from syncmap
 	if !errorExists {
 		//This ended normally. Delete the targetPath

+ 50 - 9
web/desktop.system

@@ -1788,9 +1788,20 @@
             $("#stackedWindowList").hide();
         }
 
-        function closeFWviaFWB(object, event) {
-            event.preventDefault();
-            event.stopImmediatePropagation();
+
+        //Close FloatWindow via fwid
+        function closeFloatWindowViaID(fwid){
+            var thisFW = getFloatWindowByID(fwid);
+            closeFloatWindow(thisFW.find(".close"), null);
+        }
+
+        //Close FloatWindow via the floatWindowBody
+        function closeFWviaFWB(object, event=null) {
+            if (event != null){
+                event.preventDefault();
+                event.stopImmediatePropagation();
+            }
+          
             var targetWFID = $(object).parent().attr("windowId");
             var targetFW = getFloatWindowByID(targetWFID);
             if (targetFW == undefined){
@@ -2198,13 +2209,16 @@
             }
         }
 
-        function closeFloatWindow(object, event) {
-            if (event.type == "mousedown" && event.which != 1) {
-                //Ignore right mouse down on close buttons
-                return;
+        function closeFloatWindow(object, event=null) {
+            if (event != null){
+                if (event.type == "mousedown" && event.which != 1) {
+                    //Ignore right mouse down on close buttons
+                    return;
+                }
+                event.preventDefault();
+                event.stopImmediatePropagation();
             }
-            event.preventDefault();
-            event.stopImmediatePropagation();
+         
             if ($(object).is("img")) {
                 object = $(object).panret();
             }
@@ -4643,6 +4657,21 @@
                     }
                     addContextMenuItem($("#contextmenu"), lcontex('Close'), "<i class='remove icon'></i>", "closeSelectedFloatWindow", false);
                     showMenu = true;
+                } else if ($(clickTarget).hasClass("floatWindowButton") || $(clickTarget).parent().hasClass("floatWindowButton")){
+                    if ($(clickTarget).parent().hasClass("floatWindowButton")){
+                        clickTarget = $(clickTarget).parent();
+                    }
+                    //Get the ID list of this button group
+                    var originalIDlist = JSON.parse(decodeURIComponent($(clickTarget).attr('windowIDGroup')));
+                    var buttonGroupName = $(clickTarget).attr('group');
+                    var displayText = lcontex('Close');
+                    if (originalIDlist.length > 1){
+                        //More than 1 window
+                        displayText = lcontex('Close All');
+                    }
+
+                    addContextMenuItem($("#contextmenu"), displayText, "<i class='remove icon'></i>", `closeWindowGroup('${buttonGroupName}');`, false);
+                    showMenu = true;
                 }
 
                 
@@ -6256,6 +6285,18 @@
             return targetFloatWindowId;
         }
 
+        function closeWindowGroup(groupName){
+            $(".floatWindowButton").each(function(){
+                if ($(this).attr("group") == groupName){
+                    var originalIDlist = JSON.parse(decodeURIComponent($(this).attr('windowIDGroup')));
+                    originalIDlist.forEach(fwid => {
+                        closeFloatWindowViaID(fwid);
+                    });
+                    
+                }
+            })
+        }
+
         function getFocusedFloatWindow(){
             var focusedFwId = getFocusedFloatWindowID();
             if (focusedFwId != ""){