Jelajahi Sumber

Added testing code for linux

Toby Chui 1 tahun lalu
induk
melakukan
c5714ab2c2

+ 1 - 1
disk.go

@@ -132,7 +132,7 @@ func DiskServiceInit() {
 		*/
 
 		if *allow_hardware_management {
-			adminRouter.HandleFunc("/system/disk/diskmg/view", diskmg.HandleView)
+			authRouter.HandleFunc("/system/disk/diskmg/view", diskmg.HandleView)
 			adminRouter.HandleFunc("/system/disk/diskmg/platform", diskmg.HandlePlatform)
 			adminRouter.HandleFunc("/system/disk/diskmg/mount", func(w http.ResponseWriter, r *http.Request) {
 				//Mount option require passing in all filesystem handlers

+ 14 - 15
mod/disk/diskmg/diskmg.go

@@ -64,12 +64,12 @@ var (
 )
 
 /*
-	Diskmg View Generator
-	This section of the code is a direct translation of the original
-	AOB's diskmg.php and diskmgWin.php.
+Diskmg View Generator
+This section of the code is a direct translation of the original
+AOB's diskmg.php and diskmgWin.php.
 
-	If you find any bugs in these code, just remember they are legacy
-	code and rewriting the whole thing will save you a lot more time.
+If you find any bugs in these code, just remember they are legacy
+code and rewriting the whole thing will save you a lot more time.
 */
 func HandleView(w http.ResponseWriter, r *http.Request) {
 	partition, _ := utils.GetPara(r, "partition")
@@ -185,10 +185,10 @@ func HandleView(w http.ResponseWriter, r *http.Request) {
 }
 
 /*
-	Mounting a given partition or devices
-	Manual translated from mountTool.php
+Mounting a given partition or devices
+Manual translated from mountTool.php
 
-	Require GET parameter: dev / format / mnt
+Require GET parameter: dev / format / mnt
 */
 func HandleMount(w http.ResponseWriter, r *http.Request, fsHandlers []*fs.FileSystemHandler) {
 	if runtime.GOOS == "linux" {
@@ -260,9 +260,8 @@ func HandleMount(w http.ResponseWriter, r *http.Request, fsHandlers []*fs.FileSy
 }
 
 /*
-	Format Tool
-	Manual translation from AOB's formatTool.php
-
+Format Tool
+Manual translation from AOB's formatTool.php
 */
 func HandleFormat(w http.ResponseWriter, r *http.Request, fsHandlers []*fs.FileSystemHandler) {
 	dev, err := utils.PostPara(r, "dev")
@@ -380,7 +379,7 @@ func Mount(devID string, mountpt string, mountingTool string, fsHandlers []*fs.F
 	return string(o), err
 }
 
-//Unmount a given mountpoint
+// Unmount a given mountpoint
 func Unmount(mountpt string, fsHandlers []*fs.FileSystemHandler) (string, error) {
 	//Unmount the fsHandlers that related to this mountpt
 	for _, fsh := range fsHandlers {
@@ -396,14 +395,14 @@ func Unmount(mountpt string, fsHandlers []*fs.FileSystemHandler) (string, error)
 	return string(o), err
 }
 
-//Return a list of mountable directory
+// Return a list of mountable directory
 func HandleListMountPoints(w http.ResponseWriter, r *http.Request) {
 	mp, _ := filepath.Glob("/media/*")
 	js, _ := json.Marshal(mp)
 	utils.SendJSONResponse(w, string(js))
 }
 
-//Check if the device is mounted
+// Check if the device is mounted
 func checkDeviceMounted(devname string) (bool, error) {
 	cmd := exec.Command("bash", "-c", "lsblk -f -b --json | grep "+devname)
 	output, err := cmd.CombinedOutput()
@@ -447,7 +446,7 @@ func getDeviceMountPoint(devname string) (string, error) {
 	}
 }
 
-//Check device valid, only usable in linux
+// Check device valid, only usable in linux
 func checkDeviceValid(devname string) (bool, string) {
 	//Check if the device name is valid
 	match, _ := regexp.MatchString("sd[a-z][1-9]", devname)

+ 171 - 0
web/SystemAO/desktop/utils/diskoverview.html

@@ -0,0 +1,171 @@
+<div class="diskoverview">
+    <style>
+        #diskrender{
+            max-height: 300px;
+            overflow-y: auto;
+            overflow-x: hidden;
+        }
+
+        #diskrender .ui.avatar.image{
+            border-radius: 0 !important;
+            margin-top: 1em;
+        }
+
+        #diskrender .content{
+            width: calc(100% - 40px);
+        }
+        
+        #diskrender .driveinfo{
+           
+        }
+
+        #diskrender .diskspace{
+            margin-top: 0.6em;
+        }
+
+        #diskrender .progress .bar{
+            background-color: var(--theme_color) !important;
+        }
+
+        #diskrender .progress .bar.lowspace{
+            background-color: #b51d1d !important;
+        }
+    </style>
+    <div id="diskrender">
+        <div class="ui list" id="diskspaceList">
+            <div class="item driveinfo">
+              <img class="ui avatar image" src="img/system/drive.svg">
+              <div class="content">
+                <div class="header"> (C:\)</div>
+                <div class="description">
+                    <div class="ui active small fluid progress diskspace">
+                        <div class="bar" style="width: 30%">
+                          <div class="progress"></div>
+                        </div>
+                    </div>
+                </div>
+              </div>
+            </div>
+            <div class="item driveinfo">
+                <img class="ui avatar image" src="img/system/drive.svg">
+                <div class="content">
+                  <div class="header">新增磁碟區 (D:\)</div>
+                  <div class="description">
+                      <div class="ui active small fluid progress diskspace">
+                          <div class="bar lowspace" style="width: 50%;">
+                            <div class="progress"></div>
+                          </div>
+                      </div>
+                  </div>
+                </div>
+              </div>
+        </div>
+    </div>
+
+    <script>
+        // This is intented to be loaded on the desktop.system interface
+        // use paths from web root instead of relative path from this script
+
+        updateDiskSpaceOverview();
+        function updateDiskSpaceOverview(){
+            $("#diskspaceList").html(`<div style="text-align: center; margin-top: 2em;"><i class="ui loading spinner icon"></i></div>`);
+            $.get("./system/disk/diskmg/view", function(data){
+                if (data.error != undefined){
+                    //Unable to load API, hide the util
+                    $("#diskrender").hide();
+                    return;
+                }
+                if (data[0] && typeof(data[0]["blockdevices"]) != "undefined"){
+                    //This is a linux host
+                    $("#diskspaceList").html("");
+                    for (var i = 0; i < data[0]["blockdevices"].length; i++){
+                        let thisDiskInfo = data[0]["blockdevices"][i];
+                        let driveId = thisDiskInfo.name;
+                        let diskName = "";
+                        if (thisDiskInfo.children.length > 0){
+                            //Try to extract mountpoint as name
+                            let mountpoint = thisDiskInfo.children[0].mountpoint;
+                            if (mountpoint == null || mountpoint == undefined){
+                                mountpoint = "";
+                            }
+
+                            diskName = mountpoint;
+                        }
+
+                        let remainingSpace = 0;
+                        //Try to get the remaining space from mounted partitions
+                        if (data[2].length > 0){
+                            let accumulateRemainingSpace = 0;
+                            for (var j = 0; j < data[2].length; i++){
+                                //For each mounted partitions
+                                let thisPartInfo = data[2][j];
+                                let thisPartName = thisPartInfo[0]; //e.g. /dev/sdc1
+                                if (thisPartName.includes("/" + driveId)){
+                                    //Check if part name include drive id, e.g. /sdc
+                                    //If yes, add the parition remaining space to acc
+                                    accumulateUsedSpace += thisPartInfo[3];
+                                }
+                            }
+
+                            remainingSpace = accumulateRemainingSpace;
+                        }
+                        let totalSpace = thisDiskInfo.size;
+                        let usedSpace = totalSpace - remainingSpace;
+                        let usedPercentage = (usedSpace / totalSpace) * 100;
+                        let colorClass = "";
+                        if (usedPercentage > 90){
+                            colorClass = "lowspace";
+                        }
+
+                        $("#diskspaceList").append(`<div class="item driveinfo">
+                            <img class="ui avatar image" src="img/system/drive.svg">
+                            <div class="content">
+                                <div class="header">${diskName} (${driveId})</div>
+                                <div class="description">
+                                    <div class="ui active small fluid progress diskspace">
+                                        <div class="bar ${colorClass}" style="width: ${usedPercentage}%">
+                                        <div class="progress">${usedPercentage.toFixed(1)}%</div>
+                                        </div>
+                                    </div>
+                                </div>
+                            </div>
+                            </div>`);
+                    }
+                }else if (data[0].length == 7){
+                    //This is a Window hosts
+                    $("#diskspaceList").html("");
+                    for (var i = 0; i < data.length; i++){
+                        let thisDiskInfo = data[i];
+                        let driveId = thisDiskInfo[0].replace("\\\\", "\\");
+                        let diskName = thisDiskInfo[2];
+                        let remainingSpace = thisDiskInfo[5];
+                        let totalSpace = thisDiskInfo[6];
+                        let usedSpace = totalSpace - remainingSpace;
+                        let usedPercentage = (usedSpace / totalSpace) * 100;
+                        let colorClass = "";
+                        if (usedPercentage > 90){
+                            colorClass = "lowspace";
+                        }
+
+                        $("#diskspaceList").append(`<div class="item driveinfo">
+                            <img class="ui avatar image" src="img/system/drive.svg">
+                            <div class="content">
+                                <div class="header">${diskName} (${driveId})</div>
+                                <div class="description">
+                                    <div class="ui active small fluid progress diskspace">
+                                        <div class="bar ${colorClass}" style="width: ${usedPercentage}%">
+                                        <div class="progress">${usedPercentage.toFixed(1)}%</div>
+                                        </div>
+                                    </div>
+                                </div>
+                            </div>
+                            </div>`);
+                    }
+                }else{
+                    //Something else
+                    $("#diskrender").text("Platform not supported");
+                }
+            })
+        }
+    </script>
+</div>

+ 11 - 0
web/SystemAO/desktop/utils/sysoverview.html

@@ -0,0 +1,11 @@
+<div class="sysoverview">
+    <style>
+        #sysoverviewRender{
+            height: 200px;
+            border: 1px solid blue;
+        }
+    </style>
+    <div id="sysoverviewRender">
+        SYSTEM OVERVIEW
+    </div>
+</div>

+ 90 - 56
web/desktop.system

@@ -784,10 +784,11 @@
             bottom:calc(36px + 0.4em);
             left:55px;
             z-index:114;
-            width:300px;
+            width:720px;
             border-radius: 6px;
-            max-height: calc(100% - 100px);
-            overflow-y: auto;
+            overflow: hidden;
+            max-height: calc(100% - 136px);
+            
             scrollbar-width: thin;
             border: 1px solid #ebebeb;
             padding-top:8px;
@@ -798,6 +799,15 @@
             -moz-box-shadow: 6px 8px 13px 2px rgba(191,191,191,0.13);
         }
 
+        #quickAccessPanel .mxmenu{
+            border-right: 1px solid var(--divider);
+            padding-right: 0;
+        }
+
+        #quickAccessPanel .viewutils{
+            padding-right: 2em !important;
+        }
+
         #quickAccessPanel .item{
             padding-left:12px;
             padding-right:12px;
@@ -805,13 +815,16 @@
             padding-bottom:4px;
             cursor:pointer;
             border-left: 3px solid transparent;
-            
         }
 
         #quickAccessPanel .item{
             color: var(--text_color);
         }
 
+        #quickAccessPanel #quickseach{
+            padding-top: 0.4em;
+        }
+
         #quickAccessPanel .item:hover{
            background-color:var(--body_background_active);
         }
@@ -844,7 +857,7 @@
            background-color: var(--body_background_active);
         }
 
-        #quickAccessPanel .progress .bar{
+        #quickAccessPanel .progress .bar :not(#diskrender){
             background-color: var(--theme_color) !important;
         }
 
@@ -1240,65 +1253,78 @@
 
     <!-- Content / Quick Access Panel-->
     <div id="quickAccessPanel" class="" style="display:none;">
-        <div class="ui small items" style="margin-bottom: 0;">
-            <div class="item">
-                <div class="ui mini image">
-                    <img class="usericon" src="img/desktop/system_icon/user.svg">
+        <div class="ui grid">
+            <div class="seven wide column mxmenu">
+                <div class="ui small items" style="margin-bottom: 0;">
+                    <div class="item">
+                        <div class="ui mini image">
+                            <img class="usericon" src="img/desktop/system_icon/user.svg">
+                        </div>
+                        <div class="content" style="padding-left: 1em;">
+                            <div id="username" class="header" style="font-weight: 600; font-size: 1.22em;">User</div>
+                            <div class="meta" style="margin-top: 0.15em;">
+                                <div id="usergroups">@Users</div>
+                            </div>
+                        </div>
+                        <div class="actions">
+                            <div class="ui small button" onclick="logout(); hideToolPanel();">
+                                <i class="log out icon"></i> <span locale="quickAccess/logout">Logout</span>
+                            </div>
+                        </div>
+                    </div>
+                    <div class="ui divider"  style="margin-left: 0.4em; margin-right: 0.4em;"></div>
+                    <div id="alternativeAccountList">
+                    
+                    </div>
+                    <div class="ui divider" style="margin-left: 3em; margin-right: 3em;"></div>
+                    <div class="item" style="padding-top: 6px; padding-bottom:6px; margin: 0px !important;" onclick="openSwitchAccountPanel(); hideToolPanel();">
+                        <i class="ui user plus icon" style="margin-right: 0.6em;"></i> <span locale="account/switch/addAccount">Add another account</span>
+                    </div>
+                    <div id="signoutAllButton" style="padding-top: 6px; padding-bottom:6px; margin: 0px !important;" class="item" onclick="logoutAllAccounts();">
+                        <i class="log out icon icon" style="margin-right: 0.6em;"></i> <span locale="account/switch/signoutAll">Sign-out all accounts</span>
+                    </div>
                 </div>
-                <div class="content" style="padding-left: 1em;">
-                    <div id="username" class="header" style="font-weight: 600; font-size: 1.22em;">User</div>
-                    <div class="meta" style="margin-top: 0.15em;">
-                        <div id="usergroups">@Users</div>
+                <div class="ui divider" style="margin-left: 0.4em; margin-right: 0.4em;"></div>
+                <div class="item" style="padding-bottom:12px;">
+                    <i class="volume up icon"></i> <span locale="quickAccess/sysvol">System Global Volume</span>
+                    <div class="ui fluid small progress" style="margin-top:8px; margin-bottom:8px; cursor:pointer;" onclick="updateVolume(this,event);" >
+                        <div id="volumebar" class="bar" style="width: 0%; min-width: 0px; background-color:#52C9FF;  cursor:pointer;"></div>
                     </div>
                 </div>
-                <div class="actions">
-                    <div class="ui small button" onclick="logout(); hideToolPanel();">
-                        <i class="log out icon"></i> <span locale="quickAccess/logout">Logout</span>
+                <div class="item" style="padding-bottom:12px;">
+                    <i class="lightbulb icon"></i> <span locale="quickAccess/brightness">Brightness</span>
+                    <div class="ui fluid small progress" style="margin-top:8px; margin-bottom:8px; cursor:pointer;" onclick="updateBrightness(this,event);" >
+                        <div id="brightnessbar" class="bar" style="width: 100%; min-width: 0px; background-color:#52C9FF;  cursor:pointer;"></div>
                     </div>
                 </div>
+                <div class="item" id="settingButton" onclick="showSystemSettings(); hideToolPanel();" ontouchend="showSystemSettings(); hideToolPanel();">
+                    <i class="setting icon"></i> <span locale="quickAccess/settings">System Settings</span>
+                    <!-- <div style="float:right;"><i class="caret right icon"></i></div> -->
+                </div>
+                <div class="item" onclick="fullscreen(); hideToolPanel();" ontouchend="fullscreen(); hideToolPanel();">
+                    <i class="expand icon"></i> <span locale="quickAccess/fullscreen">Toggle Fullscreen</span>
+                </div>
+                <div class="ui divider" style="margin: 0.4em;"></div>
+                <div class="item powerman" onclick="restart(); hideToolPanel();" ontouchend="restart(); hideToolPanel();">
+                    <i class="repeat icon"></i> <span locale="quickAccess/restart">Restart</span>
+                </div>
+                <div class="item powerman" style="color:#b51d1d;"  onclick="shutdown(); hideToolPanel();" ontouchend="shutdown(); hideToolPanel();">
+                    <i class="power icon"></i> <span locale="quickAccess/poweroff">Power Off</span>
+                </div>
+                <div class="ui container" style="padding-left: 1em; color: rgb(199, 199, 199);">
+                    <small id="sysinfo"></small>
+                </div>
             </div>
-            <div class="ui divider"></div>
-            <div id="alternativeAccountList">
-               
-            </div>
-            <div class="ui divider" style="margin-left: 3em; margin-right: 3em;"></div>
-            <div class="item" style="padding-top: 6px; padding-bottom:6px; margin: 0px !important;" onclick="openSwitchAccountPanel(); hideToolPanel();">
-                <i class="ui user plus icon" style="margin-right: 0.6em;"></i> <span locale="account/switch/addAccount">Add another account</span>
-            </div>
-            <div id="signoutAllButton" style="padding-top: 6px; padding-bottom:6px; margin: 0px !important;" class="item" onclick="logoutAllAccounts();">
-                <i class="log out icon icon" style="margin-right: 0.6em;"></i> <span locale="account/switch/signoutAll">Sign-out all accounts</span>
-            </div>
-            <div class="ui divider"></div>
-        </div>
-        <div class="item" style="padding-bottom:12px;">
-            <i class="volume up icon"></i> <span locale="quickAccess/sysvol">System Global Volume</span>
-            <div class="ui fluid small progress" style="margin-top:8px; margin-bottom:8px; cursor:pointer;" onclick="updateVolume(this,event);" >
-                <div id="volumebar" class="bar" style="width: 0%; min-width: 0px; background-color:#52C9FF;  cursor:pointer;"></div>
-            </div>
-        </div>
-        <div class="item" style="padding-bottom:12px;">
-            <i class="lightbulb icon"></i> <span locale="quickAccess/brightness">Brightness</span>
-            <div class="ui fluid small progress" style="margin-top:8px; margin-bottom:8px; cursor:pointer;" onclick="updateBrightness(this,event);" >
-                <div id="brightnessbar" class="bar" style="width: 100%; min-width: 0px; background-color:#52C9FF;  cursor:pointer;"></div>
+            <div class="nine wide column viewutils">
+                <div id="sysoverview">
+                    
+                </div>
+                <div class="ui divider"></div>
+                <div id="diskoverview">
+
+                </div>
             </div>
         </div>
-        <div class="item" id="settingButton" onclick="showSystemSettings(); hideToolPanel();" ontouchend="showSystemSettings(); hideToolPanel();">
-            <i class="setting icon"></i> <span locale="quickAccess/settings">System Settings</span>
-            <!-- <div style="float:right;"><i class="caret right icon"></i></div> -->
-        </div>
-        <div class="item" onclick="fullscreen(); hideToolPanel();" ontouchend="fullscreen(); hideToolPanel();">
-            <i class="expand icon"></i> <span locale="quickAccess/fullscreen">Toggle Fullscreen</span>
-        </div>
-        <div class="ui divider" style="margin: 0.4em;"></div>
-        <div class="item powerman" onclick="restart(); hideToolPanel();" ontouchend="restart(); hideToolPanel();">
-            <i class="repeat icon"></i> <span locale="quickAccess/restart">Restart</span>
-        </div>
-        <div class="item powerman" style="color:#b51d1d;"  onclick="shutdown(); hideToolPanel();" ontouchend="shutdown(); hideToolPanel();">
-            <i class="power icon"></i> <span locale="quickAccess/poweroff">Power Off</span>
-        </div>
-        <div class="ui container" style="padding-left: 1em; color: rgb(199, 199, 199);">
-            <small id="sysinfo"></small>
-        </div>
     </div>
     <div>
         <canvas id="textWidthCanvas" style="display:none;"></canvas>
@@ -1405,6 +1431,7 @@
             initDesktop();
         }
 
+
         function initDesktop(){
             //Initiation functions
             initDesktopTheme();
@@ -1421,6 +1448,7 @@
             initTheme();
             initStartupSounds();
             initUploadCuttoffValues();
+            initFrameLoading();
 
             //Login cookie expire check
             setInterval(function() {
@@ -1431,6 +1459,12 @@
             $(".dropdown").dropdown();
         }
 
+        function initFrameLoading(){
+            //Load desktop utilities into suitable positions
+            $("#diskoverview").load("SystemAO/desktop/utils/diskoverview.html");
+            $("#sysoverview").load("SystemAO/desktop/utils/sysoverview.html");
+        }
+
         function initUploadCuttoffValues(){
              //Get the avaible space on tmp disk and decide the cutoff file size that need to directly write to disk
             $.ajax({