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 cursor-pointer 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
36 aria-hidden
37 className="ml-1 inline size-3 -rotate-45 align-[-0.125em]"
38 strokeWidth={2.25}
39 />
40 </button>
41 );
42}
43
44export function showDesktopUpdateDownloadedToast(
45 shell: DesktopUpdateShell,
46 state: DesktopUpdateState,
47): void {
48 const releaseUrl = getDesktopUpdateReleaseUrl(getDesktopUpdateDownloadedVersion(state));
49 toastManager.add({
50 type: "success",
51 title: "Update downloaded",
52 description: (
53 <>
54 Restart the app from the update button to install it.
55 {releaseUrl ? <ReleaseNotesLink releaseUrl={releaseUrl} shell={shell} /> : null}
56 </>
57 ),
58 });
59}