(n: SocketNotification)
| 754 | // hello so the server scopes delivery; here we re-check the active session per |
| 755 | // notification (it can change between queue and delivery) before acting. |
| 756 | const handleNotification = async (n: SocketNotification): Promise<boolean> => { |
| 757 | const requestedSessionId = getSessionId(api) |
| 758 | const generation = getRpcGeneration() |
| 759 | // A session-scoped notification only applies while we're viewing that |
| 760 | // session; global (session-less) ones always apply. Returning false leaves |
| 761 | // it unacked so a TUI on the right session (or a later switch back) still |
| 762 | // gets it. |
| 763 | if (n.sessionId && requestedSessionId && n.sessionId !== requestedSessionId) { |
| 764 | return false |
| 765 | } |
| 766 | if (n.type === "toast") { |
| 767 | const p = n.payload |
| 768 | showToast(api, { |
| 769 | message: String(p.message ?? ""), |
| 770 | variant: (p.variant as "info" | "warning" | "error" | "success") ?? "info", |
| 771 | durationOverrideMs: |
| 772 | typeof p.duration === "number" && Number.isFinite(p.duration) |
| 773 | ? p.duration |
| 774 | : undefined, |
| 775 | }) |
| 776 | return true |
| 777 | } |
| 778 | if (n.type !== "action") return false |
| 779 | const action = n.payload?.action |
| 780 | const stillActive = () => |
| 781 | getRpcGeneration() === generation && getSessionId(api) === requestedSessionId |
| 782 | if (action === "show-status-dialog") { |
| 783 | return stillActive() && (await showStatusDialog(api, requestedSessionId)) |
| 784 | } |
| 785 | if (action === "show-recomp-dialog") { |
| 786 | return stillActive() && (await showRecompDialog(api, requestedSessionId)) |
| 787 | } |
| 788 | if (action === "show-upgrade-dialog") { |
| 789 | const resume = |
| 790 | n.payload?.resume === true |
| 791 | ? { |
| 792 | stagedCount: Number(n.payload?.stagedCount ?? 0), |
| 793 | stagedThrough: Number(n.payload?.stagedThrough ?? 0), |
| 794 | } |
| 795 | : undefined |
| 796 | return stillActive() && showUpgradeDialog(api, resume, requestedSessionId) |
| 797 | } |
| 798 | if (action === "show-embed-dialog") { |
| 799 | return stillActive() && (await showEmbedDialog(api, requestedSessionId)) |
| 800 | } |
| 801 | if (action === "show-flush-dialog") { |
| 802 | const flushMsg = String(n.payload?.message ?? "Flushed.") |
| 803 | return stillActive() && showResultDialog(api, "Flush", flushMsg) |
| 804 | } |
| 805 | if (action === "show-result-dialog") { |
| 806 | const title = String(n.payload?.title ?? "Magic Context") |
| 807 | const body = String(n.payload?.message ?? "") |
| 808 | return stillActive() && showResultDialog(api, title, body) |
| 809 | } |
| 810 | return false |
| 811 | } |
| 812 | |
| 813 | startNotificationSocket({ |
nothing calls this directly
no test coverage detected