Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,8 @@ function MainApp() {
updaterState,
startUpdate,
dismissUpdate,
postUpdateNotice,
dismissPostUpdateNotice,
handleTestNotificationSound,
handleTestSystemNotification,
} = useUpdaterController({
Expand Down Expand Up @@ -1895,6 +1897,8 @@ function MainApp() {
updaterState,
onUpdate: startUpdate,
onDismissUpdate: dismissUpdate,
postUpdateNotice,
onDismissPostUpdateNotice: dismissPostUpdateNotice,
errorToasts,
onDismissErrorToast: dismissErrorToast,
latestAgentRuns,
Expand Down
11 changes: 10 additions & 1 deletion src/features/app/hooks/useUpdaterController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ export function useUpdaterController({
successSoundUrl,
errorSoundUrl,
}: Params) {
const { state: updaterState, startUpdate, checkForUpdates, dismiss } = useUpdater({
const {
state: updaterState,
startUpdate,
checkForUpdates,
dismiss,
postUpdateNotice,
dismissPostUpdateNotice,
} = useUpdater({
enabled,
onDebug,
});
Expand Down Expand Up @@ -112,6 +119,8 @@ export function useUpdaterController({
startUpdate,
checkForUpdates,
dismissUpdate: dismiss,
postUpdateNotice,
dismissPostUpdateNotice,
handleTestNotificationSound,
handleTestSystemNotification,
};
Expand Down
2 changes: 2 additions & 0 deletions src/features/layout/hooks/layoutNodes/buildPrimaryNodes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ export function buildPrimaryNodes(options: LayoutNodesOptions): PrimaryLayoutNod
state={options.updaterState}
onUpdate={options.onUpdate}
onDismiss={options.onDismissUpdate}
postUpdateNotice={options.postUpdateNotice}
onDismissPostUpdateNotice={options.onDismissPostUpdateNotice}
/>
);

Expand Down
7 changes: 6 additions & 1 deletion src/features/layout/hooks/layoutNodes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ import type {
TurnPlan,
WorkspaceInfo,
} from "../../../../types";
import type { UpdateState } from "../../../update/hooks/useUpdater";
import type {
PostUpdateNoticeState,
UpdateState,
} from "../../../update/hooks/useUpdater";
import type { TerminalSessionState } from "../../../terminal/hooks/useTerminalSession";
import type { TerminalTab } from "../../../terminal/hooks/useTerminalTabs";
import type { ErrorToast } from "../../../../services/toasts";
Expand Down Expand Up @@ -179,6 +182,8 @@ export type LayoutNodesOptions = {
updaterState: UpdateState;
onUpdate: () => void;
onDismissUpdate: () => void;
postUpdateNotice: PostUpdateNoticeState;
onDismissPostUpdateNotice: () => void;
errorToasts: ErrorToast[];
onDismissErrorToast: (id: string) => void;
latestAgentRuns: Array<{
Expand Down
97 changes: 96 additions & 1 deletion src/features/update/components/UpdateToast.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
// @vitest-environment jsdom
import { fireEvent, render, screen, within } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { openUrl } from "@tauri-apps/plugin-opener";
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { UpdateState } from "../hooks/useUpdater";
import { UpdateToast } from "./UpdateToast";

vi.mock("@tauri-apps/plugin-opener", () => ({
openUrl: vi.fn(),
}));

const openUrlMock = vi.mocked(openUrl);

describe("UpdateToast", () => {
beforeEach(() => {
vi.clearAllMocks();
});

it("renders available state and handles actions", () => {
const onUpdate = vi.fn();
const onDismiss = vi.fn();
Expand Down Expand Up @@ -83,4 +94,88 @@ describe("UpdateToast", () => {
fireEvent.click(scoped.getByRole("button", { name: "Dismiss" }));
expect(onDismiss).toHaveBeenCalledTimes(1);
});

it("renders post-update loading notice and dismisses", () => {
const onDismissPostUpdateNotice = vi.fn();
const state: UpdateState = { stage: "idle" };

const { container } = render(
<UpdateToast
state={state}
onUpdate={vi.fn()}
onDismiss={vi.fn()}
postUpdateNotice={{
stage: "loading",
version: "1.2.3",
htmlUrl: "https://github.com/Dimillian/CodexMonitor/releases/tag/v1.2.3",
}}
onDismissPostUpdateNotice={onDismissPostUpdateNotice}
/>,
);
const scoped = within(container);

expect(scoped.getByText("What's New")).toBeTruthy();
expect(scoped.getByText(/Loading release notes/i)).toBeTruthy();
fireEvent.click(scoped.getByRole("button", { name: "Dismiss" }));
expect(onDismissPostUpdateNotice).toHaveBeenCalledTimes(1);
});

it("renders post-update release notes and opens GitHub link", () => {
const onDismissPostUpdateNotice = vi.fn();
const htmlUrl =
"https://github.com/Dimillian/CodexMonitor/releases/tag/v1.2.3";
const state: UpdateState = { stage: "idle" };

const { container } = render(
<UpdateToast
state={state}
onUpdate={vi.fn()}
onDismiss={vi.fn()}
postUpdateNotice={{
stage: "ready",
version: "1.2.3",
body: "## Highlights\n- Added release notes toast",
htmlUrl,
}}
onDismissPostUpdateNotice={onDismissPostUpdateNotice}
/>,
);
const scoped = within(container);

expect(scoped.getByText("Highlights")).toBeTruthy();
expect(scoped.getByText("Added release notes toast")).toBeTruthy();

fireEvent.click(scoped.getByRole("button", { name: "View on GitHub" }));
expect(openUrlMock).toHaveBeenCalledWith(htmlUrl);

fireEvent.click(scoped.getByRole("button", { name: "Dismiss" }));
expect(onDismissPostUpdateNotice).toHaveBeenCalledTimes(1);
});

it("renders post-update fallback notice", () => {
const htmlUrl =
"https://github.com/Dimillian/CodexMonitor/releases/tag/v1.2.3";
const state: UpdateState = { stage: "available", version: "9.9.9" };

const { container } = render(
<UpdateToast
state={state}
onUpdate={vi.fn()}
onDismiss={vi.fn()}
postUpdateNotice={{
stage: "fallback",
version: "1.2.3",
htmlUrl,
}}
/>,
);
const scoped = within(container);

expect(
scoped.getByText("Updated to v1.2.3. Release notes could not be loaded."),
).toBeTruthy();
fireEvent.click(scoped.getByRole("button", { name: "View on GitHub" }));
expect(openUrlMock).toHaveBeenCalledWith(htmlUrl);
expect(scoped.queryByText("A new version is available.")).toBeNull();
});
});
91 changes: 89 additions & 2 deletions src/features/update/components/UpdateToast.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { UpdateState } from "../hooks/useUpdater";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
import { openUrl } from "@tauri-apps/plugin-opener";
import type { PostUpdateNoticeState, UpdateState } from "../hooks/useUpdater";
import {
ToastActions,
ToastBody,
Expand All @@ -13,6 +16,8 @@ type UpdateToastProps = {
state: UpdateState;
onUpdate: () => void;
onDismiss: () => void;
postUpdateNotice?: PostUpdateNoticeState;
onDismissPostUpdateNotice?: () => void;
};

function formatBytes(value: number) {
Expand All @@ -29,7 +34,89 @@ function formatBytes(value: number) {
return `${size.toFixed(size >= 10 ? 0 : 1)} ${units[unitIndex]}`;
}

export function UpdateToast({ state, onUpdate, onDismiss }: UpdateToastProps) {
export function UpdateToast({
state,
onUpdate,
onDismiss,
postUpdateNotice = null,
onDismissPostUpdateNotice,
}: UpdateToastProps) {
if (postUpdateNotice) {
return (
<ToastViewport className="update-toasts" role="region" ariaLive="polite">
<ToastCard className="update-toast" role="status">
<ToastHeader className="update-toast-header">
<ToastTitle className="update-toast-title">What's New</ToastTitle>
<div className="update-toast-version">v{postUpdateNotice.version}</div>
</ToastHeader>
{postUpdateNotice.stage === "loading" ? (
<ToastBody className="update-toast-body">
Updated successfully. Loading release notes...
</ToastBody>
) : null}
{postUpdateNotice.stage === "ready" ? (
<>
<ToastBody className="update-toast-body">
Updated successfully. Here is what is new:
</ToastBody>
<div className="update-toast-notes" role="document">
<ReactMarkdown
remarkPlugins={[remarkGfm]}
components={{
a: ({ href, children }) => {
if (!href) {
return <span>{children}</span>;
}
return (
<a
href={href}
target="_blank"
rel="noreferrer"
onClick={(event) => {
event.preventDefault();
void openUrl(href);
}}
>
{children}
</a>
);
},
}}
>
{postUpdateNotice.body}
</ReactMarkdown>
</div>
</>
) : null}
{postUpdateNotice.stage === "fallback" ? (
<ToastBody className="update-toast-body">
Updated to v{postUpdateNotice.version}. Release notes could not be
loaded.
</ToastBody>
) : null}
<ToastActions className="update-toast-actions">
{postUpdateNotice.stage !== "loading" ? (
<button
className="primary"
onClick={() => {
void openUrl(postUpdateNotice.htmlUrl);
}}
>
View on GitHub
</button>
) : null}
<button
className="secondary"
onClick={onDismissPostUpdateNotice ?? onDismiss}
>
Dismiss
</button>
</ToastActions>
</ToastCard>
</ToastViewport>
);
}

if (state.stage === "idle") {
return null;
}
Expand Down
Loading
Loading