: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 a one-hour pause for notifications (#105926)
Paul D'Ambra9decc22a2431
diff --git a/products/desktop/apps/code/src/renderer/desktop-services.ts b/products/desktop/apps/code/src/renderer/desktop-services.tsindex c4859689032e..6f1fe6fe47ba 100644--- a/products/desktop/apps/code/src/renderer/desktop-services.ts+++ b/products/desktop/apps/code/src/renderer/desktop-services.ts@@ -103,7 +103,10 @@ import {AGENT_PROMPT_SENDER,type AgentPromptSender,} from "@posthog/ui/features/sessions/agentPromptSender";-import { useSettingsStore } from "@posthog/ui/features/settings/settingsStore";+import {+ notificationsPaused,+ useSettingsStore,+} from "@posthog/ui/features/settings/settingsStore";import {type ISpeechKeyStore,SPEECH_KEY_STORE,@@ -326,6 +329,7 @@ containercompletionVolume: s.completionVolume,scaleSoundWithTaskLength: s.scaleSoundWithTaskLength,customSounds: s.customSounds,+ notificationsPausedUntil: s.notificationsPausedUntil,};},});@@ -388,7 +392,9 @@ containerget: () => {const s = useSettingsStore.getState();return {- enabled: s.spokenNotifications,+ enabled:+ s.spokenNotifications &&+ !notificationsPaused(s.notificationsPausedUntil),voiceId: s.elevenLabsVoiceId || undefined,};},diff --git a/products/desktop/apps/web/src/web-notifications.ts b/products/desktop/apps/web/src/web-notifications.tsindex 39f6b9d14212..71f533bd7b24 100644--- a/products/desktop/apps/web/src/web-notifications.ts+++ b/products/desktop/apps/web/src/web-notifications.ts@@ -75,6 +75,7 @@ export const webNotificationSettings: INotificationSettings = {completionVolume: s.completionVolume,scaleSoundWithTaskLength: s.scaleSoundWithTaskLength,customSounds: s.customSounds,+ notificationsPausedUntil: s.notificationsPausedUntil,};},};diff --git a/products/desktop/apps/web/src/web-speech.ts b/products/desktop/apps/web/src/web-speech.tsindex 9ee520833a36..5c9526c02daf 100644--- a/products/desktop/apps/web/src/web-speech.ts+++ b/products/desktop/apps/web/src/web-speech.ts@@ -5,7 +5,10 @@ import type {import type { ISpeech } from "@posthog/platform/speech";import { authKeys } from "@posthog/ui/features/auth/useCurrentUser";import type { ISpeechNotifySettings } from "@posthog/ui/features/notifications/identifiers";-import { useSettingsStore } from "@posthog/ui/features/settings/settingsStore";+import {+ notificationsPaused,+ useSettingsStore,+} from "@posthog/ui/features/settings/settingsStore";import type { ImperativeQueryClient } from "@posthog/ui/shell/queryClient";import {isSpeechSupported,@@ -29,7 +32,9 @@ export const webSpeechNotifySettings: ISpeechNotifySettings = {get: () => {const s = useSettingsStore.getState();return {- enabled: s.spokenNotifications,+ enabled:+ s.spokenNotifications &&+ !notificationsPaused(s.notificationsPausedUntil),needsInput: s.spokenNotifyNeedsInput,completion: s.spokenNotifyCompletion,progress: s.spokenNotifyProgress,diff --git a/products/desktop/packages/core/src/speech/speech.test.ts b/products/desktop/packages/core/src/speech/speech.test.tsindex 796445a482c9..97aeadc0abdd 100644--- a/products/desktop/packages/core/src/speech/speech.test.ts+++ b/products/desktop/packages/core/src/speech/speech.test.ts@@ -42,9 +42,8 @@ const noopLogger = {function make(settings: Partial<{ enabled: boolean; voiceId?: string }> = {}) {const speech = new ControllableSpeech();- const settingsProvider: SpeechSettingsProvider = {- get: () => ({ enabled: true, ...settings }),- };+ const current = { enabled: true, ...settings };+ const settingsProvider: SpeechSettingsProvider = { get: () => current };const userName: UserNameProvider = { getFirstName: () => "Jon" };const service = new SpeechQueueService(speech,@@ -52,7 +51,7 @@ function make(settings: Partial<{ enabled: boolean; voiceId?: string }> = {}) {userName,noopLogger as never,);- return { speech, service };+ return { speech, service, settings: current };}// let the queued microtasks (drain loop) run@@ -87,6 +86,26 @@ describe("SpeechQueueService", () => {expect(speech.spoken).toEqual([]);});+ it("drops queued lines when narration turns off mid-queue", async () => {+ const { speech, service, settings } = make();+ service.enqueue({ text: "one", taskTitle: "a", taskId: "1" });+ service.enqueue({ text: "two", taskTitle: "b", taskId: "2" });+ await tick();++ settings.enabled = false;+ speech.finishOne();+ await tick();+ expect(speech.spoken).toEqual(["PostHog task 'a' — one"]);++ settings.enabled = true;+ service.enqueue({ text: "three", taskTitle: "c", taskId: "3" });+ await tick();+ expect(speech.spoken).toEqual([+ "PostHog task 'a' — one",+ "PostHog task 'c' — three",+ ]);+ });+it("coalesces a newer line for the same queued task", async () => {const { speech, service } = make();// First starts playing immediately (in-flight, not in queue).diff --git a/products/desktop/packages/core/src/speech/speech.ts b/products/desktop/packages/core/src/speech/speech.tsindex f5dd3ce7d7c9..ad84ed95dac1 100644--- a/products/desktop/packages/core/src/speech/speech.ts+++ b/products/desktop/packages/core/src/speech/speech.ts@@ -117,7 +117,12 @@ export class SpeechQueueService implements ISpeechQueue {while (this.queue.length > 0) {const next = this.queue.shift();if (!next) break;- const { voiceId } = this.settings.get();+ // A pause or an opt-out also silences the lines that already wait.+ const { enabled, voiceId } = this.settings.get();+ if (!enabled) {+ this.queue.length = 0;+ break;+ }try {await this.speech.speak(next.text, { voiceId });} catch (err) {diff --git a/products/desktop/packages/shared/src/analytics-events.ts b/products/desktop/packages/shared/src/analytics-events.tsindex ba0a7ac679bf..24ad69318186 100644--- a/products/desktop/packages/shared/src/analytics-events.ts+++ b/products/desktop/packages/shared/src/analytics-events.ts@@ -54,6 +54,7 @@ export type CommandMenuAction =| "logout"| "toggle-theme"| "toggle-left-sidebar"+ | "toggle-notifications-pause"| "open-review-panel"| "archive-task"| "go-back"diff --git a/products/desktop/packages/ui/src/features/command/CommandMenu.tsx b/products/desktop/packages/ui/src/features/command/CommandMenu.tsxindex 8b4e16a35d60..f11ce51d0562 100644--- a/products/desktop/packages/ui/src/features/command/CommandMenu.tsx+++ b/products/desktop/packages/ui/src/features/command/CommandMenu.tsx@@ -1,6 +1,8 @@import {ArchiveIcon,ArrowClockwiseIcon,+ BellIcon,+ BellSlashIcon,CaretLeftIcon,CaretRightIcon,ChartLineIcon,@@ -114,10 +116,16 @@ import {closeSettings,openSettings,} from "@posthog/ui/features/settings/hooks/useOpenSettings";+import {+ NOTIFICATION_PAUSE_MS,+ notificationsPaused,+ useSettingsStore,+} from "@posthog/ui/features/settings/settingsStore";import { useSidebarStore } from "@posthog/ui/features/sidebar/sidebarStore";import { useTasks } from "@posthog/ui/features/tasks/useTasks";import { useWorkspaces } from "@posthog/ui/features/workspace/useWorkspace";import { LoopIcon } from "@posthog/ui/primitives/LoopIcon";+import { toast } from "@posthog/ui/primitives/toast";import {goBackInHistory,goForwardInHistory,@@ -265,6 +273,13 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {const { theme, setTheme } = useThemeStore();const toggleLeftSidebar = useSidebarStore((state) => state.toggle);const openFeedback = useFeedbackStore((state) => state.open);+ const notificationsPausedUntil = useSettingsStore(+ (state) => state.notificationsPausedUntil,+ );+ const setNotificationsPausedUntil = useSettingsStore(+ (state) => state.setNotificationsPausedUntil,+ );+ const pausedNow = notificationsPaused(notificationsPausedUntil);const view = useAppView();const setReviewMode = useReviewNavigationStore((state) => state.setReviewMode,@@ -552,6 +567,34 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {shortcut: SHORTCUTS.TOGGLE_LEFT_SIDEBAR,onRun: toggleLeftSidebar,},+ {+ id: "toggle-notifications-pause",+ label: pausedNow+ ? "Resume notifications"+ : "Pause notifications for 1 hour",+ keywords: "mute silence sound quiet meeting alerts",+ icon: pausedNow ? (+ <BellIcon size={12} className="text-muted-foreground" />+ ) : (+ <BellSlashIcon size={12} className="text-muted-foreground" />+ ),+ action: "toggle-notifications-pause",+ onRun: () => {+ if (pausedNow) {+ setNotificationsPausedUntil(null);+ toast.success("Notifications resumed");+ return;+ }+ const until = Date.now() + NOTIFICATION_PAUSE_MS;+ setNotificationsPausedUntil(until);+ toast.success(+ `Notifications paused until ${new Date(until).toLocaleTimeString(+ [],+ { hour: "numeric", minute: "2-digit" },+ )}`,+ );+ },+ },{id: "send-feedback",label: "Send feedback",@@ -708,6 +751,8 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {closeSettingsDialog,toggleLeftSidebar,openFeedback,+ pausedNow,+ setNotificationsPausedUntil,openReviewPanel,reviewTaskId,openedTask,diff --git a/products/desktop/packages/ui/src/features/notifications/identifiers.ts b/products/desktop/packages/ui/src/features/notifications/identifiers.tsindex 5eb322a4481a..663ba6401bcf 100644--- a/products/desktop/packages/ui/src/features/notifications/identifiers.ts+++ b/products/desktop/packages/ui/src/features/notifications/identifiers.ts@@ -12,6 +12,7 @@ export interface NotificationSettings {completionVolume: number;scaleSoundWithTaskLength: boolean;customSounds: CustomSound[];+ notificationsPausedUntil: number | null;}export interface INotificationSettings {diff --git a/products/desktop/packages/ui/src/features/notifications/notifications.test.ts b/products/desktop/packages/ui/src/features/notifications/notifications.test.tsindex be22264f6be2..ef01db02bcc0 100644--- a/products/desktop/packages/ui/src/features/notifications/notifications.test.ts+++ b/products/desktop/packages/ui/src/features/notifications/notifications.test.ts@@ -57,6 +57,7 @@ function makeBus(overrides?: {completionVolume: 80,scaleSoundWithTaskLength: false,customSounds: [],+ notificationsPausedUntil: null,...overrides?.settings,};@@ -170,6 +171,35 @@ describe("notifyPromptComplete", () => {});});+describe("pause", () => {+ it.each([+ { label: "native tier", hasFocus: false, toast: false },+ { label: "toast tier", hasFocus: true, toast: true },+ ])("stays silent on the $label while paused", ({ hasFocus, toast }) => {+ const { bus, notify, showUnreadIndicator, requestAttention, play } =+ makeBus({+ hasFocus,+ settings: { notificationsPausedUntil: Date.now() + 60_000 },+ });+ bus.notifyPromptComplete("My task", "end_turn", TASK_ID);+ expect(play).not.toHaveBeenCalled();+ expect(notify).not.toHaveBeenCalled();+ expect(showUnreadIndicator).not.toHaveBeenCalled();+ expect(requestAttention).not.toHaveBeenCalled();+ expect(toastMock.success).toHaveBeenCalledTimes(toast ? 1 : 0);+ });++ it("alerts again once the pause ends", () => {+ const { bus, notify, play } = makeBus({+ hasFocus: false,+ settings: { notificationsPausedUntil: Date.now() - 1 },+ });+ bus.notifyPromptComplete("My task", "end_turn", TASK_ID);+ expect(play).toHaveBeenCalledTimes(1);+ expect(notify).toHaveBeenCalledTimes(1);+ });+});+describe("native tier settings gating (app unfocused)", () => {it("skips the OS notification when desktopNotifications is off, still dings dock", () => {const { bus, notify, showUnreadIndicator, requestAttention } = makeBus({diff --git a/products/desktop/packages/ui/src/features/notifications/notifications.ts b/products/desktop/packages/ui/src/features/notifications/notifications.tsindex 102d9076e7c7..5c80a15bad73 100644--- a/products/desktop/packages/ui/src/features/notifications/notifications.ts+++ b/products/desktop/packages/ui/src/features/notifications/notifications.ts@@ -4,6 +4,7 @@ import {type NotificationTarget,} from "@posthog/platform/notifications";import type { TaskActivityKind } from "@posthog/shared/domain-types";+import { notificationsPaused } from "@posthog/ui/features/settings/settingsStore";import { toast } from "@posthog/ui/primitives/toast";import { openNotificationTarget } from "@posthog/ui/router/navigationBridge";import { logger } from "@posthog/ui/shell/logger";@@ -102,6 +103,9 @@ export class NotificationBus {});const settings = this.settings.get();+ // A pause keeps the silent in-app toast but stops every noise and every+ // alert outside the app window.+ const paused = notificationsPaused(settings.notificationsPausedUntil);const playbackRate =settings.scaleSoundWithTaskLength &&descriptor.soundDurationMs !== undefined@@ -112,12 +116,16 @@ export class NotificationBus {// resolves to nothing. Under a `random-*` sound this re-picks, so it// reports whether a sound plays, not which one.const willPlaySound =+ !paused &&resolveSoundUrl(settings.completionSound, settings.customSounds) !== null;// A native notification we leave unsilenced rings the OS chime instead, so// the line has to name that noise rather than read as silence.const nativeSilent = descriptor.silent ?? willPlaySound;const osChimePlayed =- channel === "native" && settings.desktopNotifications && !nativeSilent;+ channel === "native" &&+ !paused &&+ settings.desktopNotifications &&+ !nativeSilent;// One line for every notification, including the suppressed ones. At info// level on purpose: packaged builds drop debug, and "the app made a noise@@ -130,6 +138,7 @@ export class NotificationBus {target: describeTarget(descriptor.target),viewingTarget: describeTarget(viewingTarget),appFocused,+ paused,sound: settings.completionSound,soundPlayed: channel !== "suppress" && willPlaySound,osChimePlayed,@@ -144,18 +153,21 @@ export class NotificationBus {// Sound fires on both delivered tiers (toast + native), not on suppress —// matching the pre-bus behavior where any non-suppressed notification rang.- playCompletionSound(- settings.completionSound,- settings.completionVolume,- settings.customSounds,- playbackRate,- descriptor.reason,- );+ if (!paused) {+ playCompletionSound(+ settings.completionSound,+ settings.completionVolume,+ settings.customSounds,+ playbackRate,+ descriptor.reason,+ );+ }if (channel === "toast") {this.showToast(descriptor);return;}+ if (paused) return;// nativeif (settings.desktopNotifications) {diff --git a/products/desktop/packages/ui/src/features/settings/sections/NotificationsSettings.stories.tsx b/products/desktop/packages/ui/src/features/settings/sections/NotificationsSettings.stories.tsxnew file mode 100644index 000000000000..9e045579f3bf--- /dev/null+++ b/products/desktop/packages/ui/src/features/settings/sections/NotificationsSettings.stories.tsx@@ -0,0 +1,19 @@+import type { Meta, StoryObj } from "@storybook/react-vite";+import { NotificationsSettings } from "./NotificationsSettings";++const meta: Meta<typeof NotificationsSettings> = {+ title: "Settings/NotificationsSettings",+ component: NotificationsSettings,+ decorators: [+ (Story) => (+ <div className="max-w-[640px] p-6">+ <Story />+ </div>+ ),+ ],+};++export default meta;+type Story = StoryObj<typeof NotificationsSettings>;++export const Default: Story = {};diff --git a/products/desktop/packages/ui/src/features/settings/sections/NotificationsSettings.tsx b/products/desktop/packages/ui/src/features/settings/sections/NotificationsSettings.tsxindex 3f85920b2f68..8f83f39d3bc2 100644--- a/products/desktop/packages/ui/src/features/settings/sections/NotificationsSettings.tsx+++ b/products/desktop/packages/ui/src/features/settings/sections/NotificationsSettings.tsx@@ -43,6 +43,8 @@ import {type CompletionSound,type CustomSound,NOTIFICATION_DEFAULTS,+ NOTIFICATION_PAUSE_MS,+ notificationsPaused,type SpokenFocusMode,useSettingsStore,} from "@posthog/ui/features/settings/settingsStore";@@ -87,6 +89,7 @@ export function NotificationsSettings() {completionVolume,scaleSoundWithTaskLength,customSounds,+ notificationsPausedUntil,setDesktopNotifications,setDockBadgeNotifications,setDockBounceNotifications,@@ -96,6 +99,7 @@ export function NotificationsSettings() {setScaleSoundWithTaskLength,removeCustomSound,renameCustomSound,+ setNotificationsPausedUntil,} = useSettingsStore();const [addSoundOpen, setAddSoundOpen] = useState(false);@@ -129,6 +133,32 @@ export function NotificationsSettings() {const notificationsDenied = window.Notification?.permission === "denied";+ const paused = notificationsPaused(notificationsPausedUntil);++ // Clear the pause when it ends, so the row does not keep showing it.+ useEffect(() => {+ if (!paused || notificationsPausedUntil === null) return;+ const timeout = setTimeout(+ () => setNotificationsPausedUntil(null),+ notificationsPausedUntil - Date.now(),+ );+ return () => clearTimeout(timeout);+ }, [paused, notificationsPausedUntil, setNotificationsPausedUntil]);++ const handlePauseChange = useCallback(+ (pause: boolean) => {+ track(ANALYTICS_EVENTS.SETTING_CHANGED, {+ setting_name: "notifications_paused",+ new_value: pause,+ old_value: paused,+ });+ setNotificationsPausedUntil(+ pause ? Date.now() + NOTIFICATION_PAUSE_MS : null,+ );+ },+ [paused, setNotificationsPausedUntil],+ );+const handleDesktopNotificationsChange = useCallback(async (checked: boolean) => {if (checked) {@@ -283,6 +313,30 @@ export function NotificationsSettings() {</>)}</div>+ <SettingsCard>+ <SettingsCardRow+ label="Pause alerts"+ description={+ paused && notificationsPausedUntil !== null+ ? `Paused until ${new Date(+ notificationsPausedUntil,+ ).toLocaleTimeString([], {+ hour: "numeric",+ minute: "2-digit",+ })}. In-app toasts still show.`+ : "Mute sounds, voice and system notifications for 1 hour"+ }+ >+ <Button+ type="button"+ variant="outline"+ size="sm"+ onClick={() => handlePauseChange(!paused)}+ >+ {paused ? "Resume" : "Pause for 1 hour"}+ </Button>+ </SettingsCardRow>+ </SettingsCard></SettingsSection><SettingsSectiondiff --git a/products/desktop/packages/ui/src/features/settings/settingsStore.ts b/products/desktop/packages/ui/src/features/settings/settingsStore.tsindex c7edcd6952e0..20f266a55286 100644--- a/products/desktop/packages/ui/src/features/settings/settingsStore.ts+++ b/products/desktop/packages/ui/src/features/settings/settingsStore.ts@@ -204,6 +204,8 @@ export interface SettingsStore {completionVolume: number;scaleSoundWithTaskLength: boolean;customSounds: CustomSound[];+ // Epoch ms. Until then, alerts make no sound, voice or system notification.+ notificationsPausedUntil: number | null;setDesktopNotifications: (enabled: boolean) => void;setDockBadgeNotifications: (enabled: boolean) => void;setDockBounceNotifications: (enabled: boolean) => void;@@ -214,6 +216,7 @@ export interface SettingsStore {addCustomSound: (sound: CustomSound) => void;removeCustomSound: (id: string) => void;renameCustomSound: (id: string, name: string) => void;+ setNotificationsPausedUntil: (until: number | null) => void;// Spoken notificationsspokenNotifications: boolean;@@ -373,6 +376,16 @@ export const NOTIFICATION_DEFAULTS = {elevenLabsKeyConfigured: false,};+export const NOTIFICATION_PAUSE_MS = 60 * 60 * 1000;++// No timer clears the pause: it ends when the clock passes the stored time.+export function notificationsPaused(+ pausedUntil: number | null,+ now = Date.now(),+): boolean {+ return pausedUntil !== null && now < pausedUntil;+}+export const useSettingsStore = create<SettingsStore>()(persist((set, get) => ({@@ -457,6 +470,7 @@ export const useSettingsStore = create<SettingsStore>()(// Kept out of NOTIFICATION_DEFAULTS so "Reset to defaults" never discards// sounds the user installed.customSounds: [],+ notificationsPausedUntil: null,setDesktopNotifications: (enabled) =>set({ desktopNotifications: enabled }),setDockBadgeNotifications: (enabled) =>@@ -502,6 +516,8 @@ export const useSettingsStore = create<SettingsStore>()(s.id === id ? { ...s, name } : s,),})),+ setNotificationsPausedUntil: (until) =>+ set({ notificationsPausedUntil: until }),// Composer / chatautoConvertLongText: "2500",@@ -702,6 +718,7 @@ export const useSettingsStore = create<SettingsStore>()(completionVolume: state.completionVolume,scaleSoundWithTaskLength: state.scaleSoundWithTaskLength,customSounds: state.customSounds,+ notificationsPausedUntil: state.notificationsPausedUntil,spokenNotifications: state.spokenNotifications,spokenNotifyNeedsInput: state.spokenNotifyNeedsInput,spokenNotifyCompletion: state.spokenNotifyCompletion,