ia_rewrite_ntapp 1.0.6 → 1.0.7

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/index.js +14 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -39,7 +39,7 @@ function runVbsSendKeys(keys) {
39
39
  }
40
40
 
41
41
  function readClipboardFallback() {
42
- const output = execSync("powershell -NoProfile -Command Get-Clipboard", { encoding: "utf8" });
42
+ const output = execSync("powershell -NoProfile -Command Get-Clipboard -Raw", { encoding: "utf8" });
43
43
  return String(output);
44
44
  }
45
45
 
@@ -51,6 +51,17 @@ async function readClipboard() {
51
51
  }
52
52
  }
53
53
 
54
+ async function readClipboardWithRetry(previousValue, maxWaitMs = 1500) {
55
+ const start = Date.now();
56
+ let current = await readClipboard();
57
+ while (Date.now() - start < maxWaitMs) {
58
+ if (current && current.trim() && current !== previousValue) return current;
59
+ await new Promise((r) => setTimeout(r, 100));
60
+ current = await readClipboard();
61
+ }
62
+ return current;
63
+ }
64
+
54
65
  function writeClipboardFallback(text) {
55
66
  const tmpPath = path.join(os.tmpdir(), `ia_rewrite_clip_${Date.now()}_${Math.random()}.txt`);
56
67
  fs.writeFileSync(tmpPath, String(text), "utf8");
@@ -112,7 +123,8 @@ async function main() {
112
123
  runVbsSendKeys("^c");
113
124
  await new Promise((r) => setTimeout(r, 150));
114
125
 
115
- const original = (await readClipboard()).trim();
126
+ const beforeCopy = await readClipboard();
127
+ const original = (await readClipboardWithRetry(beforeCopy)).trim();
116
128
  log(`Clipboard lido. Tamanho: ${original.length}`);
117
129
  if (!original) {
118
130
  notify("ia_rewrite_ntapp", "Clipboard vazio. Selecione um texto e tente novamente.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ia_rewrite_ntapp",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "CLI para reescrever texto selecionado via IA",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",