From 2467bbc0f099132dcaf4193fc868c516ab1694fb Mon Sep 17 00:00:00 2001 From: henrygd Date: Wed, 23 Apr 2025 14:17:14 -0400 Subject: [PATCH] Add support for copying Windows and Homebrew installation commands --- beszel/site/src/components/add-system.tsx | 100 ++++++++++++++++------ beszel/site/src/components/ui/icons.tsx | 10 +++ 2 files changed, 85 insertions(+), 25 deletions(-) diff --git a/beszel/site/src/components/add-system.tsx b/beszel/site/src/components/add-system.tsx index 0e33b56..0f39886 100644 --- a/beszel/site/src/components/add-system.tsx +++ b/beszel/site/src/components/add-system.tsx @@ -1,5 +1,5 @@ -import { Trans } from "@lingui/react/macro"; -import { t } from "@lingui/core/macro"; +import { Trans } from "@lingui/react/macro" +import { t } from "@lingui/core/macro" import { Button } from "@/components/ui/button" import { Dialog, @@ -19,11 +19,12 @@ import { $publicKey, pb } from "@/lib/stores" import { cn, copyToClipboard, isReadOnlyUser, useLocalStorage } from "@/lib/utils" import { i18n } from "@lingui/core" import { useStore } from "@nanostores/react" -import { ChevronDownIcon, Copy, PlusIcon } from "lucide-react" +import { ChevronDownIcon, Copy, ExternalLinkIcon, PlusIcon } from "lucide-react" import { memo, useRef, useState } from "react" import { basePath, navigate } from "./router" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "./ui/dropdown-menu" import { SystemRecord } from "@/types" +import { AppleIcon, DockerIcon, TuxIcon, WindowsIcon } from "./ui/icons" export function AddSystemButton({ className }: { className?: string }) { const [open, setOpen] = useState(false) @@ -72,15 +73,22 @@ function copyDockerRun(port = "45876", publicKey: string) { ) } -function copyInstallCommand(port = "45876", publicKey: string) { - let cmd = `curl -sL https://raw.githubusercontent.com/henrygd/beszel/main/supplemental/scripts/install-agent.sh -o install-agent.sh && chmod +x install-agent.sh && ./install-agent.sh -p ${port} -k "${publicKey}"` - // add china mirrors flag if zh-CN +function copyLinuxCommand(port = "45876", publicKey: string, brew = false) { + let cmd = `curl -sL https://get.beszel.dev${ + brew ? "/brew" : "" + } -o /tmp/install-agent.sh && chmod +x /tmp/install-agent.sh && /tmp/install-agent.sh -p ${port} -k "${publicKey}"` if ((i18n.locale + navigator.language).includes("zh-CN")) { cmd += ` --china-mirrors` } copyToClipboard(cmd) } +function copyWindowsCommand(port = "45876", publicKey: string) { + copyToClipboard( + `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser; & iwr -useb https://get.beszel.dev -OutFile "$env:TEMP\install-agent.ps1"; & "$env:TEMP\install-agent.ps1" -Key "${publicKey}" -Port ${port}` + ) +} + /** * SystemDialog component for adding or editing a system. * @param {Object} props - The component props. @@ -197,7 +205,7 @@ export const SystemDialog = memo(({ setOpen, system }: { setOpen: (open: boolean className="absolute end-0 top-0" onClick={() => copyToClipboard(publicKey)} > - + @@ -215,17 +223,39 @@ export const SystemDialog = memo(({ setOpen, system }: { setOpen: (open: boolean copyDockerCompose(isUnixSocket ? hostValue : port.current?.value, publicKey)} - dropdownText={t`Copy` + " docker run"} - dropdownOnClick={() => copyDockerRun(isUnixSocket ? hostValue : port.current?.value, publicKey)} + icon={} + dropdownItems={[ + { + text: t`Copy` + " docker run", + onClick: () => copyDockerRun(isUnixSocket ? hostValue : port.current?.value, publicKey), + icons: [], + }, + ]} /> {/* Binary */} copyInstallCommand(isUnixSocket ? hostValue : port.current?.value, publicKey)} - dropdownText={t`Manual setup instructions`} - dropdownUrl="https://beszel.dev/guide/agent-installation#binary" + icon={} + onClick={() => copyLinuxCommand(isUnixSocket ? hostValue : port.current?.value, publicKey)} + dropdownItems={[ + { + text: t`Copy Homebrew command`, + onClick: () => copyLinuxCommand(isUnixSocket ? hostValue : port.current?.value, publicKey, true), + icons: [, ], + }, + { + text: t`Copy Windows command`, + onClick: () => copyWindowsCommand(isUnixSocket ? hostValue : port.current?.value, publicKey), + icons: [], + }, + { + text: t`Manual setup instructions`, + url: "https://beszel.dev/guide/agent-installation#binary", + icons: [], + }, + ]} /> {/* Save */} @@ -237,19 +267,30 @@ export const SystemDialog = memo(({ setOpen, system }: { setOpen: (open: boolean ) }) +interface DropdownItem { + text: string + onClick?: () => void + url?: string + icons?: React.ReactNode[] +} + interface CopyButtonProps { text: string onClick: () => void - dropdownText: string - dropdownOnClick?: () => void - dropdownUrl?: string + dropdownItems: DropdownItem[] + icon?: React.ReactNode } const CopyButton = memo((props: CopyButtonProps) => { return (
-
@@ -259,15 +300,24 @@ const CopyButton = memo((props: CopyButtonProps) => { - {props.dropdownUrl ? ( - - - {props.dropdownText} - + {props.dropdownItems.map((item, index) => ( + + {item.url ? ( + + {item.text} {item.icons?.map((icon) => icon)} + + ) : ( +
+ {item.text} {item.icons?.map((icon) => icon)} +
+ )}
- ) : ( - {props.dropdownText} - )} + ))}
diff --git a/beszel/site/src/components/ui/icons.tsx b/beszel/site/src/components/ui/icons.tsx index 6dd6d6d..272ec8d 100644 --- a/beszel/site/src/components/ui/icons.tsx +++ b/beszel/site/src/components/ui/icons.tsx @@ -38,6 +38,16 @@ export function AppleIcon(props: SVGProps) { ) } +// ion icons (MIT) https://github.com/ionic-team/ionicons/blob/main/LICENSE +export function DockerIcon(props: SVGProps) { + return ( + + + + + ) +} + // MingCute Apache License 2.0 https://github.com/Richard9394/MingCute export function Rows(props: SVGProps) { return (