NewLife/Stardust

采集Linux桌面系统的分辨率,但是服务后台运行时采集失败
大石头 编写于 2024-05-05 18:58:30
共计: 修改1个文件,增加17行、删除1行。
修改 +17 -1
修改 +17 -1
diff --git a/Stardust/StarClient.cs b/Stardust/StarClient.cs
index fbb852d..3a9fbf1 100644
--- a/Stardust/StarClient.cs
+++ b/Stardust/StarClient.cs
@@ -290,7 +290,7 @@ public class StarClient : ApiHttpClient, ICommandClient, IEventProvider
         if (Runtime.Windows) FixGdi(di);
 #endif
 
-        if (Runtime.Linux) di.MaxOpenFiles = Execute("bash", "-c \"ulimit -n\"")?.Trim().ToInt() ?? 0;
+        if (Runtime.Linux) FixOnLinux(di);
 
         return di;
     }
@@ -323,6 +323,22 @@ public class StarClient : ApiHttpClient, ICommandClient, IEventProvider
     }
 #endif
 
+    private static void FixOnLinux(NodeInfo di)
+    {
+        di.MaxOpenFiles = Execute("bash", "-c \"ulimit -n\"")?.Trim().ToInt() ?? 0;
+
+        var xrandr = Execute("xrandr", "-q");
+        if (!xrandr.IsNullOrEmpty())
+        {
+            var current = xrandr.Substring("current", ",").Trim();
+            if (!current.IsNullOrEmpty())
+            {
+                var ss = current.SplitAsInt("x");
+                if (ss.Length >= 2) di.Resolution = $"{ss[0]}*{ss[1]}";
+            }
+        }
+    }
+
     /// <summary>获取驱动器信息</summary>
     /// <returns></returns>
     public static IList<DriveInfo> GetDrives()