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.
This commit is contained in:
@@ -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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user