Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/browser/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
import { getVisibleWorkspaceIds } from "./utils/ui/workspaceDomNav";
import { useUnreadTracking } from "./hooks/useUnreadTracking";
import { useWorkspaceStoreRaw, useWorkspaceRecency } from "./stores/WorkspaceStore";
import { getAppConfigStore } from "./stores/AppConfigStore";
import {
getResponseCompleteNotificationBody,
shouldNotifyOnResponseComplete,
Expand Down Expand Up @@ -1030,6 +1031,9 @@ function AppInner() {
onToggleReasoningMode: toggleReasoningModeFromPalette,
getFastMode: getFastModeActive,
onToggleFastMode: toggleFastMode,
// Read when the palette opens, from the shared cache (one fetch + one config subscription
// per session), so showing the state costs no IPC call (#5791).
getKeepScreenAwake: () => getAppConfigStore().getSnapshot()?.keepScreenAwake,
computerUse: computerUseAvailable
? { enabled: computerUse.enabledHere, onToggle: computerUse.toggle }
: null,
Expand Down
3 changes: 3 additions & 0 deletions src/browser/stores/AppConfigStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export interface AppConfigSnapshot {
bashCollapsedSummaryMode?: BashCollapsedSummaryMode;
transcriptDensity?: TranscriptDensity;
agentAiDefaults?: AgentAiDefaults;
/** Read by the command palette to show the toggle's current state (#5791). */
keepScreenAwake?: boolean;
}

/**
Expand Down Expand Up @@ -96,6 +98,7 @@ export class AppConfigStore {
bashCollapsedSummaryMode: config.userPreferences?.appearance?.bashCollapsedSummaryMode,
transcriptDensity: config.userPreferences?.appearance?.transcriptDensity,
agentAiDefaults: config.agentAiDefaults,
keepScreenAwake: config.keepScreenAwake === true,
};
this.notify();
}
Expand Down
19 changes: 19 additions & 0 deletions src/browser/utils/commands/sources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,25 @@ test("toggle keep screen awake command is only offered in the desktop app", () =
}
});

// #5791: config-backed toggles showed no current state, unlike the local-state toggles.
test("toggle keep screen awake shows the loaded config value", () => {
const originalWindow = globalThis.window;
globalThis.window = new GlobalWindow() as unknown as Window & typeof globalThis;
globalThis.window.api = { platform: "linux", versions: {} };
const subtitleWith = (value: boolean | undefined) =>
getActions({ getKeepScreenAwake: () => value }).find(
(a) => a.id === "settings:toggle-keep-screen-awake"
)?.subtitle;
try {
expect(subtitleWith(true)).toBe("Current: On");
expect(subtitleWith(false)).toBe("Current: Off");
// Config not loaded yet: say what the toggle does, never guess a state.
expect(subtitleWith(undefined)).toBe("Prevent display sleep while agents are working");
} finally {
globalThis.window = originalWindow;
}
});

test("toggle keep screen awake command inverts the persisted config flag", async () => {
const originalWindow = globalThis.window;
globalThis.window = new GlobalWindow() as unknown as Window & typeof globalThis;
Expand Down
15 changes: 14 additions & 1 deletion src/browser/utils/commands/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ export interface BuildSourcesParams {
) => void;
getFastMode: () => boolean;
onToggleFastMode: () => void | Promise<void>;
/** config.json keepScreenAwake from the shared app config cache; undefined until it loads. */
getKeepScreenAwake?: () => boolean | undefined;
/** Native host computer use for the selected workspace; null when unsupported or no workspace. */
computerUse?: { enabled: boolean; onToggle: () => void | Promise<void> } | null;
/** auto-model-routing experiment: gates the composer's Auto toggles in the palette. */
Expand Down Expand Up @@ -393,6 +395,12 @@ function openGoalPanel(workspaceId: string, openCompleteInput = false): void {
createCustomEvent(CUSTOM_EVENTS.OPEN_GOAL_TAB, { workspaceId, openCompleteInput })
);
}

/** Subtitle for an On/Off toggle backed by config.json; `fallback` until the value is known. */
function describeConfigToggle(value: boolean | undefined, fallback: string): string {
return value === undefined ? fallback : `Current: ${value ? "On" : "Off"}`;
}

export function buildCoreSources(p: BuildSourcesParams): Array<() => CommandAction[]> {
const actions: Array<() => CommandAction[]> = [];

Expand Down Expand Up @@ -2030,7 +2038,12 @@ export function buildCoreSources(p: BuildSourcesParams): Array<() => CommandActi
{
id: CommandIds.settingsToggleKeepScreenAwake(),
title: "Toggle Keep Screen Awake",
subtitle: "Prevent display sleep while agents are working",
// Show the current state like the local-state toggles do (#5791). Until the config
// has loaded, describe the toggle instead of guessing a state.
subtitle: describeConfigToggle(
p.getKeepScreenAwake?.(),
"Prevent display sleep while agents are working"
),
section: section.settings,
keywords: ["awake", "sleep", "screen", "display", "lock", "power", "caffeinate"],
run: async () => {
Expand Down
Loading