Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(e2e): route notification bell to app server

Louis Beaumontc4b89bd487d5
diff --git a/apps/screenpipe-app-tauri/components/notification-bell.tsx b/apps/screenpipe-app-tauri/components/notification-bell.tsx
index 806c45d2a..6ef233733 100644
--- a/apps/screenpipe-app-tauri/components/notification-bell.tsx
+++ b/apps/screenpipe-app-tauri/components/notification-bell.tsx
@@ -18,7 +18,7 @@ import {
} from "@/components/ui/popover";
import { useRouter } from "next/navigation";
import { showChatWithPrefill } from "@/lib/chat-utils";
-import { localFetch } from "@/lib/api";
+import { invoke } from "@tauri-apps/api/core";
interface NotificationEntry {
id: string;
@@ -30,6 +30,27 @@ interface NotificationEntry {
read: boolean;
}
+interface AppServerConfig {
+ port: number;
+}
+
+let appServerBaseUrl: Promise<string> | null = null;
+
+async function getAppServerBaseUrl(): Promise<string> {
+ appServerBaseUrl ??= invoke<AppServerConfig>("get_app_server_config")
+ .then((config) => `http://localhost:${config.port || 11435}`)
+ .catch(() => "http://localhost:11435");
+ return appServerBaseUrl;
+}
+
+async function notificationFetch(
+ path: string,
+ init?: RequestInit,
+): Promise<Response> {
+ const baseUrl = await getAppServerBaseUrl();
+ return fetch(`${baseUrl}${path.startsWith("/") ? path : `/${path}`}`, init);
+}
+
async function openNotificationLink(href: string) {
const raw = href.trim();
if (!raw) return;
@@ -81,7 +102,7 @@ export function NotificationBell() {
const loadHistory = useCallback(async () => {
try {
- const res = await localFetch("/notifications");
+ const res = await notificationFetch("/notifications");
if (res.ok) {
const entries: NotificationEntry[] = await res.json();
setHistory(entries);
@@ -102,7 +123,7 @@ export function NotificationBell() {
const markAllRead = async () => {
setHistory((prev) => prev.map((n) => ({ ...n, read: true })));
try {
- await localFetch("/notifications", { method: "POST" });
+ await notificationFetch("/notifications", { method: "POST" });
} catch {}
};
@@ -110,7 +131,7 @@ export function NotificationBell() {
posthog.capture("notification_bell_clear_all", { count: history.length });
setHistory([]);
try {
- await localFetch("/notifications", { method: "DELETE" });
+ await notificationFetch("/notifications", { method: "DELETE" });
} catch {}
};
@@ -123,7 +144,7 @@ export function NotificationBell() {
setHistory((prev) => prev.filter((n) => n.id !== id));
if (expandedId === id) setExpandedId(null);
try {
- await localFetch(`/notifications/${encodeURIComponent(id)}`, { method: "DELETE" });
+ await notificationFetch(`/notifications/${encodeURIComponent(id)}`, { method: "DELETE" });
} catch {}
};
@@ -143,6 +164,7 @@ export function NotificationBell() {
onOpenChange={(o) => {
setOpen(o);
if (o) {
+ void loadHistory();
posthog.capture("notification_bell_opened", {
unread_count: unreadCount,
total_count: history.length,
diff --git a/apps/screenpipe-app-tauri/e2e/README.md b/apps/screenpipe-app-tauri/e2e/README.md
index 7329a1226..55b7c9642 100644
--- a/apps/screenpipe-app-tauri/e2e/README.md
+++ b/apps/screenpipe-app-tauri/e2e/README.md
@@ -57,6 +57,9 @@ controller is unavailable, so it never fails the default CI lane.
```
Uses `.e2e/` as isolated data dir; real data is never touched.
+The E2E launcher also moves the app-local focus/notification server to
+`SCREENPIPE_FOCUS_PORT` (default `11436`) so tests can exercise `/notify` and
+`/notifications` without colliding with a developer's production app on 11435.
## Running locally on Windows
diff --git a/apps/screenpipe-app-tauri/e2e/specs/windows-user-journey.spec.ts b/apps/screenpipe-app-tauri/e2e/specs/windows-user-journey.spec.ts
index a1929fd6d..52660b29c 100644
--- a/apps/screenpipe-app-tauri/e2e/specs/windows-user-journey.spec.ts
+++ b/apps/screenpipe-app-tauri/e2e/specs/windows-user-journey.spec.ts
@@ -18,23 +18,13 @@ import { closeWindow, invokeOrThrow, waitForWindowHandle } from "../helpers/taur
const isWindows = process.platform === "win32";
const SEARCH_QUERY = "screenpipe windows ux journey";
const SEARCH_INPUT_SELECTOR = 'input[placeholder*="search memory"]';
+const APP_SERVER_PORT = Number(process.env.SCREENPIPE_FOCUS_PORT ?? "11436");
+const APP_SERVER_BASE_URL = `http://127.0.0.1:${APP_SERVER_PORT}`;
-interface LocalApiConfig {
- key: string | null;
- port: number;
- auth_enabled: boolean;
-}
-
-async function localApiRequest(
+async function appServerRequest(
path: string,
options: { method?: string; headers?: Record<string, string>; body?: string } = {},
): Promise<{ ok: boolean; status: number; text: string }> {
- const config = await invokeOrThrow<LocalApiConfig>("get_local_api_config");
- const headers = { ...(options.headers ?? {}) };
- if (config.auth_enabled && config.key && !headers.Authorization) {
- headers.Authorization = `Bearer ${config.key}`;
- }
-
return (await browser.executeAsync(
(
url: string,
@@ -53,13 +43,13 @@ async function localApiRequest(
}),
);
},
- `http://127.0.0.1:${config.port}${path}`,
- { ...options, headers },
+ `${APP_SERVER_BASE_URL}${path}`,
+ options,
)) as { ok: boolean; status: number; text: string };
}
async function postNotification(id: string, title: string, body: string): Promise<void> {
- const response = await localApiRequest("/notify", {
+ const response = await appServerRequest("/notify", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
@@ -642,7 +632,7 @@ describe("Windows user journey", function () {
if (initialDisplayChanges !== null) {
await setSwitchChecked(displayChangesSelector, initialDisplayChanges).catch(() => {});
}
- await localApiRequest(`/notifications/${encodeURIComponent(notificationId)}`, {
+ await appServerRequest(`/notifications/${encodeURIComponent(notificationId)}`, {
method: "DELETE",
}).catch(() => {});
}
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
index 9469558d1..9bdc77c91 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
@@ -509,6 +509,18 @@ pub async fn get_local_api_config(app_handle: tauri::AppHandle) -> serde_json::V
fallback_local_api_config(crate::store::resolved_api_auth_key())
}
+/// Get the app-local focus/notification server port.
+#[tauri::command]
+#[specta::specta]
+pub fn get_app_server_config() -> serde_json::Value {
+ let port = std::env::var("SCREENPIPE_FOCUS_PORT")
+ .ok()
+ .and_then(|v| v.parse::<u16>().ok())
+ .unwrap_or(11435);
+
+ serde_json::json!({ "port": port })
+}
+
/// Pure JSON shape used by the cold-spawn fallback. Extracted so the contract
/// is covered by a unit test without needing a tauri::AppHandle. Port is the
/// well-known default because the server hasn't bound yet — the UI will refresh