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
12export async function openDesktopUpdateReleaseNotes(
13 shell: DesktopUpdateShell | undefined,
14 releaseUrl: string,
15): Promise<void> {
16 try {
17 if (shell && (await shell.openExternal(releaseUrl))) return;
18 } catch {}
19 toastManager.add({ type: "error", title: "Unable to open release notes" });
20}
21
22function ReleaseNotesLink({
23 shell,
24 releaseUrl,
25}: {
26 shell: DesktopUpdateShell;
27 releaseUrl: string;
28}) {
29 return (
30 <button
31 className="ml-2 inline cursor-pointer text-muted-foreground underline decoration-dotted underline-offset-4 transition-colors hover:text-foreground"
32 onClick={() => {
33 void openDesktopUpdateReleaseNotes(shell, releaseUrl);
34 }}
35 type="button"
36 >
37 Read more
38 <ArrowRightIcon
39 aria-hidden
40 className="ml-1 inline size-3 -rotate-45 align-[-0.125em]"
41 strokeWidth={2.25}
42 />
43 </button>
44 );
45}
46
47export function showDesktopUpdateDownloadedToast(
48 shell: DesktopUpdateShell,
49 state: DesktopUpdateState,
50): void {
51 const releaseUrl = getDesktopUpdateReleaseUrl(getDesktopUpdateDownloadedVersion(state));
52 toastManager.add({
53 type: "success",
54 title: "Update downloaded",
55 description: (
56 <>
57 Restart the app from the update button to install it.
58 {releaseUrl ? <ReleaseNotesLink releaseUrl={releaseUrl} shell={shell} /> : null}
59 </>
60 ),
61 });
62}