@copylee/dsh-computer-use 0.8.5 → 0.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/helper/CuHelper.cs +37 -2
  2. package/package.json +1 -1
@@ -1077,6 +1077,7 @@ namespace DshComputerUse
1077
1077
  public static Bitmap Capture(Rectangle area, IntPtr exclude)
1078
1078
  {
1079
1079
  if (!Ready()) return null;
1080
+ Bitmap result = null;
1080
1081
  try
1081
1082
  {
1082
1083
  // The never-shown host must be as large as the capture, or the control is clipped.
@@ -1086,7 +1087,7 @@ namespace DshComputerUse
1086
1087
  frame = null;
1087
1088
  var rc = new Native.RECT { Left = area.Left, Top = area.Top, Right = area.Right, Bottom = area.Bottom };
1088
1089
  if (!MagSetWindowSource(magnifier, rc)) { broken = true; Why = "source"; return null; }
1089
- var result = frame;
1090
+ result = frame;
1090
1091
  frame = null;
1091
1092
  if (result == null || result.Width != area.Width || result.Height != area.Height)
1092
1093
  {
@@ -1095,9 +1096,43 @@ namespace DshComputerUse
1095
1096
  broken = true;
1096
1097
  return null;
1097
1098
  }
1099
+ if (!HasVisiblePixels(result))
1100
+ {
1101
+ result.Dispose();
1102
+ broken = true;
1103
+ Why = "black magnifier frame";
1104
+ Console.Error.WriteLine("Magnification capture returned a black frame; using BitBlt for the rest of this helper process.");
1105
+ return null;
1106
+ }
1098
1107
  return result;
1099
1108
  }
1100
- catch (Exception e) { broken = true; Why = "capture: " + e.Message; return null; }
1109
+ catch (Exception e)
1110
+ {
1111
+ if (result != null) result.Dispose();
1112
+ broken = true;
1113
+ Why = "capture: " + e.Message;
1114
+ return null;
1115
+ }
1116
+ }
1117
+
1118
+ internal static bool HasVisiblePixels(Bitmap bitmap)
1119
+ {
1120
+ var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb);
1121
+ try
1122
+ {
1123
+ var row = new byte[bitmap.Width * 4];
1124
+ for (int y = 0; y < bitmap.Height; y++)
1125
+ {
1126
+ Marshal.Copy(IntPtr.Add(data.Scan0, y * data.Stride), row, 0, row.Length);
1127
+ for (int x = 0; x < row.Length; x += 4)
1128
+ {
1129
+ // Ignore the padding byte and allow black-level noise.
1130
+ if (row[x] > 3 || row[x + 1] > 3 || row[x + 2] > 3) return true;
1131
+ }
1132
+ }
1133
+ return false;
1134
+ }
1135
+ finally { bitmap.UnlockBits(data); }
1101
1136
  }
1102
1137
 
1103
1138
  static bool OnImage(IntPtr hwnd, IntPtr srcdata, MAGIMAGEHEADER h, IntPtr destdata, MAGIMAGEHEADER dh, Native.RECT unclipped, Native.RECT clipped, IntPtr dirty)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.8.5",
3
+ "version": "0.8.6",
4
4
  "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
5
5
  "type": "module",
6
6
  "author": "copylee",