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:
@@ -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=<reason> 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
|
||||
|
||||
+3
-3
@@ -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",
|
||||
|
||||
@@ -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