From 14624d78fef35a5959b4882ba60816a6cbfd0c6a Mon Sep 17 00:00:00 2001 From: Adrian Bonpin Date: Sun, 20 Sep 2026 21:17:14 +0800 Subject: [PATCH] Prevent display sleep by default `caffeinate -i` blocks system idle sleep but lets the display blank, so the screen still slept and the extension looked broken. The "Also Prevent Display Sleep" preference that fixes this defaulted to off. Flip it to on, and guard it with a manifest test that reads package.json and asserts the shipped defaults map to `-i -d`. Verified on macOS: `caffeinate -i` yields PreventUserIdleDisplaySleep 0, `caffeinate -i -d` yields 1. --- README.md | 4 +-- package.json | 6 ++--- src/__tests__/manifest.test.ts | 46 ++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 src/__tests__/manifest.test.ts diff --git a/README.md b/README.md index 83eedc5..1c5dd56 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Sleep prevention is an OS-level assertion, so the extension delegates to the pla | Platform | Mechanism | | --- | --- | -| macOS | `/usr/bin/caffeinate -i [-d] [-s]` | +| macOS | `/usr/bin/caffeinate -i [-d] [-s]` (defaults to `-i -d`) | | Linux | `systemd-inhibit --what=idle:sleep --why= sleep infinity` | Both run until signalled — there is no timer, so nothing needs to be refreshed or babysat. @@ -63,7 +63,7 @@ pkill -f vicinae-caffeinate | Preference | Default | Notes | | --- | --- | --- | -| Also Prevent Display Sleep | off | macOS only. `systemd-inhibit` cannot hold the display awake — that is the compositor's job, and the UI says so rather than pretending. | +| Prevent Display Sleep | **on** | macOS only. On by default: `caffeinate -i` alone blocks *system* idle sleep, so the screen still blanks and the extension looks broken. Turn it off to save battery. `systemd-inhibit` cannot hold the display awake — that is the compositor's job, and the UI says so rather than pretending. | | Also Prevent System Sleep | off | On macOS this assertion only takes effect while on AC power. | ## Development diff --git a/package.json b/package.json index 08955a8..f54db8f 100644 --- a/package.json +++ b/package.json @@ -26,12 +26,12 @@ "preferences": [ { "name": "preventDisplaySleep", - "title": "Also Prevent Display Sleep", - "description": "Keep the screen on as well. Off means the display may still turn off while the system stays awake.", + "title": "Prevent Display Sleep", + "description": "Keep the screen on. On by default, because a blank screen is the usual reason caffeination looks like it is not working. Turn it off to let the display sleep while the system stays awake (saves battery).", "type": "checkbox", "label": "Prevent display sleep", "required": false, - "default": false + "default": true }, { "name": "preventSystemSleep", diff --git a/src/__tests__/manifest.test.ts b/src/__tests__/manifest.test.ts new file mode 100644 index 0000000..4f4b656 --- /dev/null +++ b/src/__tests__/manifest.test.ts @@ -0,0 +1,46 @@ +import { readFileSync } from "node:fs"; +import { join } from "node:path"; + +import { describe, expect, it } from "vitest"; + +import { flagsFromOptions } from "../lib/platform"; +import { CaffeinateOptions } from "../lib/types"; + +interface Preference { + name: string; + default?: unknown; +} + +const manifest = JSON.parse(readFileSync(join(process.cwd(), "package.json"), "utf8")) as { + preferences: Preference[]; +}; + +function preferenceDefault(name: string): unknown { + return manifest.preferences.find((preference) => preference.name === name)?.default; +} + +/** + * `caffeinate -i` blocks *system* idle sleep but lets the display blank, which + * is the #1 way this extension looks broken: the screen sleeps, so the user + * concludes the toggle did nothing. Display sleep prevention must stay on by + * default; opting out is a deliberate battery-saving choice. + */ +describe("manifest defaults", () => { + it("prevents display sleep by default", () => { + expect(preferenceDefault("preventDisplaySleep")).toBe(true); + }); + + it("leaves full system sleep opt-in", () => { + expect(preferenceDefault("preventSystemSleep")).toBe(false); + }); + + it("maps the shipped defaults onto flags that keep the screen awake", () => { + const defaults: CaffeinateOptions = { + preventDisplaySleep: preferenceDefault("preventDisplaySleep") as boolean, + preventSystemSleep: preferenceDefault("preventSystemSleep") as boolean, + }; + + // "id" == -i -d: idle sleep AND display sleep both blocked. + expect(flagsFromOptions(defaults)).toBe("id"); + }); +});