Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(web): add chrome extension detection hook and constants
Richie McIlroyfa3bf1b65c99
diff --git a/apps/web/hooks/useCapChromeExtension.ts b/apps/web/hooks/useCapChromeExtension.tsnew file mode 100644index 000000000..e023dc970--- /dev/null+++ b/apps/web/hooks/useCapChromeExtension.ts@@ -0,0 +1,32 @@+import { useCallback, useEffect, useState } from "react";+import {+ CAP_CHROME_EXTENSION_INSTALLED_ATTRIBUTE,+ CAP_CHROME_EXTENSION_OPEN_EVENT,+ CAP_CHROME_EXTENSION_READY_EVENT,+} from "@/lib/chrome-extension";++const isCapChromeExtensionInstalled = () =>+ document.documentElement.getAttribute(+ CAP_CHROME_EXTENSION_INSTALLED_ATTRIBUTE,+ ) === "true";++export const useCapChromeExtension = () => {+ const [isInstalled, setIsInstalled] = useState(false);++ useEffect(() => {+ const detect = () => setIsInstalled(isCapChromeExtensionInstalled());++ detect();+ window.addEventListener(CAP_CHROME_EXTENSION_READY_EVENT, detect);++ return () => {+ window.removeEventListener(CAP_CHROME_EXTENSION_READY_EVENT, detect);+ };+ }, []);++ const openRecorder = useCallback(() => {+ window.dispatchEvent(new CustomEvent(CAP_CHROME_EXTENSION_OPEN_EVENT));+ }, []);++ return { isInstalled, openRecorder };+};diff --git a/apps/web/lib/chrome-extension.ts b/apps/web/lib/chrome-extension.tsindex 7ca7344dc..ab4c07dad 100644--- a/apps/web/lib/chrome-extension.ts+++ b/apps/web/lib/chrome-extension.ts@@ -1,6 +1,10 @@export const CAP_CHROME_EXTENSION_URL ="https://chromewebstore.google.com/detail/cap-screen-recorder-scree/fefjaffcodfiogbbngmjkcjpbpclbdcp";-/** Clean white styling for the "Add to Chrome" button used alongside Download CTAs. */export const CHROME_EXTENSION_BUTTON_CLASS ="border-gray-6 bg-white text-gray-12 shadow-[0_1px_2px_rgba(0,0,0,0.08)] hover:border-gray-7 hover:bg-gray-2";++export const CAP_CHROME_EXTENSION_INSTALLED_ATTRIBUTE =+ "data-cap-chrome-extension-installed";+export const CAP_CHROME_EXTENSION_READY_EVENT = "cap-chrome-extension-ready";+export const CAP_CHROME_EXTENSION_OPEN_EVENT = "cap-chrome-extension-open";