:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(desktop): add setting to toggle Mission Control overlay (#81183)
Adam Bowker5d85ddb103c8
diff --git a/products/desktop/apps/code/src/main/platform-adapters/electron-mission-control.test.ts b/products/desktop/apps/code/src/main/platform-adapters/electron-mission-control.test.tsindex 8db7b7606b67..5f043b517202 100644--- a/products/desktop/apps/code/src/main/platform-adapters/electron-mission-control.test.ts+++ b/products/desktop/apps/code/src/main/platform-adapters/electron-mission-control.test.ts@@ -23,6 +23,15 @@ vi.mock("../services/mission-control/cg-window-list", () => ({createWindowListSampler: sampler.create,}));+const settings = vi.hoisted(() => ({+ enabled: true,+ set: vi.fn<(value: boolean) => void>(),+}));+vi.mock("../services/settingsStore", () => ({+ getMissionControlOverlayEnabled: () => settings.enabled,+ setMissionControlOverlayEnabled: settings.set,+}));+vi.mock("electron", () => ({screen: {getAllDisplays: () => [@@ -69,6 +78,8 @@ describe("MissionControlService", () => {beforeEach(() => {vi.useFakeTimers();sampler.create.mockReset();+ settings.enabled = true;+ settings.set.mockReset();pretendPlatform("darwin");});@@ -116,6 +127,43 @@ describe("MissionControlService", () => {expect(service.getState().active).toBe(false);});+ it("never touches the window list while the setting is off", () => {+ settings.enabled = false;+ const { state, impl } = fakeSampler([MISSION_CONTROL_BACKING]);+ sampler.create.mockReturnValue(impl);+ const service = new MissionControlService();++ service.arm();+ state.windows = [MISSION_CONTROL_BACKING];+ vi.advanceTimersByTime(5000);++ expect(sampler.create).not.toHaveBeenCalled();+ expect(service.getState().active).toBe(false);+ });++ it("turning the setting off drops a live overlay, then back on resumes it", () => {+ const { state, impl } = fakeSampler([MISSION_CONTROL_BACKING]);+ sampler.create.mockReturnValue(impl);+ const service = new MissionControlService();++ service.arm();+ vi.advanceTimersByTime(250);+ expect(service.getState().active).toBe(true);++ service.setEnabled(false);+ expect(service.getState().active).toBe(false);+ expect(settings.set).toHaveBeenLastCalledWith(false);++ state.windows = [MISSION_CONTROL_BACKING];+ vi.advanceTimersByTime(5000);+ expect(service.getState().active).toBe(false);++ service.setEnabled(true);+ vi.advanceTimersByTime(250);+ expect(settings.set).toHaveBeenLastCalledWith(true);+ expect(service.getState().active).toBe(true);+ });+it("gives up after repeated sampling failures instead of logging forever", () => {const { state, impl } = fakeSampler();const sampleSpy = vi.spyOn(impl, "sample");diff --git a/products/desktop/apps/code/src/main/platform-adapters/electron-mission-control.ts b/products/desktop/apps/code/src/main/platform-adapters/electron-mission-control.tsindex 0c01a8f660a6..4ee9bf3d04a7 100644--- a/products/desktop/apps/code/src/main/platform-adapters/electron-mission-control.ts+++ b/products/desktop/apps/code/src/main/platform-adapters/electron-mission-control.ts@@ -18,6 +18,10 @@ import type {Rect,WindowListSampler,} from "../services/mission-control/window-list";+import {+ getMissionControlOverlayEnabled,+ setMissionControlOverlayEnabled,+} from "../services/settingsStore";import { logger } from "../utils/logger";const log = logger.scope("mission-control");@@ -39,12 +43,34 @@ export class MissionControlService extends TypedEventEmitter<MissionControlServiprivate active = false;private forced = false;private consecutiveErrors = 0;+ private enabled = getMissionControlOverlayEnabled();getState(): MissionControlState {return { active: this.active };}+ // Only macOS has Mission Control, and the overlay is the only thing the+ // detection drives, so elsewhere the setting has nothing to control.+ isSupported(): boolean {+ return process.platform === "darwin";+ }++ getEnabled(): boolean {+ return this.enabled;+ }++ setEnabled(enabled: boolean): void {+ if (enabled === this.enabled) return;+ this.enabled = enabled;+ setMissionControlOverlayEnabled(enabled);+ // The user turns this on or off from a visible settings window, so arming+ // here matches the window state without waiting for the next show event.+ if (enabled) this.arm();+ else this.disarm();+ }+arm(): void {+ if (!this.enabled) return;if (this.timer || !this.resolveSampler()) return;this.timer = setInterval(() => this.poll(), POLL_INTERVAL_MS);}diff --git a/products/desktop/apps/code/src/main/services/settingsStore.ts b/products/desktop/apps/code/src/main/services/settingsStore.tsindex 4ed515d35b38..8ac1ff4b9dab 100644--- a/products/desktop/apps/code/src/main/services/settingsStore.ts+++ b/products/desktop/apps/code/src/main/services/settingsStore.ts@@ -14,6 +14,7 @@ interface SettingsSchema {discordPresenceEnabled: boolean;discordPresenceShowTaskTitle: boolean;discordPresenceShowRepoName: boolean;+ missionControlOverlayEnabled: boolean;}function getDefaultWorktreeLocation(): string {@@ -99,6 +100,10 @@ const schema = {type: "boolean" as const,default: false,},+ missionControlOverlayEnabled: {+ type: "boolean" as const,+ default: true,+ },};export const settingsStore = new Store<SettingsSchema>({@@ -114,6 +119,7 @@ export const settingsStore = new Store<SettingsSchema>({discordPresenceEnabled: false,discordPresenceShowTaskTitle: false,discordPresenceShowRepoName: false,+ missionControlOverlayEnabled: true,},});@@ -192,3 +198,11 @@ export function getPreventSleepWhileRunning(): boolean {export function setPreventSleepWhileRunning(value: boolean): void {settingsStore.set("preventSleepWhileRunning", value);}++export function getMissionControlOverlayEnabled(): boolean {+ return settingsStore.get("missionControlOverlayEnabled", true);+}++export function setMissionControlOverlayEnabled(value: boolean): void {+ settingsStore.set("missionControlOverlayEnabled", value);+}diff --git a/products/desktop/apps/code/src/main/trpc/routers/mission-control.ts b/products/desktop/apps/code/src/main/trpc/routers/mission-control.tsindex 0573d124af5b..f90d3abb5fc2 100644--- a/products/desktop/apps/code/src/main/trpc/routers/mission-control.ts+++ b/products/desktop/apps/code/src/main/trpc/routers/mission-control.ts@@ -1,14 +1,16 @@+import { z } from "zod";import { container } from "../../di/container";import { MISSION_CONTROL_SERVICE } from "../../di/tokens";import type { MissionControlService } from "../../platform-adapters/electron-mission-control";import { MissionControlServiceEvent } from "../../services/mission-control/schemas";import { publicProcedure, router } from "../trpc";+const getService = () =>+ container.get<MissionControlService>(MISSION_CONTROL_SERVICE);+export const missionControlRouter = router({onStateChanged: publicProcedure.subscription(async function* (opts) {- const service = container.get<MissionControlService>(- MISSION_CONTROL_SERVICE,- );+ const service = getService();for await (const data of service.toIterable(MissionControlServiceEvent.StateChanged,{ signal: opts.signal },@@ -16,4 +18,9 @@ export const missionControlRouter = router({yield data;}}),+ isSupported: publicProcedure.query(() => getService().isSupported()),+ getEnabled: publicProcedure.query(() => getService().getEnabled()),+ setEnabled: publicProcedure+ .input(z.object({ enabled: z.boolean() }))+ .mutation(({ input }) => getService().setEnabled(input.enabled)),});diff --git a/products/desktop/apps/code/src/renderer/di/container.ts b/products/desktop/apps/code/src/renderer/di/container.tsindex 1723d5fce420..6f0256f863d9 100644--- a/products/desktop/apps/code/src/renderer/di/container.ts+++ b/products/desktop/apps/code/src/renderer/di/container.ts@@ -256,6 +256,10 @@ const missionControlClient: MissionControlClient = {});return () => sub.unsubscribe();},+ isSupported: () => trpcClient.missionControl.isSupported.query(),+ getEnabled: () => trpcClient.missionControl.getEnabled.query(),+ setEnabled: (enabled) =>+ trpcClient.missionControl.setEnabled.mutate({ enabled }),};container.bind(MISSION_CONTROL_CLIENT).toConstantValue(missionControlClient);diff --git a/products/desktop/packages/ui/src/features/mission-control/MissionControlOverlay.test.tsx b/products/desktop/packages/ui/src/features/mission-control/MissionControlOverlay.test.tsxindex 3ad653d1ea37..0c78442d3305 100644--- a/products/desktop/packages/ui/src/features/mission-control/MissionControlOverlay.test.tsx+++ b/products/desktop/packages/ui/src/features/mission-control/MissionControlOverlay.test.tsx@@ -1,14 +1,16 @@-import { render, screen } from "@testing-library/react";-import { afterEach, beforeEach, describe, expect, it } from "vitest";+import { act, render, screen } from "@testing-library/react";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import { MissionControlOverlay } from "./MissionControlOverlay";import { useMissionControlStore } from "./missionControlStore";describe("MissionControlOverlay", () => {beforeEach(() => {+ vi.useFakeTimers();useMissionControlStore.setState({ active: false });});afterEach(() => {+ vi.useRealTimers();document.getElementById("portal-container")?.remove();});@@ -35,6 +37,27 @@ describe("MissionControlOverlay", () => {);});+ it("fades in and stays mounted while fading out", () => {+ useMissionControlStore.setState({ active: true });+ render(<MissionControlOverlay />);++ expect(screen.getByTestId("mission-control-overlay")).toHaveClass(+ "opacity-0",+ );+ act(() => vi.runAllTimers());+ expect(screen.getByTestId("mission-control-overlay")).toHaveClass(+ "opacity-100",+ );++ act(() => useMissionControlStore.setState({ active: false }));+ expect(screen.getByTestId("mission-control-overlay")).toHaveClass(+ "opacity-0",+ );++ act(() => vi.advanceTimersByTime(150));+ expect(screen.queryByTestId("mission-control-overlay")).toBeNull();+ });+it("portals into the theme container when one exists", () => {// Falling back to document.body lands outside the Radix <Theme> subtree// and renders a light panel in dark mode.diff --git a/products/desktop/packages/ui/src/features/mission-control/MissionControlOverlay.tsx b/products/desktop/packages/ui/src/features/mission-control/MissionControlOverlay.tsxindex c70df88f2372..2ce4383f73a3 100644--- a/products/desktop/packages/ui/src/features/mission-control/MissionControlOverlay.tsx+++ b/products/desktop/packages/ui/src/features/mission-control/MissionControlOverlay.tsx@@ -1,13 +1,34 @@import LogosLandscape from "@posthog/ui/primitives/Logo";+import { useEffect, useState } from "react";import { createPortal } from "react-dom";import { useMissionControlStore } from "./missionControlStore";-// Unanimated on purpose: at Mission Control's thumbnail scale a transition-// reads as a rendering glitch.+const FADE_DURATION_MS = 150;+export function MissionControlOverlay() {const active = useMissionControlStore((state) => state.active);+ const [rendered, setRendered] = useState(active);+ const [visible, setVisible] = useState(false);++ useEffect(() => {+ if (active) {+ setRendered(true);+ let revealFrame = 0;+ const mountedFrame = requestAnimationFrame(() => {+ revealFrame = requestAnimationFrame(() => setVisible(true));+ });+ return () => {+ cancelAnimationFrame(mountedFrame);+ cancelAnimationFrame(revealFrame);+ };+ }++ setVisible(false);+ const timeout = setTimeout(() => setRendered(false), FADE_DURATION_MS);+ return () => clearTimeout(timeout);+ }, [active]);- if (!active) return null;+ if (!rendered) return null;// Portalling to document.body would land outside the Radix <Theme> subtree// and render a light panel in dark mode.@@ -18,7 +39,7 @@ export function MissionControlOverlay() {<divaria-hidden="true"data-testid="mission-control-overlay"- className="pointer-events-none fixed inset-0 z-[300] flex flex-col items-center justify-center gap-[2.5vh] bg-(--gray-1)/75 backdrop-blur-md"+ className={`pointer-events-none fixed inset-0 z-[300] flex flex-col items-center justify-center gap-[2.5vh] bg-(--gray-1)/10 backdrop-blur-sm transition-opacity duration-150 ease-out motion-reduce:transition-none ${visible ? "opacity-100" : "opacity-0"}`}>{/* The logo-only variant reserves room for the wordmark, so crop to thelogomark's own 52:28 box. */}diff --git a/products/desktop/packages/ui/src/features/mission-control/identifiers.ts b/products/desktop/packages/ui/src/features/mission-control/identifiers.tsindex 24bd5d8232c0..844ef4761e72 100644--- a/products/desktop/packages/ui/src/features/mission-control/identifiers.ts+++ b/products/desktop/packages/ui/src/features/mission-control/identifiers.ts@@ -4,6 +4,9 @@ export interface MissionControlState {export interface MissionControlClient {onStateChanged(onData: (state: MissionControlState) => void): () => void;+ isSupported(): Promise<boolean>;+ getEnabled(): Promise<boolean>;+ setEnabled(enabled: boolean): Promise<void>;}export const MISSION_CONTROL_CLIENT = Symbol.for(diff --git a/products/desktop/packages/ui/src/features/settings/sections/GeneralSettings.tsx b/products/desktop/packages/ui/src/features/settings/sections/GeneralSettings.tsxindex 2b51c4cd2edb..b79262907267 100644--- a/products/desktop/packages/ui/src/features/settings/sections/GeneralSettings.tsx+++ b/products/desktop/packages/ui/src/features/settings/sections/GeneralSettings.tsx@@ -1,5 +1,6 @@import { ArrowSquareOut } from "@phosphor-icons/react";import { buildPostHogUrl } from "@posthog/core/settings/posthogUrl";+import { useServiceOptional } from "@posthog/di/react";import { useHostTRPC } from "@posthog/host-router/react";import { ANALYTICS_EVENTS } from "@posthog/shared";import {@@ -8,6 +9,10 @@ import {EFFORT_LEVELS,} from "@posthog/shared/domain-types";import { useAuthStateValue } from "@posthog/ui/features/auth/store";+import {+ MISSION_CONTROL_CLIENT,+ type MissionControlClient,+} from "@posthog/ui/features/mission-control/identifiers";import {ReasoningLevelDropdown,type ReasoningLevelOption,@@ -27,7 +32,7 @@ import type { ThemePreference } from "@posthog/ui/shell/themeStore";import { useThemeStore } from "@posthog/ui/shell/themeStore";import { useHostCapabilities } from "@posthog/ui/shell/useHostCapabilities";import { Button, Flex, Link, Select, Switch, Text } from "@radix-ui/themes";-import { useMutation, useQuery } from "@tanstack/react-query";+import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";import { useCallback, useEffect } from "react";const DEFAULT_EFFORT_OPTIONS: ReasoningLevelOption[] = [@@ -86,6 +91,40 @@ export function GeneralSettings() {[setPreventSleepWhileRunning, preventSleepMutation],);+ // Mission Control overlay state. The client is bound on desktop only, so on+ // other hosts this resolves to null and the setting is hidden.+ const queryClient = useQueryClient();+ const missionControl = useServiceOptional<MissionControlClient>(+ MISSION_CONTROL_CLIENT,+ );+ const { data: missionControlSupported } = useQuery({+ queryKey: ["missionControlOverlay", "supported"],+ queryFn: () => missionControl?.isSupported() ?? false,+ enabled: missionControl != null,+ });+ const { data: missionControlEnabled } = useQuery({+ queryKey: ["missionControlOverlay", "enabled"],+ queryFn: () => missionControl?.getEnabled() ?? false,+ enabled: missionControl != null && missionControlSupported === true,+ });+ const missionControlMutation = useMutation({+ mutationFn: (enabled: boolean) =>+ missionControl?.setEnabled(enabled) ?? Promise.resolve(),+ });++ const handleMissionControlOverlayChange = useCallback(+ (checked: boolean) => {+ track(ANALYTICS_EVENTS.SETTING_CHANGED, {+ setting_name: "mission_control_overlay",+ new_value: checked,+ old_value: !checked,+ });+ queryClient.setQueryData(["missionControlOverlay", "enabled"], checked);+ missionControlMutation.mutate(checked);+ },+ [missionControlMutation, queryClient],+ );+// Chat stateconst {autoConvertLongText,@@ -288,6 +327,19 @@ export function GeneralSettings() {</Select.Root></SettingRow>+ {missionControl != null && missionControlSupported === true && (+ <SettingRow+ label="Mission Control overlay"+ description="Show the PostHog logo over the window while macOS Mission Control is open, so it's easy to spot among your other windows"+ >+ <Switch+ checked={missionControlEnabled ?? false}+ onCheckedChange={handleMissionControlOverlayChange}+ size="1"+ />+ </SettingRow>+ )}+{/* Input */}<Text className="mb-2 block border-gray-6 border-t pt-4 font-medium text-sm">Input