Open History to see the last commit
1import type { DesktopBridge, DesktopUpdateState } from "@t3tools/contracts";
2import { ArrowRightIcon } from "lucide-react";
3
4import {
5 getDesktopUpdateDownloadedVersion,
6 getDesktopUpdateReleaseUrl,
7} from "./desktopUpdate.logic";
8import { toastManager } from "./ui/toast";
9
10type DesktopUpdateShell = Pick<DesktopBridge, "openExternal">;
11
12function ReleaseNotesLink({
13 shell,
14 releaseUrl,
15}: {
16 shell: DesktopUpdateShell;
17 releaseUrl: string;
18}) {
19 return (
20 <button
21 className="ml-2 inline-flex cursor-pointer items-center gap-1 align-baseline text-muted-foreground underline decoration-dotted underline-offset-4 transition-colors hover:text-foreground"
22 onClick={() => {
23 void (async () => {
24 try {
25 if (await shell.openExternal(releaseUrl)) return;
26 } catch {
27 // Surface rejected IPC calls through the same user-visible fallback.
28 }
29 toastManager.add({ type: "error", title: "Unable to open release notes" });
30 })();
31 }}
32 type="button"
33 >
34 Read more
35 <ArrowRightIcon aria-hidden className="size-3 -rotate-45" strokeWidth={2.25} />
36 </button>
37 );
38}
39
40export function showDesktopUpdateDownloadedToast(
41 shell: DesktopUpdateShell,
42 state: DesktopUpdateState,
43): void {
44 const releaseUrl = getDesktopUpdateReleaseUrl(getDesktopUpdateDownloadedVersion(state));
45 toastManager.add({
46 type: "success",
47 title: "Update downloaded",
48 description: (
49 <>
50 Restart the app from the update button to install it.
51 {releaseUrl ? <ReleaseNotesLink releaseUrl={releaseUrl} shell={shell} /> : null}
52 </>
53 ),
54 });
55}