pencil-team 0.2.0 → 0.2.2
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.
- package/dist/index.js +39 -31
- 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
|
-
|
|
9453
|
+
execSync(`open -a "Pencil" "${absPath}"`, { stdio: "ignore" });
|
|
9453
9454
|
} catch {
|
|
9454
|
-
|
|
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
|
|
9468
|
-
const fileName = path3.basename(path3.resolve(filePath));
|
|
9474
|
+
function getPencilPids() {
|
|
9469
9475
|
try {
|
|
9470
9476
|
switch (process.platform) {
|
|
9471
|
-
case "darwin":
|
|
9472
|
-
|
|
9473
|
-
|
|
9474
|
-
|
|
9475
|
-
|
|
9476
|
-
|
|
9477
|
-
|
|
9478
|
-
|
|
9479
|
-
|
|
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
|
-
|
|
9498
|
+
process.kill(pencilPid, "SIGTERM");
|
|
9490
9499
|
break;
|
|
9491
9500
|
case "win32":
|
|
9492
|
-
execSync(`
|
|
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,13 +9604,8 @@ 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(
|
|
9595
|
-
|
|
9596
|
-
if (fs4.existsSync(filePath)) {
|
|
9597
|
-
fs4.unlinkSync(filePath);
|
|
9598
|
-
console.log("Cleaned up temp file.");
|
|
9599
|
-
}
|
|
9600
|
-
} catch {}
|
|
9607
|
+
closePencil();
|
|
9608
|
+
console.log(`File saved: ${filePath}`);
|
|
9601
9609
|
process.exit(0);
|
|
9602
9610
|
};
|
|
9603
9611
|
process.on("SIGINT", shutdown);
|