Jelajahi Sumber

Updated function completed (require launcher)

Toby Chui 3 tahun lalu
induk
melakukan
ff5a8c2ecc
3 mengubah file dengan 106 tambahan dan 11 penghapusan
  1. 10 0
      mod/updates/updates.go
  2. 11 11
      web/SystemAO/updates/index.html
  3. 85 0
      web/SystemAO/updates/updating.html

+ 10 - 0
mod/updates/updates.go

@@ -23,6 +23,12 @@ func DownloadUpdatesFromURL(binaryURL string, webpackURL string, progressUpdateF
 	binaryDownloadTarget := "./updates/" + filepath.Base(binaryURL)
 	webpackDownloadTarget := "./updates/" + filepath.Base(webpackURL)
 
+	//Check if the webpack is .tar.gz
+	if filepath.Ext(webpackDownloadTarget) != ".gz" {
+		//This is not a gzip file
+		return errors.New("Webpack in invalid compression format")
+	}
+
 	//Start the download of binary
 	//0 = false, 1 = true, 2 = error
 	binaryDownloadComplete := 0
@@ -40,6 +46,8 @@ func DownloadUpdatesFromURL(binaryURL string, webpackURL string, progressUpdateF
 			progressUpdateFunction(0, 100, "Binary Download Completed")
 		} else {
 			progressUpdateFunction(0, 100, "Error: "+errorMessage)
+			//Remove the update folder
+			os.RemoveAll("./updates/")
 		}
 
 	}()
@@ -64,6 +72,8 @@ func DownloadUpdatesFromURL(binaryURL string, webpackURL string, progressUpdateF
 			progressUpdateFunction(1, 100, "Webpack Download Completed")
 		} else {
 			progressUpdateFunction(1, 100, "Error: "+errorMessage)
+			//Remove the update folder
+			os.RemoveAll("./updates/")
 		}
 	}()
 	err = downloadFile(webpackURL, webpackDownloadTarget)

+ 11 - 11
web/SystemAO/updates/index.html

@@ -86,13 +86,14 @@
                     <p id="failedErrorMessage">Unknown Error Occured</p>
                 </div>
             </div>
-            <div id="restartPanel" class="ui inversed red message" style="display:none;">
+            <div id="restartPanel" class="ui message" style="display:none;">
                 <div class="header" >
-                    Launcher Exists: <span id="launcherName"></span>
+                    Launcher Exists: <span id="launcherName">N/A</span>
                 </div>
                 <p>You will need to restart ArozOS in order to apply the updates.</p>
                 <p>Warning! Make sure you have physical access to this ArozOS Host before pressing the restart button.<br> Update failure might require a manual restart of the ArozOS system host and its launcher.</p>
-                <button class="ui red button" onclick="restartArozOS();">RESTART ArozOS WITH LAUNCHER</button>
+                <button class="ui red button" onclick="restartArozOS();">RESTART NOW</button>
+                <button class="ui button" onclick="restartLater();">Restart Later</button>
             </div>
             <!-- End of Status Messages -->
             <h4>Update via Download</h4>
@@ -265,14 +266,7 @@
 
         function restartArozOS(){
             if (confirm("CONFIRM RESTART?")){
-                $.ajax({
-                    url: "/system/update/restart",
-                    method: "POST",
-                    data: {exec: true},
-                    success: function(data){
-                        console.log(data);
-                    }
-                });
+                window.top.location.href = "../updates/updating.html";
             }
         }
 
@@ -281,6 +275,11 @@
             $("#warning").slideDown("fast");
         }
 
+        function restartLater(){
+            hideAllStatus();
+        }
+
+
         function hideAllStatus(){
             $("#warning").slideUp("fast");
             $("#confirmDownload").slideUp("fast");
@@ -288,6 +287,7 @@
             $("#downloading").slideUp("fast");
             $("#success").slideUp("fast");
             $("#failed").slideUp("fast");
+            $("#restartPanel").slideUp("fast");
         }
     </script>
 </body>

+ 85 - 0
web/SystemAO/updates/updating.html

@@ -0,0 +1,85 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>System Update</title>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
+    <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
+    <script type="text/javascript" src="../../script/jquery.min.js"></script>
+    <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
+    <script type="text/javascript" src="../../script/ao_module.js"></script>
+    <style>
+        body{
+            background-color: #1c1c1c;
+        }
+        #panel {
+            display: flex;
+            justify-content: center;
+            align-items: center;
+            text-align: center;
+            min-height: 100vh;
+        }
+    </style>
+</head>
+<body>
+    <div id="panel" style="text-align: left;">
+        <div id="pinging" class="ui message">
+            <div class="header" >
+                <i class="ui loading spinner icon"></i> Performing System Updates
+            </div>
+            <p>The updates might take a few minutes depending on your disk IO and CPU speed. This page will refresh itself after the update completes.</p>
+            <p>Last Ping: <span id="pingTime"></span></p>
+            <div class="ui divider"></div>
+            <p><i class="info icon"></i> Do you know you can write your own launcher / updater for ArozOS by using some simple code of your own?</p>
+        </div>
+        <div id="succ" class="ui green message" style="min-width: 30vw; display:none;">
+            <div class="header">
+                <i class="ui green big checkmark icon"></i> Update Completed
+            </div>
+            <p>Redirecting to homepage in 3 seconds.<br> If it doesn't work, click <a href="../../">here</a></p>
+        </div>
+    </div>
+    <script>
+        //Delay 1 sec and start update process
+        setTimeout(function(){
+            $("#pingTime").text("READY!");
+            UpdateRestartArozOS();
+        }, 1000)
+        
+        function UpdateRestartArozOS(){
+            $.ajax({
+                url: "/system/update/restart",
+                method: "POST",
+                data: {exec: true},
+                success: function(data){
+                   //This wont succ
+                }
+            });
+            setTimeout(function(){
+                pingServer();
+            }, 1000);
+        }
+        function pingServer(){
+            $.ajax({
+                url: "../../system/auth/checkLogin",
+                error: function(){
+                    //Not started up yet, ping again 3 sec later
+                    setTimeout(function(){
+                        pingServer();
+                    }, 3000);
+                    $("#pingTime").text(new Date().toLocaleString(undefined, {year: 'numeric', month: '2-digit', day: '2-digit', weekday:"long", hour: '2-digit', hour12: false, minute:'2-digit', second:'2-digit'}));
+                },
+                success: function(){
+                    //Server started up again. Redirect back to index
+                    $("#pinging").slideUp("fast");
+                    $("#succ").slideDown("fast");
+                    setTimeout(function(){
+                        window.location.href = "../../";
+                    }, 3200);
+                    
+                },
+                timeout: 1000 
+            })
+        }
+    </script>
+</body>