Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(desktop): recover from booking links that strand the app (#9538)
Eric Hayes71454defab30
diff --git a/apps/web/src/lib/core/util/macroAppUrl.test.ts b/apps/web/src/lib/core/util/macroAppUrl.test.tsindex 8f689ed76b..747eeb5d29 100644--- a/apps/web/src/lib/core/util/macroAppUrl.test.ts+++ b/apps/web/src/lib/core/util/macroAppUrl.test.ts@@ -19,6 +19,12 @@ describe('parseInternalAppLink', () => {).toEqual({ path: '/component/abc', query: 'foo=bar' });});+ it('keeps the fragment of a booking receipt link', () => {+ expect(+ parseInternalAppLink('https://dev.macro.com/app/booking/abc#token')+ ).toEqual({ path: '/booking/abc', query: '', fragment: 'token' });+ });+it('maps a bare /app path to the router root', () => {expect(parseInternalAppLink('https://dev.macro.com/app')).toEqual({path: '/',diff --git a/apps/web/src/lib/core/util/macroAppUrl.ts b/apps/web/src/lib/core/util/macroAppUrl.tsindex 47ccf989d8..5dfe68950e 100644--- a/apps/web/src/lib/core/util/macroAppUrl.ts+++ b/apps/web/src/lib/core/util/macroAppUrl.ts@@ -49,12 +49,14 @@ export function isValidMacroAppHostname(hostname: string): boolean {type InternalAppLink = {path: string;query: string;+ fragment?: string;};/*** Parses an absolute URL pointing at the Macro web app (e.g.- * `https://macro.com/app/channel/<id>?message=<id>`) into a router path and- * query. Returns null for anything that is not a Macro `/app` URL.+ * `https://macro.com/app/channel/<id>?message=<id>`) into a router path, query+ * and fragment; a booking receipt link keeps its private token in the fragment.+ * Returns null for anything that is not a Macro `/app` URL.** The `/app` prefix is stripped because the Tauri router uses `/` as its* base (mirrors `MacroScheme::from_url` on the Rust side).@@ -76,5 +78,6 @@ export function parseInternalAppLink(url: string): InternalAppLink | null {return {path: pathname.slice('/app'.length) || '/',query: parsed.search.slice(1),+ fragment: parsed.hash.slice(1) || undefined,};}diff --git a/apps/web/src/lib/tauri/macroLinkInterceptor.test.ts b/apps/web/src/lib/tauri/macroLinkInterceptor.test.tsindex 139abf58e7..77a5ceb419 100644--- a/apps/web/src/lib/tauri/macroLinkInterceptor.test.ts+++ b/apps/web/src/lib/tauri/macroLinkInterceptor.test.ts@@ -37,6 +37,18 @@ describe('openMacroLinkInApp', () => {});});+ it('keeps the private token of a booking receipt link', () => {+ vi.mocked(isTauri).mockReturnValue(true);+ expect(openMacroLinkInApp('https://macro.com/app/booking/123#token')).toBe(+ true+ );+ expect(emit).toHaveBeenCalledWith('navigate', {+ path: '/booking/123',+ query: '',+ fragment: 'token',+ });+ });+it('leaves external links alone under Tauri', () => {vi.mocked(isTauri).mockReturnValue(true);expect(openMacroLinkInApp('https://github.com/macro-inc')).toBe(false);diff --git a/apps/web/src/lib/tauri/navigation.test.ts b/apps/web/src/lib/tauri/navigation.test.tsindex f43e556e95..ca917eb412 100644--- a/apps/web/src/lib/tauri/navigation.test.ts+++ b/apps/web/src/lib/tauri/navigation.test.ts@@ -37,7 +37,9 @@ import {import { useTauriNavigationEffect } from './navigation';let dispose: (() => void) | undefined;-let receive: (event: { payload: { path: string; query: string } }) => void;+let receive: (event: {+ payload: { path: string; query: string; fragment?: string };+}) => void;beforeEach(() => {vi.clearAllMocks();@@ -161,4 +163,24 @@ describe('native link session routing', () => {expect(mocks.navigate).toHaveBeenCalledWith('/task/123?view=comments');expect(mocks.setPostLoginRedirect).not.toHaveBeenCalled();});++ it('keeps the private token of a booking receipt link on desktop', () => {+ mocks.platform = 'macos';+ receive({+ payload: { path: '/booking/123', query: '', fragment: 'token' },+ });++ expect(mocks.navigate).toHaveBeenCalledWith('/booking/123#token');+ });++ it('retains a booking receipt token while Android checks the session', () => {+ receive({+ payload: { path: '/booking/123', query: '', fragment: 'token' },+ });++ expect(mocks.setPostLoginRedirect).toHaveBeenCalledWith(+ '/booking/123#token'+ );+ expect(mocks.navigate).toHaveBeenCalledWith('/');+ });});diff --git a/apps/web/src/lib/tauri/navigation.ts b/apps/web/src/lib/tauri/navigation.tsindex 85f311f4bc..7af250f26c 100644--- a/apps/web/src/lib/tauri/navigation.ts+++ b/apps/web/src/lib/tauri/navigation.ts@@ -14,6 +14,7 @@ import { registerMacroLinkInterceptor } from './macroLinkInterceptor';type NavigateEvent = {path: string;query: string;+ fragment?: string;};/// this must be used as a child of router@@ -44,9 +45,9 @@ export function useTauriNavigationEffect() {}return;}- const path = ev.payload.query- ? `${ev.payload.path}?${ev.payload.query}`- : ev.payload.path;+ const query = ev.payload.query ? `?${ev.payload.query}` : '';+ const fragment = ev.payload.fragment ? `#${ev.payload.fragment}` : '';+ const path = `${ev.payload.path}${query}${fragment}`;if (getNativeMobilePlatform() === 'android' &&ev.payload.path !== '/login'diff --git a/apps/web/src/routes/public-booking-shell.test.tsx b/apps/web/src/routes/public-booking-shell.test.tsxindex 4557b21267..1c12a606ef 100644--- a/apps/web/src/routes/public-booking-shell.test.tsx+++ b/apps/web/src/routes/public-booking-shell.test.tsx@@ -5,8 +5,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { PublicBookingShell } from './public-booking-shell';const platform = vi.hoisted(() => ({ native: true }));-vi.mock('@core/mobile/isNativeMobilePlatform', () => ({- isNativeMobilePlatform: () => platform.native,+vi.mock('@core/util/platform', () => ({+ isTauri: () => platform.native,}));beforeEach(() => {diff --git a/apps/web/src/routes/public-booking-shell.tsx b/apps/web/src/routes/public-booking-shell.tsxindex e359341838..6ee8441b22 100644--- a/apps/web/src/routes/public-booking-shell.tsx+++ b/apps/web/src/routes/public-booking-shell.tsx@@ -1,14 +1,17 @@import { hapticImpact } from '@core/mobile/haptics';-import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';+import { isTauri } from '@core/util/platform';import ArrowLeftIcon from '@icon/system/regular/arrow-left.svg';import { useNavigate } from '@solidjs/router';import { Button } from '@ui';import { type ParentProps, Show } from 'solid-js';-/** Native webviews have no browser chrome, including on unavailable pages. */+/**+ * Native webviews have no browser chrome, including on unavailable pages, and+ * these routes render outside the split layout that owns the app's history.+ */export function PublicBookingShell(props: ParentProps) {const navigate = useNavigate();- const showBack = () => isNativeMobilePlatform() && window.parent === window;+ const showBack = () => isTauri() && window.parent === window;return (<div class="min-h-0 flex-1 overflow-y-auto bg-page text-ink">diff --git a/apps/web/tauri/navigation_plugin/src/lib.rs b/apps/web/tauri/navigation_plugin/src/lib.rsindex 4f878467cb..daf04e490e 100644--- a/apps/web/tauri/navigation_plugin/src/lib.rs+++ b/apps/web/tauri/navigation_plugin/src/lib.rs@@ -43,6 +43,8 @@ enum NavigationOutput<'a> {pub struct NavigatePayload<'a> {pub path: &'a str,pub query: &'a str,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub fragment: Option<&'a str>,}#[derive(Clone, Copy, Debug)]@@ -248,6 +250,7 @@ impl MacroNavigationPlugin {NavigatePayload {path: scheme.path(),query: scheme.query().unwrap_or_default(),+ fragment: scheme.fragment(),},).log_and_consume();diff --git a/apps/web/tauri/navigation_plugin/src/scheme.rs b/apps/web/tauri/navigation_plugin/src/scheme.rsindex fa0fbb3278..d09a8f4083 100644--- a/apps/web/tauri/navigation_plugin/src/scheme.rs+++ b/apps/web/tauri/navigation_plugin/src/scheme.rs@@ -20,7 +20,7 @@ impl MacroScheme {Ok(Self(url))}/// turn a http(s) url into a macro scheme url- #[tracing::instrument(err, ret)]+ #[tracing::instrument(skip(url), err)]pub fn from_url(url: &Url) -> Result<Self, SchemeError> {let ("http" | "https" | "tauri") = url.scheme() else {return Err(SchemeError::InvalidScheme {@@ -29,7 +29,15 @@ impl MacroScheme {});};- let mut rest = url.fragment().unwrap_or(url.path()).trim_start_matches('/');+ // A webview URL carries its route in the fragment (`tauri://localhost/#/mail`).+ // Any other fragment belongs to the route, like a booking receipt's token.+ let (route, fragment) = match url.fragment() {+ Some(route) if route.starts_with('/') => route+ .split_once('#')+ .map_or((route, None), |(route, fragment)| (route, Some(fragment))),+ fragment => (url.path(), fragment),+ };+ let mut rest = route.trim_start_matches('/');// Mobile router uses '/' as base, so strip the 'app' prefix from universal linksif let Some(stripped) = rest.strip_prefix("app/") {rest = stripped;@@ -37,11 +45,12 @@ impl MacroScheme {rest = "";}let query = url.query();- let inner = match query {+ let mut inner = match query {Some(q) => format!("macro:///{rest}?{q}"),None => format!("macro:///{rest}"),}.parse::<Url>()?;+ inner.set_fragment(fragment);Ok(MacroScheme(inner))}}diff --git a/apps/web/tauri/navigation_plugin/src/tests.rs b/apps/web/tauri/navigation_plugin/src/tests.rsindex b0d033b940..5783e1dbf1 100644--- a/apps/web/tauri/navigation_plugin/src/tests.rs+++ b/apps/web/tauri/navigation_plugin/src/tests.rs@@ -285,6 +285,16 @@ fn popup_app_link_emits_once_and_never_creates_a_webview() {vec![serde_json::json!({"path": "/mail", "query": "view=all"})],);assert!(app.webview_windows().is_empty());++ received.lock().unwrap().clear();+ test_plugin().on_new_window(+ app.handle(),+ &Url::parse("https://macro.com/app/booking/id#token").unwrap(),+ );+ assert_eq!(+ *received.lock().unwrap(),+ vec![serde_json::json!({"path": "/booking/id", "query": "", "fragment": "token"})],+ );}#[test]@@ -388,6 +398,29 @@ fn from_url_extracts_path_and_query_from_universal_link() {assert_eq!(result.query(), Some("foo=bar"));}+#[test]+fn from_url_keeps_the_fragment_of_a_universal_link() {+ let url = Url::parse("https://macro.com/app/booking/id?foo=bar#token").unwrap();+ let result = MacroScheme::from_url(&url).unwrap();+ assert_eq!(result.path(), "/booking/id");+ assert_eq!(result.query(), Some("foo=bar"));+ assert_eq!(result.fragment(), Some("token"));+}++#[test]+fn from_url_reads_the_route_from_a_webview_fragment() {+ let url = Url::parse("tauri://localhost/#/app/booking/id#token").unwrap();+ let result = MacroScheme::from_url(&url).unwrap();+ assert_eq!(result.path(), "/booking/id");+ assert_eq!(result.fragment(), Some("token"));++ let url = Url::parse("tauri://localhost/#/mail?view=all").unwrap();+ let result = MacroScheme::from_url(&url).unwrap();+ assert_eq!(result.path(), "/mail");+ assert_eq!(result.query(), Some("view=all"));+ assert_eq!(result.fragment(), None);+}+#[test]fn from_url_strips_bare_app_path() {let url = Url::parse("https://macro.com/app").unwrap();diff --git a/apps/web/tauri/src-tauri/src/lib.rs b/apps/web/tauri/src-tauri/src/lib.rsindex 7e42086e1e..98cb37dc43 100644--- a/apps/web/tauri/src-tauri/src/lib.rs+++ b/apps/web/tauri/src-tauri/src/lib.rs@@ -683,6 +683,7 @@ fn emit_navigate_for_deep_link(url: Url, handle: &AppHandle) -> Result<(), Reporlet payload = NavigatePayload {path: macro_scheme.0.path(),query: macro_scheme.0.query().unwrap_or_default(),+ fragment: macro_scheme.0.fragment(),};// we send a navigate event instead of calling navigate directly// because navigate performs a full browser navigationdiff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.mdindex db06f99f25..1e4cce94fb 100644--- a/docs/agent-guide/calendar.md+++ b/docs/agent-guide/calendar.md@@ -229,7 +229,7 @@ show progress; the event summary and selected time stay visible. Choose anothertime preserves attendee input. Event booking pages do not show an All meetingslink back to the profile chooser.The private confirmation shows the meeting, date, timezone, location, and guest.-In the native iOS and Android apps, standalone booking and receipt pages keep a+In the native desktop, iOS and Android apps, standalone booking and receipt pages keep asticky **Back to Macro** button below the device's top safe-area inset. It returns tothe app through the router without reloading, including while the page is loadingor unavailable. Browser pages and embedded booking dialogs omit this button.