Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

desktopUpdate.toast.tsx

64 lines1.8 KB

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