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[mobile]: restructure push notification navigation (#3633)
Peter Chinmanc88b543859c4
diff --git a/js/app/package.json b/js/app/package.jsonindex d12b63fd01..55241aa8fe 100644--- a/js/app/package.json+++ b/js/app/package.json@@ -35,7 +35,7 @@"@floating-ui/dom": "^1.7.4","@fontsource-variable/inter": "^5.2.8","@fontsource-variable/roboto-mono": "^5.2.8",- "@inkibra/tauri-plugins": "git+https://github.com/macro-inc/tauri-plugins.git#61520093d5c7fcd60a2ed354dc150ca9556519a4",+ "@inkibra/tauri-plugins": "git+https://github.com/macro-inc/tauri-plugins.git#26537c8a46bb8424f9cf4021d08aa76aa7cd66ef","@kobalte/core": "^0.13.11","@leeoniya/ufuzzy": "^1.0.19","@lexical/history": "^0.32.1",diff --git a/js/app/packages/app/component/PendingNotificationNavigationEffect.tsx b/js/app/packages/app/component/PendingNotificationNavigationEffect.tsxnew file mode 100644index 0000000000..54fabf6417--- /dev/null+++ b/js/app/packages/app/component/PendingNotificationNavigationEffect.tsx@@ -0,0 +1,36 @@+import { globalSplitManager } from '@app/signal/splitLayout';+import { toast } from '@core/component/Toast/Toast';+import {+ type NotificationSource,+ openNotificationFromId,+ pendingNotificationNavigationId,+ setPendingNotificationNavigationId,+} from '@notifications';+import { createEffect, on } from 'solid-js';++export function usePendingNotificationNavigationEffect(+ notificationSource: NotificationSource+) {+ createEffect(+ on(+ [pendingNotificationNavigationId, globalSplitManager],+ ([notificationId, layoutManager]) => {+ if (!notificationId) return;+ if (!layoutManager) return;++ setPendingNotificationNavigationId(undefined);++ void openNotificationFromId(+ notificationId,+ layoutManager,+ notificationSource+ ).match(+ () => {},+ () => {+ toast.failure('Failed to open notification.');+ }+ );+ }+ )+ );+}diff --git a/js/app/packages/app/component/Root.tsx b/js/app/packages/app/component/Root.tsxindex 412d4d9b83..944a77bf1b 100644--- a/js/app/packages/app/component/Root.tsx+++ b/js/app/packages/app/component/Root.tsx@@ -83,6 +83,7 @@ import { makeEmailAuthComponents } from './EmailAuth';import { GlobalAppStateProvider } from './GlobalAppState';import { Layout } from './Layout';import { SearchProvider } from './next-soup/search-context';+import { usePendingNotificationNavigationEffect } from './PendingNotificationNavigationEffect';import { ReactiveFavicon } from './ReactiveFavicon';import { LAYOUT_ROUTE } from './split-layout/SplitLayoutRoute';import { TeamInviteAcceptance } from './TeamInviteAcceptance';@@ -409,6 +410,7 @@ function ConfiguredGlobalAppStateProvider(props: ParentProps) {}const blockOrchestrator = createBlockOrchestrator();+ usePendingNotificationNavigationEffect(notificationSource);return (<GlobalAppStateProviderdiff --git a/js/app/packages/app/component/split-layout/componentRegistry.tsx b/js/app/packages/app/component/split-layout/componentRegistry.tsxindex fbbb464e57..7e31556372 100644--- a/js/app/packages/app/component/split-layout/componentRegistry.tsx+++ b/js/app/packages/app/component/split-layout/componentRegistry.tsx@@ -15,7 +15,6 @@ import {} from '@core/constant/featureFlags';import { useUserContext } from '@core/context/user';import type { ViewId } from '@core/types/view';-import NotificationRoute from '@notifications/components/NotificationRoute';import { useAutomationEntities } from '@queries/agent-schedule/entities';import { type Component, type JSXElement, lazy, onMount, Show } from 'solid-js';import { EmailCompose } from '../../../block-email/component/compose/Compose';@@ -297,7 +296,6 @@ registerComponent(lazy(() => import('@app/component/import-linear/ImportLinear')));registerComponent('settings', () => <SettingsPanelComponentWrapper />);-registerComponent('notification', () => <NotificationRoute />);const NewOnboarding = lazy(() => import('@app/component/onboarding/onboarding'));diff --git a/js/app/packages/notifications/components/NotificationRoute.tsx b/js/app/packages/notifications/components/NotificationRoute.tsxdeleted file mode 100644index 95e87f9d03..0000000000--- a/js/app/packages/notifications/components/NotificationRoute.tsx+++ /dev/null@@ -1,73 +0,0 @@-import { useGlobalNotificationSource } from '@app/component/GlobalAppState';-import { useSplitPanelOrThrow } from '@app/component/split-layout/layoutUtils';-import { LIST_VIEW_ID } from '@app/constants/list-views';-import { globalSplitManager } from '@app/signal/splitLayout';-import { LoadingBlock } from '@core/component/LoadingBlock';-import { toast } from '@core/component/Toast/Toast';-import { openNotificationFromId } from '@notifications/notification-navigation';-import { logger } from '@observability';-import { useSearchParams } from '@solidjs/router';-import { createEffect, onCleanup, onMount } from 'solid-js';--export default function NotificationRoute() {- const split = useSplitPanelOrThrow();- const [searchParams] = useSearchParams();-- const getNotificationId = (): string | undefined => {- const raw = searchParams.notificationId;- if (typeof raw === 'string') return raw;- if (Array.isArray(raw) && typeof raw[0] === 'string') return raw[0];- return undefined;- };-- const replaceWithUnifiedList = (cause?: Error) => {- logger.error('Failed to open notification.', { cause });- toast.failure('Failed to open notification.');- split.handle.replace({- next: { type: 'component', id: LIST_VIEW_ID.inbox },- mergeHistory: true,- });- };-- // Give the router a tick to populate params before falling back to unified-list- onMount(() => {- const timeout = window.setTimeout(() => {- const notificationId = getNotificationId();- if (!notificationId) {- replaceWithUnifiedList(new Error('No notification ID found.'));- }- }, 0);- onCleanup(() => window.clearTimeout(timeout));- });-- const notificationSource = useGlobalNotificationSource();-- createEffect(() => {- const notificationId = getNotificationId();- const layoutManager = globalSplitManager();- if (!notificationId) return;- if (!layoutManager) return;-- openNotificationFromId(- notificationId,- layoutManager,- notificationSource- ).match(- () => {- // We only use this route as a "bridge" from external navigation into the split layout.- // At narrowWidths, openWithSplit replaces this split in-place, so content()- // will have changed by the time we get here — closing would navigate- // away from the notification. Only close if we're still the bridge.- const current = split.handle.content();- if (current.type === 'component' && current.id === 'notification') {- split.handle.close();- }- },- (err) => {- replaceWithUnifiedList(new Error(err.tag));- }- );- });-- return <LoadingBlock />;-}diff --git a/js/app/packages/notifications/index.ts b/js/app/packages/notifications/index.tsindex 7c5b3af8d4..8d81a66659 100644--- a/js/app/packages/notifications/index.ts+++ b/js/app/packages/notifications/index.ts@@ -47,6 +47,11 @@ export {openNotificationFromId,openSingleStackNotification,} from './notification-navigation';+export {+ pendingNotificationNavigationId,+ setPendingNotificationNavigationId,+ triggerNotificationNavigation,+} from './notification-navigation-intent';export type {PlatformNotificationData,PlatformNotificationHandle,diff --git a/js/app/packages/notifications/notification-navigation-intent.ts b/js/app/packages/notifications/notification-navigation-intent.tsnew file mode 100644index 0000000000..e29c39298c--- /dev/null+++ b/js/app/packages/notifications/notification-navigation-intent.ts@@ -0,0 +1,10 @@+import { createSignal } from 'solid-js';++export const [+ pendingNotificationNavigationId,+ setPendingNotificationNavigationId,+] = createSignal<string | undefined>();++export function triggerNotificationNavigation(notificationId: string) {+ setPendingNotificationNavigationId(notificationId);+}diff --git a/js/app/packages/tauri/src/PushNotification.tsx b/js/app/packages/tauri/src/PushNotification.tsxindex d3082bfbb8..0fed9e5664 100644--- a/js/app/packages/tauri/src/PushNotification.tsx+++ b/js/app/packages/tauri/src/PushNotification.tsx@@ -10,6 +10,7 @@ import {import {type PlatformNotificationInterface,PlatformNotificationProvider,+ triggerNotificationNavigation,} from '@notifications';import { invalidateUserNotifications } from '@queries/notification/user-notifications';import { notificationServiceClient } from '@service-notification/client';@@ -21,10 +22,14 @@ import {createSignal,type JSX,} from 'solid-js';-import { triggerNavigation } from './navigation';import { createTauriNotificationInterface } from './notification';import { useExpectTauri } from './TauriProvider';+function getNotificationId(payload: Record<string, unknown>) {+ const value = payload.notificationId;+ return typeof value === 'string' && value.length > 0 ? value : undefined;+}+function usePushNotifications(deviceType: 'android' | 'ios',onPushNotification?: (event: NotificationEvent) => void@@ -121,9 +126,16 @@ function usePushNotifications(console.error);+ const [notificationWatchStarted, setNotificationWatchStarted] =+ createSignal(false);createEffect(() => {if (!registrationResult()?.success || !onPushNotification) return;- watchNotifications(onPushNotification).then(console.info);+ if (notificationWatchStarted()) return;++ setNotificationWatchStarted(true);+ void watchNotifications(onPushNotification).catch(() => {+ setNotificationWatchStarted(false);+ });});return {@@ -159,18 +171,17 @@ export function MaybePushNotificationRegistration(props: {}const push = usePushNotifications(os, (event) => {- const notificationId: string | undefined = event.payload.notificationId;+ const notificationId = getNotificationId(event.payload);const tapped =event.type === 'BACKGROUND_TAP' || event.type === 'FOREGROUND_TAP';+// Only navigate on explicit user interaction.if (!tapped) return;if (!notificationId) return;invalidateUserNotifications();- triggerNavigation(- `/component/notification?notificationId=${notificationId}`- );+ triggerNotificationNavigation(notificationId);});// now we compose the standard tauri notif plugin with the push notification plugindiff --git a/js/app/packages/tauri/src/navigation.ts b/js/app/packages/tauri/src/navigation.tsindex 9b2d3e81be..b6b86da310 100644--- a/js/app/packages/tauri/src/navigation.ts+++ b/js/app/packages/tauri/src/navigation.ts@@ -5,65 +5,22 @@ import { createEffect, onCleanup } from 'solid-js';type NavigateEvent = {path: string;query: string;- notificationId?: string;};-let registeredNavigate: ((path: string) => void) | null = null;-let pendingNavigation: string | null = null;--/**- * Register a navigate function to be called from outside the router context.- * Called by useTauriNavigationEffect when the router is ready.- * Drains any navigation that was buffered before the router was ready.- */-function registerNavigate(fn: (path: string) => void) {- registeredNavigate = fn;- if (pendingNavigation) {- const path = pendingNavigation;- pendingNavigation = null;- fn(path);- }-}--/**- * Trigger navigation from outside the router context.- * Used by PushNotification to navigate when a notification is tapped.- * If the router is not yet ready, buffers the path for replay on mount.- */-export function triggerNavigation(path: string) {- if (registeredNavigate) {- registeredNavigate(path);- } else {- console.warn(- `[navigation] triggerNavigation: router not ready, buffering path ${path}`- );- pendingNavigation = path;- }-}-/// this must be used as a child of routerexport function useTauriNavigationEffect() {const navigate = useNavigate();- registerNavigate(navigate);-createEffect(() => {let unsubscribe: () => void | undefined;async function inner() {unsubscribe = await listen<NavigateEvent>('navigate', (ev) => {console.info({ ev });- if (ev.payload.notificationId) {- navigate(- `/component/notification?notificationId=${ev.payload.notificationId}`- );- } else {- if (ev.payload.query) {- navigate(`${ev.payload.path}?${ev.payload.query}`);- } else {- navigate(ev.payload.path);- }- }+ const path = ev.payload.query+ ? `${ev.payload.path}?${ev.payload.query}`+ : ev.payload.path;+ navigate(path);});}inner();diff --git a/js/app/tauri/Cargo.lock b/js/app/tauri/Cargo.lockindex 99d5bc6f4b..a71ba13f9a 100644--- a/js/app/tauri/Cargo.lock+++ b/js/app/tauri/Cargo.lock@@ -5404,7 +5404,7 @@ dependencies = [[[package]]name = "tauri-plugin-auth"version = "0.1.0"-source = "git+https://github.com/macro-inc/tauri-plugins?rev=61520093d5c7fcd60a2ed354dc150ca9556519a4#61520093d5c7fcd60a2ed354dc150ca9556519a4"+source = "git+https://github.com/macro-inc/tauri-plugins?rev=26537c8a46bb8424f9cf4021d08aa76aa7cd66ef#26537c8a46bb8424f9cf4021d08aa76aa7cd66ef"dependencies = ["serde","tauri",@@ -5575,7 +5575,7 @@ dependencies = [[[package]]name = "tauri-plugin-notifications"version = "0.1.0"-source = "git+https://github.com/macro-inc/tauri-plugins?rev=61520093d5c7fcd60a2ed354dc150ca9556519a4#61520093d5c7fcd60a2ed354dc150ca9556519a4"+source = "git+https://github.com/macro-inc/tauri-plugins?rev=26537c8a46bb8424f9cf4021d08aa76aa7cd66ef#26537c8a46bb8424f9cf4021d08aa76aa7cd66ef"dependencies = ["serde","tauri",diff --git a/js/app/tauri/src-tauri/Cargo.toml b/js/app/tauri/src-tauri/Cargo.tomlindex 667efd3d5a..6ba754aff6 100644--- a/js/app/tauri/src-tauri/Cargo.toml+++ b/js/app/tauri/src-tauri/Cargo.toml@@ -57,7 +57,7 @@ tauri-plugin-notification = "2"macro_bundle_updater_plugin = { path = "../macro_bundle_updater_plugin" }navigation_plugin = { path = "../navigation_plugin" }tauri-plugin-device-info = "1.0.1"-tauri-plugin-notifications = { git = "https://github.com/macro-inc/tauri-plugins", rev = "61520093d5c7fcd60a2ed354dc150ca9556519a4" }+tauri-plugin-notifications = { git = "https://github.com/macro-inc/tauri-plugins", rev = "26537c8a46bb8424f9cf4021d08aa76aa7cd66ef" }tauri-plugin-os = "2"tauri-plugin-virtual-keyboard = { git = "https://github.com/voxelbee/tauri-plugin-virtual-keyboard", branch = "main" }@@ -66,7 +66,7 @@ tauri-plugin-virtual-keyboard = { git = "https://github.com/voxelbee/tauri-plugitauri-plugin-single-instance = { version = "2", features = ["deep-link"] }[target.'cfg(any(target_os = "android", target_os = "ios"))'.dependencies]-tauri-plugin-auth = { git = "https://github.com/macro-inc/tauri-plugins", rev = "61520093d5c7fcd60a2ed354dc150ca9556519a4" }+tauri-plugin-auth = { git = "https://github.com/macro-inc/tauri-plugins", rev = "26537c8a46bb8424f9cf4021d08aa76aa7cd66ef" }tauri-plugin-haptics = "2"[target.'cfg(target_os = "ios")'.dependencies]diff --git a/js/bun.lock b/js/bun.lockindex 34867994c4..102287cfcb 100644--- a/js/bun.lock+++ b/js/bun.lock@@ -23,7 +23,7 @@"@floating-ui/dom": "^1.7.4","@fontsource-variable/inter": "^5.2.8","@fontsource-variable/roboto-mono": "^5.2.8",- "@inkibra/tauri-plugins": "git+https://github.com/macro-inc/tauri-plugins.git#61520093d5c7fcd60a2ed354dc150ca9556519a4",+ "@inkibra/tauri-plugins": "git+https://github.com/macro-inc/tauri-plugins.git#26537c8a46bb8424f9cf4021d08aa76aa7cd66ef","@kobalte/core": "^0.13.11","@leeoniya/ufuzzy": "^1.0.19","@lexical/history": "^0.32.1",@@ -824,7 +824,7 @@"@img/sharp-win32-x64": ["@img/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-+29YMsqY2/9eFEiW93eqWnuLcWcufowXewwSNIT6UwZdUUCrM3oFjMWH/Z6/TMmb4hlFenmfAVbpWeup2jryCw=="],- "@inkibra/tauri-plugins": ["@inkibra/tauri-plugins@github:macro-inc/tauri-plugins#6152009", { "dependencies": { "react": "^18.3.1", "react-dom": "^18.3.1" } }, "macro-inc-tauri-plugins-6152009", "sha512-XLN+niDA9BkzrxiZqBjYf+DL4TLoMIcI80ypCowacVfrfAjWt0qLwLkzWVUXjD7k3v0DB/G+BP4OLJNkGygHIw=="],+ "@inkibra/tauri-plugins": ["@inkibra/tauri-plugins@github:macro-inc/tauri-plugins#26537c8", { "dependencies": { "react": "^18.3.1", "react-dom": "^18.3.1" } }, "macro-inc-tauri-plugins-26537c8", "sha512-6p5xQAkS6Uw6J8Uh0vlj6MjKZXWps5E1Gu0hciBFq1E2BfPBZAgdeeafKnR3diNb4SXWK0JML49nAr+o5PhwKw=="],"@inquirer/external-editor": ["@inquirer/[email protected]", "", { "dependencies": { "chardet": "^2.1.1", "iconv-lite": "^0.7.0" }, "peerDependencies": { "@types/node": ">=18" }, "optionalPeers": ["@types/node"] }, "sha512-RWbSrDiYmO4LbejWY7ttpxczuwQyZLBUyygsA9Nsv95hpzUWwnNTVQmAq3xuh7vNwCp07UTmE5i11XAEExx4RA=="],