Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat: Show custom domain for Cap (#698)
Ameer Al Ashhab91dc80ecf4dd
diff --git a/apps/desktop/src/routes/(window-chrome)/(main).tsx b/apps/desktop/src/routes/(window-chrome)/(main).tsxindex ba164671e..7ad3c67ac 100644--- a/apps/desktop/src/routes/(window-chrome)/(main).tsx+++ b/apps/desktop/src/routes/(window-chrome)/(main).tsx@@ -21,19 +21,18 @@ import {} from "solid-js";import { createStore, reconcile } from "solid-js/store";-import Tooltip from "~/components/Tooltip";import Mode from "~/components/Mode";+import Tooltip from "~/components/Tooltip";import { identifyUser, trackEvent } from "~/utils/analytics";import {createCameraMutation,createCurrentRecordingQuery,createLicenseQuery,- createOptionsQuery,createVideoDevicesQuery,getPermissions,listAudioDevices,listScreens,- listWindows,+ listWindows} from "~/utils/queries";import {type CaptureScreen,@@ -295,17 +294,16 @@ function Page() {await commands.showWindow("Upgrade");}}}- class={`text-[0.6rem] ${- license.data?.type === "pro"- ? "bg-[--blue-400] text-gray-1 dark:text-gray-12"- : "bg-gray-3 cursor-pointer hover:bg-gray-5"- } rounded-lg px-1.5 py-0.5`}+ class={`text-[0.6rem] ${license.data?.type === "pro"+ ? "bg-[--blue-400] text-gray-1 dark:text-gray-12"+ : "bg-gray-3 cursor-pointer hover:bg-gray-5"+ } rounded-lg px-1.5 py-0.5`}>{license.data?.type === "commercial"? "Commercial": license.data?.type === "pro"- ? "Pro"- : "Personal"}+ ? "Pro"+ : "Personal"}</span></Suspense></ErrorBoundary>@@ -336,7 +334,7 @@ function Page() {"flex flex-row items-center rounded-[0.5rem] relative border h-8 transition-all duration-500",(rawOptions.captureTarget.variant === "screen" ||rawOptions.captureTarget.variant === "area") &&- "ml-[2.4rem]"+ "ml-[2.4rem]")}style={{"transition-timing-function":@@ -477,7 +475,6 @@ function useRequestPermission() {}import { makePersisted } from "@solid-primitives/storage";-import { UnlistenFn } from "@tauri-apps/api/event";import { CheckMenuItem, Menu, PredefinedMenuItem } from "@tauri-apps/api/menu";import {getCurrentWebviewWindow,@@ -491,8 +488,7 @@ import { Transition } from "solid-transition-group";import { SignInButton } from "~/components/SignInButton";import { authStore, generalSettingsStore } from "~/store";import { apiClient } from "~/utils/web-api";-import { useWindowChrome, WindowChromeHeader } from "./Context";-import { on } from "solid-js";+import { WindowChromeHeader } from "./Context";import {RecordingOptionsProvider,useRecordingOptions,@@ -577,8 +573,8 @@ function AreaSelectButton(props: {props.targetVariant === "area"? "Remove selection": areaSelection.pending- ? "Selecting area..."- : "Select area"+ ? "Selecting area..."+ : "Select area"}childClass="flex fixed flex-row items-center w-8 h-8">@@ -649,7 +645,7 @@ function AreaSelectButton(props: {class={cx("w-[1rem] h-[1rem]",areaSelection.pending &&- "animate-gentle-bounce duration-1000 text-gray-12 mt-1"+ "animate-gentle-bounce duration-1000 text-gray-12 mt-1")}/></button>@@ -973,8 +969,8 @@ function TargetSelectInfoPill<T>(props: {{!props.permissionGranted? "Request Permission": props.value !== null- ? "On"- : "Off"}+ ? "On"+ : "Off"}</InfoPill>);}diff --git a/apps/desktop/src/routes/editor/Editor.tsx b/apps/desktop/src/routes/editor/Editor.tsxindex f2cea828e..4e825bce1 100644--- a/apps/desktop/src/routes/editor/Editor.tsx+++ b/apps/desktop/src/routes/editor/Editor.tsx@@ -4,6 +4,7 @@ import { throttle } from "@solid-primitives/scheduled";import { makePersisted } from "@solid-primitives/storage";import { createMutation } from "@tanstack/solid-query";import { convertFileSrc } from "@tauri-apps/api/core";+import { cx } from "cva";import {Match,Show,@@ -15,7 +16,6 @@ import {onMount,} from "solid-js";import { createStore } from "solid-js/store";-import { cx } from "cva";import Cropper, { cropToFloor } from "~/components/Cropper";import { Toggle } from "~/components/Toggle";diff --git a/apps/desktop/src/routes/editor/Header.tsx b/apps/desktop/src/routes/editor/Header.tsxindex 93fc4a01c..d659ec6ee 100644--- a/apps/desktop/src/routes/editor/Header.tsx+++ b/apps/desktop/src/routes/editor/Header.tsx@@ -5,7 +5,7 @@ import { remove } from "@tauri-apps/plugin-fs";import { revealItemInDir } from "@tauri-apps/plugin-opener";import { type as ostype } from "@tauri-apps/plugin-os";import { cx } from "cva";-import { ComponentProps, createEffect, createSignal, onCleanup, onMount } from "solid-js";+import { ComponentProps, createEffect, createSignal, onCleanup, onMount, Show } from "solid-js";import { Button } from "@cap/ui-solid";import CaptionControlsWindows11 from "~/components/titlebar/controls/CaptionControlsWindows11";@@ -44,6 +44,7 @@ export function Header() {meta,exportState,setExportState,+ customDomain} = useEditorContext();let unlistenTitlebar: UnlistenFn | undefined;@@ -53,6 +54,7 @@ export function Header() {onCleanup(() => unlistenTitlebar?.());const [truncated, setTruncated] = createSignal(false);+let prettyNameRef: HTMLParagraphElement | undefined;createEffect(() => {@@ -165,7 +167,9 @@ export function Header() {leftIcon={<IconCapRedo class="w-5" />}/><div data-tauri-drag-region class="flex-1 h-full" />- <ShareButton />+ <Show when={customDomain()}>+ <ShareButton />+ </Show><Buttonvariant="lightdark"class={cx("flex gap-2 justify-center")}diff --git a/apps/desktop/src/routes/editor/ShareButton.tsx b/apps/desktop/src/routes/editor/ShareButton.tsxindex 2fc898e57..ef5d73e7f 100644--- a/apps/desktop/src/routes/editor/ShareButton.tsx+++ b/apps/desktop/src/routes/editor/ShareButton.tsx@@ -1,8 +1,8 @@import { Button } from "@cap/ui-solid";+import { Select as KSelect } from "@kobalte/core/select";import { createMutation } from "@tanstack/solid-query";import { createSignal, Show } from "solid-js";import { createStore, produce, reconcile } from "solid-js/store";-import Tooltip from "~/components/Tooltip";import { createProgressBar } from "~/routes/editor/utils";import { authStore } from "~/store";@@ -10,12 +10,13 @@ import { exportVideo } from "~/utils/export";import { commands, events } from "~/utils/tauri";import { useEditorContext } from "./context";import { RESOLUTION_OPTIONS } from "./Header";-import { Dialog, DialogContent } from "./ui";+import { Dialog, DialogContent, MenuItem, MenuItemList, PopperContent, topLeftAnimateClasses } from "./ui";function ShareButton() {- const { editorInstance, meta } = useEditorContext();+ const { editorInstance, meta, customDomain } = useEditorContext();const projectPath = editorInstance.path;+const upload = createMutation(() => ({mutationFn: async () => {setUploadState({ type: "idle" });@@ -89,8 +90,8 @@ function ShareButton() {const result = meta().sharing? await commands.uploadExportedVideo(projectPath, "Reupload"): await commands.uploadExportedVideo(projectPath, {- Initial: { pre_created_video: null },- });+ Initial: { pre_created_video: null },+ });if (result === "NotAuthenticated") {throw new Error("You need to sign in to share recordings");@@ -138,11 +139,27 @@ function ShareButton() {<div class="relative"><Show when={meta().sharing}>{(sharing) => {- const url = () => new URL(sharing().link);++ const normalUrl = () => new URL(sharing().link);+ const customUrl = () => customDomain()?.custom_domain ? new URL(customDomain()?.custom_domain + `/s/${meta().sharing?.id}`) : null;++ const normalLink = `${normalUrl().host}${normalUrl().pathname}`;+ const customLink = `${customUrl()?.host}${customUrl()?.pathname}`;+++ const copyLinks = {+ normal: sharing().link,+ custom: customUrl()?.href+ }++ const [linkToDisplay, setLinkToDisplay] = createSignal<string | null>(+ customDomain()?.custom_domain && customDomain()?.domain_verified ? customLink : normalLink+ );const [copyPressed, setCopyPressed] = createSignal(false);+const copyLink = () => {- navigator.clipboard.writeText(sharing().link);+ navigator.clipboard.writeText(linkToDisplay() || sharing().link);setCopyPressed(true);setTimeout(() => {setCopyPressed(false);@@ -172,26 +189,66 @@ function ShareButton() {<Tooltip content="Open link"><div class="rounded-xl px-3 py-2 flex flex-row items-center gap-[0.375rem] bg-gray-3 hover:bg-gray-4 transition-colors duration-100"><a- href={sharing().link}+ href={+ linkToDisplay() === customLink ? copyLinks.custom : copyLinks.normal+ }target="_blank"rel="noreferrer"- class="w-full truncate max-w-48"+ class="w-full truncate max-w-[200px]"><span class="text-xs text-gray-12">- {url().host}- {url().pathname}+ {linkToDisplay()}</span></a>+ {/** Dropdown */}+ <Show when={customDomain()?.custom_domain && customDomain()?.domain_verified}>+ <Tooltip content="Select link">+ <KSelect+ value={linkToDisplay()}+ onChange={(value) => value && setLinkToDisplay(value)}+ options={[customLink, normalLink].filter(link => link !== linkToDisplay())}+ multiple={false}+ itemComponent={(props) => (+ <MenuItem<typeof KSelect.Item> as={KSelect.Item} item={props.item}>+ <KSelect.ItemLabel class="flex-1 text-xs truncate">+ {props.item.rawValue}+ </KSelect.ItemLabel>+ </MenuItem>+ )}+ placement="bottom-end"+ gutter={4}+ >+ <KSelect.Trigger+ class="flex justify-center items-center transition-colors duration-200 rounded-lg size-[22px] text-gray-12 bg-gray-6 hover:bg-gray-7 group focus:outline-none focus-visible:outline-none"+ >+ <KSelect.Icon>+ <IconCapChevronDown class="size-4 transition-transform duration-200 group-data-[expanded]:rotate-180" />+ </KSelect.Icon>+ </KSelect.Trigger>+ <KSelect.Portal>+ <PopperContent<typeof KSelect.Content>+ as={KSelect.Content}+ class={topLeftAnimateClasses}+ >+ <MenuItemList<typeof KSelect.Listbox>+ as={KSelect.Listbox}+ class="w-[236px]"+ />+ </PopperContent>+ </KSelect.Portal>+ </KSelect>+ </Tooltip>+ </Show>{/** Copy button */}<Tooltip content="Copy link"><div- class="flex justify-center items-center rounded-lg size-[22px] text-gray-12 !px-0 !py-0 dark:bg-black-transparent-10 dark:hover:bg-black-transparent-40 bg-gray-3 hover:bg-gray-5"+ class="flex justify-center items-center transition-colors duration-200 rounded-lg size-[22px] text-gray-12 bg-gray-6 hover:bg-gray-7"onClick={copyLink}>{!copyPressed() ? (- <IconCapCopy class="size-2.5" />+ <IconCapCopy class="size-3" />) : (- <IconLucideCheck class="size-2.5 svgpathanimation" />+ <IconLucideCheck class="size-3 svgpathanimation" />)}</div></Tooltip>@@ -213,20 +270,19 @@ function ShareButton() {<divclass="bg-blue-9 h-2.5 rounded-full"style={{- width: `${- uploadState.type === "uploading"- ? uploadState.progress- : uploadState.type === "link-copied"+ width: `${uploadState.type === "uploading"+ ? uploadState.progress+ : uploadState.type === "link-copied"? 100: uploadState.type === "rendering"- ? Math.min(+ ? Math.min((uploadState.renderedFrames /uploadState.totalFrames) *- 100,+ 100,100)- : 0- }%`,+ : 0+ }%`,}}/></div>@@ -235,10 +291,10 @@ function ShareButton() {{uploadState.type == "idle" || uploadState.type === "starting"? "Preparing to render...": uploadState.type === "rendering"- ? `Rendering video (${uploadState.renderedFrames}/${uploadState.totalFrames} frames)`- : uploadState.type === "uploading"- ? `Uploading - ${Math.floor(uploadState.progress)}%`- : "Link copied to clipboard!"}+ ? `Rendering video (${uploadState.renderedFrames}/${uploadState.totalFrames} frames)`+ : uploadState.type === "uploading"+ ? `Uploading - ${Math.floor(uploadState.progress)}%`+ : "Link copied to clipboard!"}</p></div></DialogContent>diff --git a/apps/desktop/src/routes/editor/context.ts b/apps/desktop/src/routes/editor/context.tsindex 4239f0aaf..ab6489c4c 100644--- a/apps/desktop/src/routes/editor/context.ts+++ b/apps/desktop/src/routes/editor/context.ts@@ -16,6 +16,7 @@ import {import { createStore, produce, reconcile, unwrap } from "solid-js/store";import { createPresets } from "~/utils/createPresets";+import { createCustomDomainQuery } from "~/utils/queries";import { createImageDataWS, createLazySignal } from "~/utils/socket";import {commands,@@ -52,6 +53,11 @@ export type RenderState =| { type: "starting" }| { type: "rendering"; progress: FramesRendered };+export type CustomDomainResponse = {+ custom_domain: string | null;+ domain_verified: boolean | null;+};+export const [EditorContextProvider, useEditorContext] = createContextProvider((props: {meta: () => TransformedMeta;@@ -269,11 +275,16 @@ export const [EditorContextProvider, useEditorContext] = createContextProvider(},});+ const customDomainData = createCustomDomainQuery();+return {...editorInstanceContext,meta() {return props.meta();},+ customDomain() {+ return customDomainData.data;+ },refetchMeta: () => props.refetchMeta(),editorInstance: props.editorInstance,dialog,diff --git a/apps/desktop/src/utils/auth.ts b/apps/desktop/src/utils/auth.tsindex 09ad0eadc..d38352cb6 100644--- a/apps/desktop/src/utils/auth.ts+++ b/apps/desktop/src/utils/auth.ts@@ -1,12 +1,12 @@-import * as shell from "@tauri-apps/plugin-shell";import { createMutation } from "@tanstack/solid-query";-import { getCurrentWindow } from "@tauri-apps/api/window";-import { authStore, generalSettingsStore } from "~/store";import { invoke } from "@tauri-apps/api/core";-import callbackTemplate from "~/components/callback.template";import { listen } from "@tauri-apps/api/event";-import { z } from "zod";+import { getCurrentWindow } from "@tauri-apps/api/window";import { onOpenUrl } from "@tauri-apps/plugin-deep-link";+import * as shell from "@tauri-apps/plugin-shell";+import { z } from "zod";+import callbackTemplate from "~/components/callback.template";+import { authStore, generalSettingsStore } from "~/store";import { identifyUser, trackEvent } from "./analytics";import { commands } from "./tauri";diff --git a/apps/desktop/src/utils/queries.ts b/apps/desktop/src/utils/queries.tsindex df4a718f0..87994044c 100644--- a/apps/desktop/src/utils/queries.ts+++ b/apps/desktop/src/utils/queries.ts@@ -1,18 +1,20 @@+import { makePersisted } from "@solid-primitives/storage";import {createMutation,createQuery,queryOptions,+ useQuery,} from "@tanstack/solid-query";-import { createStore, reconcile } from "solid-js/store";import { createMemo } from "solid-js";-import { makePersisted } from "@solid-primitives/storage";+import { createStore, reconcile } from "solid-js/store";-import { authStore, generalSettingsStore } from "~/store";-import { commands, RecordingMode, ScreenCaptureTarget } from "./tauri";-import { createQueryInvalidate } from "./events";import { createEventListener } from "@solid-primitives/event-listener";-import { useRecordingOptions } from "~/routes/(window-chrome)/OptionsContext";import { getCurrentWindow } from "@tauri-apps/api/window";+import { useRecordingOptions } from "~/routes/(window-chrome)/OptionsContext";+import { authStore, generalSettingsStore } from "~/store";+import { createQueryInvalidate } from "./events";+import { commands, RecordingMode, ScreenCaptureTarget } from "./tauri";+import { orgCustomDomainClient, protectedHeaders } from "./web-api";export const listWindows = queryOptions({queryKey: ["capture", "windows"] as const,@@ -150,3 +152,24 @@ export function createCameraMutation() {return setCameraInput;}++export function createCustomDomainQuery() {+ return useQuery(() => ({+ queryKey: ["customDomain"] as const,+ queryFn: async () => {+ try {+ const auth = await authStore.get();+ if (!auth) return { custom_domain: null, domain_verified: null };+ const response = await orgCustomDomainClient.getOrgCustomDomain({+ headers: await protectedHeaders(),+ });+ if (response.status === 200) return response.body;+ } catch (error) {+ console.error("Error fetching custom domain:", error);+ return { custom_domain: null, domain_verified: null };+ }+ },+ refetchOnMount: true,+ refetchOnWindowFocus: true,+ }));+}diff --git a/apps/desktop/src/utils/web-api.ts b/apps/desktop/src/utils/web-api.tsindex f33700252..3e4537f3d 100644--- a/apps/desktop/src/utils/web-api.ts+++ b/apps/desktop/src/utils/web-api.ts@@ -1,9 +1,13 @@-import { ApiFetcher, initClient } from "@ts-rest/core";-import { contract, licenseContract } from "@cap/web-api-contract";+import {+ contract,+ licenseContract,+ orgCustomDomainContract,+} from "@cap/web-api-contract";import { fetch } from "@tauri-apps/plugin-http";+import { ApiFetcher, initClient } from "@ts-rest/core";-import { clientEnv } from "./env";import { authStore } from "~/store";+import { clientEnv } from "./env";const api: ApiFetcher = async (args) => {const bypassSecret = import.meta.env.VITE_VERCEL_AUTOMATION_BYPASS_SECRET;@@ -36,6 +40,11 @@ export const licenseApiClient = initClient(licenseContract, {api,});+export const orgCustomDomainClient = initClient(orgCustomDomainContract, {+ baseUrl: `${clientEnv.VITE_SERVER_URL}/api/desktop`,+ api,+});+export async function maybeProtectedHeaders() {const store = await authStore.get();@@ -52,6 +61,5 @@ export async function maybeProtectedHeaders() {export async function protectedHeaders() {const { authorization } = await maybeProtectedHeaders();if (!authorization) throw new Error("Not authorized");- console.log({ authorization });return { authorization };}diff --git a/apps/web/app/api/desktop/[...route]/root.ts b/apps/web/app/api/desktop/[...route]/root.tsindex de4a8a937..4d511585a 100644--- a/apps/web/app/api/desktop/[...route]/root.ts+++ b/apps/web/app/api/desktop/[...route]/root.ts@@ -1,14 +1,14 @@+import { db } from "@cap/database";+import { organizations, users } from "@cap/database/schema";import { buildEnv, serverEnv } from "@cap/env";-import { Hono } from "hono";-import { zValidator } from "@hono/zod-validator";-import { z } from "zod";import { isUserOnProPlan, stripe } from "@cap/utils";-import { db } from "@cap/database";-import { users } from "@cap/database/schema";+import { zValidator } from "@hono/zod-validator";import { eq } from "drizzle-orm";+import { Hono } from "hono";import * as crypto from "node:crypto";-import { withAuth } from "../../utils";import { PostHog } from "posthog-node";+import { z } from "zod";+import { withAuth } from "../../utils";export const app = new Hono().use(withAuth);@@ -59,6 +59,39 @@ app.post(});+app.get("/org-custom-domain", async (c) => {+ const user = c.get("user");++ try {+ const [result] = await db()+ .select({+ customDomain: organizations.customDomain,+ domainVerified: organizations.domainVerified,+ })+ .from(users)+ .leftJoin(organizations, eq(users.activeOrganizationId, organizations.id))+ .where(eq(users.id, user.id));++ // Ensure custom domain has https:// prefix+ let customDomain = result?.customDomain ?? null;+ if (+ customDomain &&+ !customDomain.startsWith("http://") &&+ !customDomain.startsWith("https://")+ ) {+ customDomain = `https://${customDomain}`;+ }++ return c.json({+ custom_domain: customDomain,+ domain_verified: result?.domainVerified ?? null,+ });+ } catch (error) {+ console.error("[GET] Error fetching custom domain:", error);+ return c.json({ error: "Failed to fetch custom domain" }, { status: 500 });+ }+});+app.get("/plan", async (c) => {const user = c.get("user");diff --git a/apps/web/app/api/desktop/[...route]/route.ts b/apps/web/app/api/desktop/[...route]/route.tsindex 9377f504f..59396a7d6 100644--- a/apps/web/app/api/desktop/[...route]/route.ts+++ b/apps/web/app/api/desktop/[...route]/route.ts@@ -1,5 +1,5 @@-import { handle } from "hono/vercel";import { Hono } from "hono";+import { handle } from "hono/vercel";import { corsMiddleware } from "../../utils";diff --git a/packages/web-api-contract/src/index.ts b/packages/web-api-contract/src/index.tsindex bea842a37..ac95b2056 100644--- a/packages/web-api-contract/src/index.ts+++ b/packages/web-api-contract/src/index.ts@@ -1,11 +1,6 @@import { z } from "zod";import desktop from "./desktop";import { c } from "./util";-import {- ClientInferRequest,- ClientInferResponseBody,- ClientInferResponses,-} from "@ts-rest/core";export const contract = c.router({desktop,@@ -39,6 +34,23 @@ export const contract = c.router({}),});+export const orgCustomDomainContract = c.router({+ getOrgCustomDomain: {+ method: "GET",+ path: "/org-custom-domain",+ headers: z.object({ authorization: z.string() }),+ responses: {+ 200: z.object({+ custom_domain: z.string().nullable(),+ domain_verified: z.boolean().nullable(),+ }),+ 500: z.object({+ message: z.string(),+ }),+ },+ },+});+export const licenseContract = c.router({activateCommercialLicense: {method: "POST",