@pulso/companion 0.2.3 → 0.2.4
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 +89 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -681,9 +681,23 @@ async function handleCommand(command, params) {
|
|
|
681
681
|
const ts = Date.now();
|
|
682
682
|
const pngPath = `/tmp/pulso-ss-${ts}.png`;
|
|
683
683
|
const jpgPath = `/tmp/pulso-ss-${ts}.jpg`;
|
|
684
|
-
|
|
684
|
+
try {
|
|
685
|
+
await runShell(`screencapture -x ${pngPath}`, 15e3);
|
|
686
|
+
} catch (ssErr) {
|
|
687
|
+
const msg = ssErr.message || "";
|
|
688
|
+
if (msg.includes("could not create image") || msg.includes("display")) {
|
|
689
|
+
return {
|
|
690
|
+
success: false,
|
|
691
|
+
error: "Screen Recording permission required. Go to System Settings \u2192 Privacy & Security \u2192 Screen Recording \u2192 enable Terminal (or your terminal app)."
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
return { success: false, error: `Screenshot failed: ${msg}` };
|
|
695
|
+
}
|
|
685
696
|
if (!existsSync(pngPath))
|
|
686
|
-
return {
|
|
697
|
+
return {
|
|
698
|
+
success: false,
|
|
699
|
+
error: "Screenshot failed \u2014 Screen Recording permission may be needed. Go to System Settings \u2192 Privacy & Security \u2192 Screen Recording."
|
|
700
|
+
};
|
|
687
701
|
try {
|
|
688
702
|
await runShell(
|
|
689
703
|
`sips --resampleWidth 1280 --setProperty format jpeg --setProperty formatOptions 60 ${pngPath} --out ${jpgPath}`,
|
|
@@ -1259,9 +1273,11 @@ print("\\(x),\\(y)")`;
|
|
|
1259
1273
|
// ── Calendar ────────────────────────────────────────────
|
|
1260
1274
|
case "sys_calendar_list": {
|
|
1261
1275
|
const days = Number(params.days) || 7;
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1276
|
+
try {
|
|
1277
|
+
await runAppleScript(`tell application "Calendar" to launch`);
|
|
1278
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
1279
|
+
} catch {
|
|
1280
|
+
}
|
|
1265
1281
|
const script = `
|
|
1266
1282
|
set output to ""
|
|
1267
1283
|
tell application "Calendar"
|
|
@@ -1297,20 +1313,47 @@ print("\\(x),\\(y)")`;
|
|
|
1297
1313
|
const notes = params.notes || "";
|
|
1298
1314
|
if (!summary || !startStr)
|
|
1299
1315
|
return { success: false, error: "Missing summary or start time" };
|
|
1316
|
+
const parseDate = (iso) => {
|
|
1317
|
+
const d = new Date(iso);
|
|
1318
|
+
if (isNaN(d.getTime())) return null;
|
|
1319
|
+
return { y: d.getFullYear(), mo: d.getMonth() + 1, d: d.getDate(), h: d.getHours(), mi: d.getMinutes() };
|
|
1320
|
+
};
|
|
1321
|
+
const buildDateScript = (varName, iso) => {
|
|
1322
|
+
const p = parseDate(iso);
|
|
1323
|
+
if (!p) return "";
|
|
1324
|
+
return `set ${varName} to current date
|
|
1325
|
+
set year of ${varName} to ${p.y}
|
|
1326
|
+
set month of ${varName} to ${p.mo}
|
|
1327
|
+
set day of ${varName} to ${p.d}
|
|
1328
|
+
set hours of ${varName} to ${p.h}
|
|
1329
|
+
set minutes of ${varName} to ${p.mi}
|
|
1330
|
+
set seconds of ${varName} to 0`;
|
|
1331
|
+
};
|
|
1332
|
+
const startDateScript = buildDateScript("startD", startStr);
|
|
1333
|
+
if (!startDateScript)
|
|
1334
|
+
return { success: false, error: `Invalid start date: ${startStr}` };
|
|
1335
|
+
const endDateScript = endStr ? buildDateScript("endD", endStr) : "";
|
|
1300
1336
|
const calTarget = calendar ? `calendar "${calendar.replace(/"/g, '\\"')}"` : "default calendar";
|
|
1301
|
-
const
|
|
1302
|
-
|
|
1337
|
+
const notesPart = notes ? `
|
|
1338
|
+
set description of newEvent to "${notes.replace(/"/g, '\\"')}"` : "";
|
|
1339
|
+
const endPart = endDateScript ? `
|
|
1340
|
+
set end date of newEvent to endD` : "";
|
|
1341
|
+
try {
|
|
1342
|
+
await runAppleScript(`tell application "Calendar" to launch`);
|
|
1343
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
1344
|
+
} catch {
|
|
1345
|
+
}
|
|
1303
1346
|
await runAppleScript(`
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1347
|
+
${startDateScript}
|
|
1348
|
+
${endDateScript}
|
|
1349
|
+
tell application "Calendar"
|
|
1350
|
+
tell ${calTarget}
|
|
1351
|
+
set newEvent to make new event with properties {summary:"${summary.replace(/"/g, '\\"')}", start date:startD}${endPart}${notesPart}
|
|
1352
|
+
end tell
|
|
1353
|
+
end tell`);
|
|
1311
1354
|
return {
|
|
1312
1355
|
success: true,
|
|
1313
|
-
data: { created: summary, start: startStr, end: endStr || "
|
|
1356
|
+
data: { created: summary, start: startStr, end: endStr || "1 hour" }
|
|
1314
1357
|
};
|
|
1315
1358
|
}
|
|
1316
1359
|
// ── Reminders ───────────────────────────────────────────
|
|
@@ -1359,16 +1402,39 @@ print("\\(x),\\(y)")`;
|
|
|
1359
1402
|
case "sys_reminder_create": {
|
|
1360
1403
|
const reminderName = params.name;
|
|
1361
1404
|
const dueDate = params.due;
|
|
1362
|
-
|
|
1405
|
+
let listName2 = params.list || "";
|
|
1363
1406
|
if (!reminderName)
|
|
1364
1407
|
return { success: false, error: "Missing reminder name" };
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1408
|
+
if (!listName2) {
|
|
1409
|
+
try {
|
|
1410
|
+
listName2 = (await runAppleScript(
|
|
1411
|
+
`tell application "Reminders" to return name of default list`
|
|
1412
|
+
)).trim();
|
|
1413
|
+
} catch {
|
|
1414
|
+
listName2 = "Reminders";
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
let duePart = "";
|
|
1418
|
+
if (dueDate) {
|
|
1419
|
+
const d = new Date(dueDate);
|
|
1420
|
+
if (!isNaN(d.getTime())) {
|
|
1421
|
+
duePart = `
|
|
1422
|
+
set dueD to current date
|
|
1423
|
+
set year of dueD to ${d.getFullYear()}
|
|
1424
|
+
set month of dueD to ${d.getMonth() + 1}
|
|
1425
|
+
set day of dueD to ${d.getDate()}
|
|
1426
|
+
set hours of dueD to ${d.getHours()}
|
|
1427
|
+
set minutes of dueD to ${d.getMinutes()}
|
|
1428
|
+
set seconds of dueD to 0`;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
const dueProperty = duePart ? `, due date:dueD` : "";
|
|
1432
|
+
await runAppleScript(`${duePart}
|
|
1433
|
+
tell application "Reminders"
|
|
1434
|
+
tell list "${listName2.replace(/"/g, '\\"')}"
|
|
1435
|
+
make new reminder with properties {name:"${reminderName.replace(/"/g, '\\"')}"${dueProperty}}
|
|
1436
|
+
end tell
|
|
1437
|
+
end tell`);
|
|
1372
1438
|
return {
|
|
1373
1439
|
success: true,
|
|
1374
1440
|
data: {
|