clipshot 1.0.16 → 1.0.17

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/dist/monitor.js +31 -7
  2. package/package.json +1 -1
package/dist/monitor.js CHANGED
@@ -89,32 +89,56 @@ function log(message) {
89
89
  }
90
90
  }
91
91
  async function getClipboardImageWindows() {
92
+ const tempFileName = `clipshot-clipboard-${Date.now()}.png`;
93
+ let tempFilePath = null;
92
94
  try {
93
- // PowerShell script to get clipboard image as base64
95
+ // PowerShell script to get clipboard image and save directly to temp file
96
+ // This avoids base64 encoding and stdout buffer limits for large images
94
97
  const psScript = `
95
98
  Add-Type -AssemblyName System.Windows.Forms
96
99
  $img = [System.Windows.Forms.Clipboard]::GetImage()
97
100
  if ($img -ne $null) {
98
- $ms = New-Object System.IO.MemoryStream
99
- $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png)
100
- [Convert]::ToBase64String($ms.ToArray())
101
+ $tempPath = Join-Path $env:TEMP '${tempFileName}'
102
+ $img.Save($tempPath, [System.Drawing.Imaging.ImageFormat]::Png)
103
+ Write-Output $tempPath
101
104
  }
102
105
  `;
103
106
  // Encode as UTF-16LE base64 for -EncodedCommand
104
107
  const encoded = Buffer.from(psScript, "utf16le").toString("base64");
105
108
  // Use powershell.exe for WSL, powershell for native Windows
106
109
  const psCmd = isWindows ? "powershell" : "powershell.exe";
107
- const result = (0, child_process_1.execSync)(`${psCmd} -NoProfile -WindowStyle Hidden -EncodedCommand ${encoded}`, {
110
+ const windowsPath = (0, child_process_1.execSync)(`${psCmd} -NoProfile -WindowStyle Hidden -EncodedCommand ${encoded}`, {
108
111
  encoding: "utf8",
109
112
  timeout: 5000,
110
113
  windowsHide: true,
111
114
  }).trim();
112
- if (result && result.length > 0) {
113
- return Buffer.from(result, "base64");
115
+ if (!windowsPath || windowsPath.length === 0) {
116
+ return null;
117
+ }
118
+ // Convert path for WSL if needed
119
+ if (isWindows) {
120
+ tempFilePath = windowsPath;
121
+ }
122
+ else {
123
+ tempFilePath = (0, child_process_1.execSync)(`wslpath '${windowsPath}'`, { encoding: "utf8", timeout: 2000 }).trim();
124
+ }
125
+ if (fs.existsSync(tempFilePath)) {
126
+ const imageBuffer = fs.readFileSync(tempFilePath);
127
+ fs.unlinkSync(tempFilePath);
128
+ return imageBuffer;
114
129
  }
115
130
  return null;
116
131
  }
117
132
  catch {
133
+ // Try to clean up temp file if it was created
134
+ if (tempFilePath) {
135
+ try {
136
+ fs.unlinkSync(tempFilePath);
137
+ }
138
+ catch {
139
+ // Ignore cleanup errors
140
+ }
141
+ }
118
142
  return null;
119
143
  }
120
144
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clipshot",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "Screenshot monitor CLI tool",
5
5
  "main": "dist/index.js",
6
6
  "bin": {