diff --git a/gauntlet.toml b/gauntlet.toml index 2733b6d..b5fc325 100644 --- a/gauntlet.toml +++ b/gauntlet.toml @@ -44,9 +44,15 @@ Copy emojis to your clipboard from Gauntlet! [[supported_system]] os = 'linux' +[[supported_system]] +os = 'macos' + +[[supported_system]] +os = 'windows' + [permissions] main_search_bar = ["read"] clipboard = ["write"] [permissions.exec] -command = ["xdg-open"] +command = ["xdg-open", "open", "start", "firefox"] diff --git a/src/tailwindcss/src/search-documentation.tsx b/src/tailwindcss/src/search-documentation.tsx index 955bea2..bf3afbd 100644 --- a/src/tailwindcss/src/search-documentation.tsx +++ b/src/tailwindcss/src/search-documentation.tsx @@ -2,14 +2,18 @@ import { List } from "@project-gauntlet/api/components"; import React, { ReactElement, useState } from "react"; import documentation from "./documentation/tailwind-css"; import { Clipboard } from "@project-gauntlet/api/helpers"; -//import { open } from "@opensrc/deno-open"; # pending a fix for https://github.com/project-gauntlet/gauntlet/issues/28 +import open from "../../utils/open-url"; + +// @ts-expect-error gauntlet uses deno and not node +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const denoCore: DenoCore = Deno[Deno.internal].core; export default function SearchDocumentation(): ReactElement { const [searchText, setSearchText] = useState(""); const onClick = async (url: string) => { - //await open(url); - await Clipboard.writeText(url); + await open(url); + //await Clipboard.writeText(url); }; return ( diff --git a/src/utils/open-url.ts b/src/utils/open-url.ts new file mode 100644 index 0000000..5104afc --- /dev/null +++ b/src/utils/open-url.ts @@ -0,0 +1,37 @@ +const getOpenCommand = (platform: typeof Deno.build.os): string => { + const commands = { + windows: "start", + darwin: "open", + linux: "xdg-open", + freebsd: "xdg-open", + netbsd: "xdg-open", + android: "open", + solaris: "firefox", //FIXME - use a different command that doesn't force a specific browser + aix: "firefox", + illumos: "firefox", + } as const; + return commands[platform] || commands.linux; +}; + +/** + * Open a URL in the user's configured default browser + * @param url The url you want to open in the default browser + * @returns Promise The status of the command + */ +const open = async (url: string) => { + // Yes, this function uses Deno. Yes, this repository uses Node.js for tooling. + // Gauntlet runs loaded plugins in a Deno runtime, so this works fine. + // Hop off Copilot I know this isn't using Node.js APIs + const platform = Deno.build.os; + const cmd = getOpenCommand(platform); + const process = new Deno.Command(cmd, { + args: [url], + env: { + LD_LIBRARY_PATH: "", + }, + }); + const child = process.spawn(); + return await child.status; +}; + +export default open;