pencil-team 0.2.0 → 0.2.1

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/index.js +38 -25
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -9276,7 +9276,6 @@ class PenSync {
9276
9276
  }
9277
9277
  loadLocalFile() {
9278
9278
  if (!fs3.existsSync(this.options.filePath)) {
9279
- fs3.writeFileSync(this.options.filePath, "{}");
9280
9279
  return;
9281
9280
  }
9282
9281
  try {
@@ -9444,14 +9443,16 @@ class PenSync {
9444
9443
  // src/platform/opener.ts
9445
9444
  import { execSync, spawn } from "child_process";
9446
9445
  import path3 from "path";
9446
+ var pencilPid = null;
9447
9447
  async function openWithPencil(filePath) {
9448
9448
  const absPath = path3.resolve(filePath);
9449
+ const pidsBefore = getPencilPids();
9449
9450
  switch (process.platform) {
9450
9451
  case "darwin":
9451
9452
  try {
9452
- spawn("open", ["-a", "Pencil", absPath], { stdio: "ignore", detached: true }).unref();
9453
+ execSync(`open -a "Pencil" "${absPath}"`, { stdio: "ignore" });
9453
9454
  } catch {
9454
- spawn("open", [absPath], { stdio: "ignore", detached: true }).unref();
9455
+ execSync(`open "${absPath}"`, { stdio: "ignore" });
9455
9456
  }
9456
9457
  break;
9457
9458
  case "linux":
@@ -9463,36 +9464,45 @@ async function openWithPencil(filePath) {
9463
9464
  default:
9464
9465
  throw new Error(`Unsupported platform: ${process.platform}`);
9465
9466
  }
9467
+ await new Promise((r) => setTimeout(r, 2000));
9468
+ const pidsAfter = getPencilPids();
9469
+ const newPids = pidsAfter.filter((p) => !pidsBefore.includes(p));
9470
+ if (newPids.length > 0) {
9471
+ pencilPid = newPids[0];
9472
+ }
9466
9473
  }
9467
- function closePencil(filePath) {
9468
- const fileName = path3.basename(path3.resolve(filePath));
9474
+ function getPencilPids() {
9469
9475
  try {
9470
9476
  switch (process.platform) {
9471
- case "darwin": {
9472
- const script = `
9473
- tell application "System Events"
9474
- if exists (process "Pencil") then
9475
- tell process "Pencil"
9476
- repeat with w in windows
9477
- if name of w contains "${fileName}" then
9478
- click button 1 of w
9479
- end if
9480
- end repeat
9481
- end tell
9482
- end if
9483
- end tell
9484
- `;
9485
- execSync(`osascript -e '${script.replace(/'/g, "'\\''")}'`, { stdio: "ignore", timeout: 5000 });
9486
- break;
9477
+ case "darwin":
9478
+ case "linux": {
9479
+ const out = execSync("pgrep -fi pencil 2>/dev/null || true", { encoding: "utf-8" });
9480
+ return out.trim().split(`
9481
+ `).filter(Boolean).map(Number).filter((n) => !isNaN(n));
9482
+ }
9483
+ case "win32": {
9484
+ const out = execSync('tasklist /FI "IMAGENAME eq Pencil.exe" /FO CSV /NH 2>nul || echo ""', { encoding: "utf-8" });
9485
+ return [...out.matchAll(/"Pencil\.exe","(\d+)"/g)].map((m) => Number(m[1]));
9487
9486
  }
9487
+ }
9488
+ } catch {}
9489
+ return [];
9490
+ }
9491
+ function closePencil() {
9492
+ if (!pencilPid)
9493
+ return;
9494
+ try {
9495
+ switch (process.platform) {
9496
+ case "darwin":
9488
9497
  case "linux":
9489
- execSync(`wmctrl -c "${fileName}"`, { stdio: "ignore", timeout: 5000 });
9498
+ process.kill(pencilPid, "SIGTERM");
9490
9499
  break;
9491
9500
  case "win32":
9492
- execSync(`powershell -Command "Get-Process | Where-Object {$_.MainWindowTitle -like '*${fileName}*'} | ForEach-Object {$_.CloseMainWindow()}"`, { stdio: "ignore", timeout: 5000 });
9501
+ execSync(`taskkill /PID ${pencilPid} /F`, { stdio: "ignore", timeout: 5000 });
9493
9502
  break;
9494
9503
  }
9495
9504
  } catch {}
9505
+ pencilPid = null;
9496
9506
  }
9497
9507
 
9498
9508
  // src/index.ts
@@ -9565,7 +9575,10 @@ program2.command("sync").description("Sync and open a .pen file from a room").ar
9565
9575
  }
9566
9576
  const filePath = getTempPenPath(room);
9567
9577
  if (!fs4.existsSync(filePath)) {
9568
- fs4.writeFileSync(filePath, "{}");
9578
+ fs4.writeFileSync(filePath, JSON.stringify({
9579
+ version: "1.0",
9580
+ children: []
9581
+ }, null, 2));
9569
9582
  }
9570
9583
  console.log(`Syncing room: ${room}`);
9571
9584
  console.log(`Local file: ${filePath}`);
@@ -9591,7 +9604,7 @@ program2.command("sync").description("Sync and open a .pen file from a room").ar
9591
9604
  Shutting down...`);
9592
9605
  sync.disconnect();
9593
9606
  console.log("Closing Pencil...");
9594
- closePencil(filePath);
9607
+ closePencil();
9595
9608
  try {
9596
9609
  if (fs4.existsSync(filePath)) {
9597
9610
  fs4.unlinkSync(filePath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pencil-team",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "pencil-team": "dist/index.js"