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"); + }); +});