@opencrater/sdk 0.8.53 → 0.8.55
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.
Potentially problematic release.
This version of @opencrater/sdk might be problematic. Click here for more details.
- package/dist/hook.js +24 -0
- package/dist/paint.js +7 -6
- package/package.json +1 -1
package/dist/hook.js
CHANGED
|
@@ -778,6 +778,25 @@ async function renderPlain(card, state, media, impressionId, campaignId) {
|
|
|
778
778
|
}
|
|
779
779
|
return { ...state, lastShownAt: Date.now(), disclosureShown: true };
|
|
780
780
|
}
|
|
781
|
+
function windowsCardShowing(displayMs) {
|
|
782
|
+
if (process.platform !== "win32") return false;
|
|
783
|
+
try {
|
|
784
|
+
const lockPath = path3__namespace.join(os2__namespace.homedir(), ".config", "opencrater", "painter.lock");
|
|
785
|
+
const lock = JSON.parse(fs3__namespace.readFileSync(lockPath, "utf8"));
|
|
786
|
+
if (typeof lock.startedAt !== "number") return false;
|
|
787
|
+
if (Date.now() - lock.startedAt > displayMs + 1500) return false;
|
|
788
|
+
if (typeof lock.pid === "number") {
|
|
789
|
+
try {
|
|
790
|
+
process.kill(lock.pid, 0);
|
|
791
|
+
} catch (err) {
|
|
792
|
+
if (err.code === "ESRCH") return false;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
return true;
|
|
796
|
+
} catch {
|
|
797
|
+
return false;
|
|
798
|
+
}
|
|
799
|
+
}
|
|
781
800
|
var RENDER_SLOT_TTL_MS = 8e3;
|
|
782
801
|
function claimRenderSlot() {
|
|
783
802
|
const slot = path3__namespace.join(os2__namespace.homedir(), ".config", "opencrater", "render.lock");
|
|
@@ -902,6 +921,11 @@ async function main() {
|
|
|
902
921
|
debug("hook: pooled ad skipped \u2014 campaign inside a local cooldown");
|
|
903
922
|
({ ad: pooled, pool } = takeFromPool({ pool }, Date.now()));
|
|
904
923
|
}
|
|
924
|
+
if ((pooled || args.key) && windowsCardShowing((config.displayDurationSeconds ?? 25) * 1e3)) {
|
|
925
|
+
writeState(state);
|
|
926
|
+
debug("hook: a card is already on screen \u2014 not rendering another");
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
905
929
|
if (pooled || args.key) {
|
|
906
930
|
if (!claimRenderSlot()) {
|
|
907
931
|
writeState(state);
|
package/dist/paint.js
CHANGED
|
@@ -1124,6 +1124,7 @@ function main() {
|
|
|
1124
1124
|
let dismissServer = null;
|
|
1125
1125
|
let dismissServerUrl = null;
|
|
1126
1126
|
const cleanup = (wipe) => {
|
|
1127
|
+
pdebug("cleanup wipe=" + wipe + " elapsed=" + (Date.now() - painterStartedAt) + "ms");
|
|
1127
1128
|
if (interval) clearInterval(interval);
|
|
1128
1129
|
if (dismissPoll) clearInterval(dismissPoll);
|
|
1129
1130
|
if (activityWatch) clearInterval(activityWatch);
|
|
@@ -1473,7 +1474,7 @@ function main() {
|
|
|
1473
1474
|
paint();
|
|
1474
1475
|
interval = setInterval(paint, animated ? ANIM_MS : REPAINT_MS);
|
|
1475
1476
|
startActivityWatch();
|
|
1476
|
-
setTimeout(() => cleanup(), duration2);
|
|
1477
|
+
setTimeout(() => cleanup(true), duration2);
|
|
1477
1478
|
return;
|
|
1478
1479
|
}
|
|
1479
1480
|
const ownerPid = real?.pid ?? 0;
|
|
@@ -1628,11 +1629,11 @@ function main() {
|
|
|
1628
1629
|
if (payload.audioUrl && format !== "audio") void upgradeAudio(payload.audioUrl);
|
|
1629
1630
|
const duration = payload.durationMs ?? (format === "video" ? 18e3 : format === "audio" ? 16e3 : DEFAULT_DURATION_MS);
|
|
1630
1631
|
deadlineAt = Date.now() + duration;
|
|
1631
|
-
setTimeout(() => cleanup(), duration);
|
|
1632
|
-
process.on("SIGTERM", () => cleanup());
|
|
1633
|
-
process.on("SIGINT", () => cleanup());
|
|
1634
|
-
process.on("SIGHUP", () => cleanup());
|
|
1635
|
-
setTimeout(() => cleanup(), duration + 5e3).unref?.();
|
|
1632
|
+
setTimeout(() => cleanup(true), duration);
|
|
1633
|
+
process.on("SIGTERM", () => cleanup(true));
|
|
1634
|
+
process.on("SIGINT", () => cleanup(true));
|
|
1635
|
+
process.on("SIGHUP", () => cleanup(true));
|
|
1636
|
+
setTimeout(() => cleanup(true), duration + 5e3).unref?.();
|
|
1636
1637
|
}
|
|
1637
1638
|
if (typeof __require !== "undefined" && typeof module !== "undefined" && __require.main === module) {
|
|
1638
1639
|
main();
|