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
2 changes: 1 addition & 1 deletion crates/domain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub use monitor::MonitorInfo;
pub use new_focus::NewFocus;
pub use notification::{
all_sources, FocusesOverCapSource, NotificationSettings, NotificationSource,
TaskTimerExpiredSource, TasksOverCapSource, TimerExpiredSource,
NotificationSourceDescriptor, TaskTimerExpiredSource, TasksOverCapSource, TimerExpiredSource,
};
pub use parse::{parse_focus_md, ParseError};
pub use pig_rect::{PigRect, RectUpdater};
Expand Down
8 changes: 8 additions & 0 deletions crates/domain/src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ pub trait NotificationSource {
fn label(&self) -> &'static str;
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[cfg_attr(feature = "export-ts", derive(ts_rs::TS))]
#[cfg_attr(feature = "export-ts", ts(export))]
pub struct NotificationSourceDescriptor {
pub key: String,
pub label: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
#[cfg_attr(feature = "export-ts", derive(ts_rs::TS))]
#[cfg_attr(feature = "export-ts", ts(export))]
Expand Down
4 changes: 2 additions & 2 deletions issues/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Each issue is a self-contained vertical slice that one person or coding agent ca

## Priority queue

- [031](031-notification-source-settings.md) — Notification source settings registry (GH #31)
No feature issues queued.

### Architecture queue (deepening)

These are not required before 031. Pick one when we choose to spend a slice on internal seams or future-proofing.
Pick one when we choose to spend a slice on internal seams or future-proofing.

- [056](056-task-timer-binding.md) — Task Timers drift when Tasks are hand-edited
- [051](051-ranch-animal-vocabulary-seam.md) — Animal vocabulary for the movement layer (render contract shipped; `Pig*` names remain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,22 @@ Notification toggles in Preferences are driven by the Rust `NotificationSource`

## Acceptance criteria

- [ ] A command/API returns notification source descriptors from `all_sources()`
- [ ] `SettingsWindow` no longer contains a hardcoded `NOTIFICATION_SOURCES` list
- [ ] "Timer expired", "Too many focuses", and "Too many tasks in a focus" toggles still render with current settings values
- [ ] Toggling any source updates `settings.yaml` and takes effect immediately (no restart needed)
- [ ] Adding a second or later `NotificationSource` requires no changes to `SettingsWindow`
- [ ] Existing Settings sections (General, Widget, Displays, Debug) are unaffected
- [ ] `task check` green
- [x] A command/API returns notification source descriptors from `all_sources()`
- [x] `SettingsWindow` no longer contains a hardcoded `NOTIFICATION_SOURCES` list
- [x] "Timer expired", "Too many focuses", and "Too many tasks in a focus" toggles still render with current settings values
- [x] Toggling any source updates `settings.yaml` and takes effect immediately (no restart needed)
- [x] Adding a second or later `NotificationSource` requires no changes to `SettingsWindow`
- [x] Existing Settings sections (General, Widget, Displays, Debug) are unaffected
- [x] `task check` green

## Blocked by

050 — settings update workflow and runtime freshness. 029 and 032 are done.

## Validation

Automated acceptance passed: the registry projection, API/hook wiring, current labels and values, and arbitrary-descriptor rendering/toggling are covered by focused tests. Existing settings workflow, flat YAML round-trip, and latest-settings notification tests passed, covering persistence and immediate runtime application without changing the settings schema.

`task check` and `task check:windows` passed. Implementation review returned PASS; the rules review was clean.

Native Preferences interaction, actual settings-file changes from native toggles, and OS notification delivery were not observed. These checks establish automated behavior, not native GUI verification.
1 change: 1 addition & 0 deletions src-tauri/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub fn run() {
ui_bridge::update_pig_rects,
ui_bridge::set_pig_drag_active,
ui_bridge::get_settings,
ui_bridge::list_notification_sources,
ui_bridge::update_settings,
ui_bridge::edit_saved_timer_minutes,
ui_bridge::get_monitors,
Expand Down
31 changes: 30 additions & 1 deletion src-tauri/src/ui_bridge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use adhd_ranch_commands::{
};
use adhd_ranch_domain::agents::hooks::{HookFiring, HookWiring};
use adhd_ranch_domain::session::AgentSession;
use adhd_ranch_domain::{Focus, Settings, TimerOwner, TimerPreset, TimerPresetEdit, TimerPresets};
use adhd_ranch_domain::{
all_sources, Focus, NotificationSourceDescriptor, Settings, TimerOwner, TimerPreset,
TimerPresetEdit, TimerPresets,
};

use tauri::{AppHandle, Emitter, Manager, State, Wry};

Expand Down Expand Up @@ -199,6 +202,17 @@ pub fn set_pig_drag_active(active: bool, state: State<'_, DragLockState>) {
state.0.store(active, Ordering::Relaxed);
}

#[tauri::command]
pub fn list_notification_sources() -> Vec<NotificationSourceDescriptor> {
all_sources()
.iter()
.map(|source| NotificationSourceDescriptor {
key: source.key().to_string(),
label: source.label().to_string(),
})
.collect()
}

#[tauri::command]
pub fn get_settings(state: State<'_, SettingsState>) -> Settings {
state.0.lock().map(|s| s.clone()).unwrap_or_default()
Expand Down Expand Up @@ -283,3 +297,18 @@ pub fn get_devtools_open(app: AppHandle<Wry>) -> bool {
pub fn get_devtools_open() -> bool {
false
}

#[cfg(test)]
mod tests {
#[test]
fn notification_descriptors_follow_the_domain_registry() {
let descriptors = super::list_notification_sources();
let sources = adhd_ranch_domain::all_sources();

assert_eq!(descriptors.len(), sources.len());
for (descriptor, source) in descriptors.iter().zip(sources) {
assert_eq!(descriptor.key, source.key());
assert_eq!(descriptor.label, source.label());
}
}
}
19 changes: 18 additions & 1 deletion src/api/settings.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { invoke } from "@tauri-apps/api/core";
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { TimerPresetEdit } from "../types/generated/TimerPresetEdit";
import { editSavedTimerMinutes } from "./settings";
import { editSavedTimerMinutes, listNotificationSources } from "./settings";

vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));

Expand Down Expand Up @@ -30,3 +30,20 @@ describe("editSavedTimerMinutes", () => {
await expect(editSavedTimerMinutes({ Add: 25 })).rejects.toBe(error);
});
});

describe("listNotificationSources", () => {
it("returns registry descriptors from IPC without filtering future keys", async () => {
const sources = [{ key: "future_source", label: "A future notification" }];
vi.mocked(invoke).mockResolvedValue(sources);

expect(await listNotificationSources()).toEqual(sources);
expect(invoke).toHaveBeenCalledWith("list_notification_sources");
});

it("propagates registry read failures", async () => {
const error = new Error("unavailable");
vi.mocked(invoke).mockRejectedValue(error);

await expect(listNotificationSources()).rejects.toBe(error);
});
});
5 changes: 5 additions & 0 deletions src/api/settings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { invoke } from "@tauri-apps/api/core";
import type { NotificationSourceDescriptor } from "../types/generated/NotificationSourceDescriptor";
import type { TimerPresetEdit } from "../types/generated/TimerPresetEdit";
import type { TimerPresets } from "../types/generated/TimerPresets";
import type { Settings } from "../types/settings";

export async function listNotificationSources(): Promise<NotificationSourceDescriptor[]> {
return invoke<NotificationSourceDescriptor[]>("list_notification_sources");
}

export async function getSettings(): Promise<Settings> {
return invoke<Settings>("get_settings");
}
Expand Down
62 changes: 60 additions & 2 deletions src/components/SettingsWindow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,22 @@ const SETTINGS: Settings = {
timers: { saved_minutes: [15] },
};

function renderSettings(onUpdate: (next: Settings) => void) {
const SOURCES = [
{ key: "timer_expired", label: "Timer expired" },
{ key: "task_timer_expired", label: "Task timer expired" },
{ key: "focuses_over_cap", label: "Too many focuses" },
{ key: "tasks_over_cap", label: "Too many tasks in a focus" },
];

function renderSettings(
onUpdate: (next: Settings) => void,
settings = SETTINGS,
notificationSources = SOURCES,
) {
render(
<SettingsWindow
settings={SETTINGS}
settings={settings}
notificationSources={notificationSources}
monitors={[]}
debugOverlay={false}
devtoolsOpen={false}
Expand Down Expand Up @@ -91,3 +103,49 @@ describe("SettingsWindow number rows", () => {
});
});
});

describe("SettingsWindow notification registry", () => {
it("renders registered labels with explicit values and enabled defaults", () => {
renderSettings(vi.fn(), {
...SETTINGS,
notifications: { sources: { timer_expired: false, focuses_over_cap: true } },
});

expect(screen.getByLabelText("Timer expired")).not.toBeChecked();
expect(screen.getByLabelText("Task timer expired")).toBeChecked();
expect(screen.getByLabelText("Too many focuses")).toBeChecked();
expect(screen.getByLabelText("Too many tasks in a focus")).toBeChecked();
});

it.each([true, false])(
"toggles an injected future source from %s and preserves settings",
async (enabled) => {
const onUpdate = vi.fn();
const settings = {
...SETTINGS,
notifications: { sources: { timer_expired: false, future_source: enabled } },
};
renderSettings(onUpdate, settings, [
...SOURCES,
{ key: "future_source", label: "A future notification" },
]);

await userEvent.click(screen.getByLabelText("A future notification"));

expect(onUpdate).toHaveBeenCalledWith({
...settings,
notifications: { sources: { timer_expired: false, future_source: !enabled } },
});
},
);

it("does not invent notification rows before the registry loads", () => {
renderSettings(vi.fn(), SETTINGS, []);

expect(screen.queryByLabelText("Timer expired")).not.toBeInTheDocument();
expect(screen.getByLabelText("Max focuses")).toHaveValue(5);
expect(screen.getByLabelText("Always on Top")).not.toBeChecked();
expect(screen.getByLabelText("Max pen size")).toHaveValue(320);
expect(screen.getByLabelText("Debug Overlay")).not.toBeChecked();
});
});
12 changes: 4 additions & 8 deletions src/components/SettingsWindow.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import type React from "react";
import { useState } from "react";
import type { NotificationSourceDescriptor } from "../types/generated/NotificationSourceDescriptor";
import type { MonitorInfo } from "../types/monitor";
import type { Settings } from "../types/settings";

const PEN_SIZE_RANGE = { min: 160, max: 960 } as const;

const NOTIFICATION_SOURCES = [
{ key: "timer_expired", label: "Timer expired" },
{ key: "task_timer_expired", label: "Task timer expired" },
{ key: "focuses_over_cap", label: "Too many focuses" },
{ key: "tasks_over_cap", label: "Too many tasks in a focus" },
] as const;

interface SettingsWindowProps {
readonly settings: Settings | null;
readonly monitors: MonitorInfo[];
readonly notificationSources: readonly NotificationSourceDescriptor[];
readonly debugOverlay: boolean;
readonly devtoolsOpen: boolean;
readonly onUpdate: (next: Settings) => void;
Expand Down Expand Up @@ -94,6 +89,7 @@ function toggleDisplayIndex(indices: readonly number[], idx: number): number[] {
export function SettingsWindow({
settings,
monitors,
notificationSources,
debugOverlay,
devtoolsOpen,
onUpdate,
Expand Down Expand Up @@ -182,7 +178,7 @@ export function SettingsWindow({

<section className="settings-section">
<h2 className="settings-section-title">Notifications</h2>
{NOTIFICATION_SOURCES.map(({ key, label }) => (
{notificationSources.map(({ key, label }) => (
<ToggleRow
key={key}
label={label}
Expand Down
76 changes: 76 additions & 0 deletions src/hooks/useSettingsWindow.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { act, renderHook, waitFor } from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { getDebugOverlay, getDevtoolsOpen } from "../api/debug";
import { getMonitors } from "../api/monitors";
import { getSettings, listNotificationSources, updateSettings } from "../api/settings";
import type { Settings } from "../types/settings";
import { useSettingsWindow } from "./useSettingsWindow";

vi.mock("../api/settings", () => ({
getSettings: vi.fn(),
listNotificationSources: vi.fn(),
updateSettings: vi.fn(),
}));
vi.mock("../api/monitors", () => ({ getMonitors: vi.fn() }));
vi.mock("../api/debug", () => ({
getDebugOverlay: vi.fn(),
getDevtoolsOpen: vi.fn(),
setDebugOverlay: vi.fn(),
toggleDevtools: vi.fn(),
}));

const SETTINGS: Settings = {
caps: { max_focuses: 5, max_tasks_per_focus: 7 },
notifications: { sources: { timer_expired: false } },
widget: { always_on_top: false, confirm_delete: true },
displays: { enabled_indices: [0] },
agents: { enabled: false },
pens: { max_size: 320 },
timers: { saved_minutes: [15] },
};

describe("useSettingsWindow notification registry", () => {
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(getSettings).mockResolvedValue(SETTINGS);
vi.mocked(getMonitors).mockResolvedValue([{ idx: 0, label: "Primary" }]);
vi.mocked(getDebugOverlay).mockResolvedValue(true);
vi.mocked(getDevtoolsOpen).mockResolvedValue(false);
vi.mocked(updateSettings).mockResolvedValue();
});

it("loads arbitrary descriptors and sends source edits through the existing settings workflow", async () => {
const sources = [{ key: "future_source", label: "A future notification" }];
vi.mocked(listNotificationSources).mockResolvedValue(sources);
const { result } = renderHook(() => useSettingsWindow());
await waitFor(() => expect(result.current.settings).toEqual(SETTINGS));

expect(result.current.notificationSources).toEqual(sources);
expect(result.current.monitors).toEqual([{ idx: 0, label: "Primary" }]);
expect(result.current.debugOverlay).toBe(true);
const next = {
...SETTINGS,
notifications: { sources: { ...SETTINGS.notifications.sources, future_source: false } },
};

act(() => result.current.update(next));

expect(updateSettings).toHaveBeenCalledWith(next);
expect(result.current.settings).toEqual(next);
});

it("keeps the other settings available when the registry read fails", async () => {
const error = new Error("unavailable");
vi.mocked(listNotificationSources).mockRejectedValue(error);
const report = vi.spyOn(console, "error").mockImplementation(() => {});
try {
const { result } = renderHook(() => useSettingsWindow());

await waitFor(() => expect(result.current.settings).toEqual(SETTINGS));

expect(result.current.notificationSources).toEqual([]);
} finally {
report.mockRestore();
}
});
});
Loading
Loading