Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
auth
Brendan Allan40f128035745
diff --git a/Cargo.lock b/Cargo.lockindex 45d711480..79773c9f8 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1559,6 +1559,7 @@ dependencies = ["tauri-plugin-decorum","tauri-plugin-dialog","tauri-plugin-fs",+ "tauri-plugin-oauth","tauri-plugin-os","tauri-plugin-process","tauri-plugin-shell",@@ -5708,6 +5709,20 @@ dependencies = ["uuid",]+[[package]]+name = "tauri-plugin-oauth"+version = "0.0.0-alpha.0"+source = "git+https://github.com/FabianLars/tauri-plugin-oauth?branch=v2#3537dd0a2a8f8a868d8e89a0002c8a5c588a27f7"+dependencies = [+ "httparse",+ "log",+ "serde",+ "tauri",+ "tauri-plugin",+ "thiserror",+ "url",+]+[[package]]name = "tauri-plugin-os"version = "2.0.0-rc.0"diff --git a/apps/desktop-solid/src-tauri/Cargo.toml b/apps/desktop-solid/src-tauri/Cargo.tomlindex 090fdefbb..bd6c21369 100644--- a/apps/desktop-solid/src-tauri/Cargo.toml+++ b/apps/desktop-solid/src-tauri/Cargo.toml@@ -23,18 +23,24 @@ tauri = { version = "2.0.0-rc", features = ["image-png",] }tauri-plugin-shell = "2.0.0-rc"+tauri-nspanel = { git = "https://github.com/ahkohd/tauri-nspanel", branch = "v2" }+tauri-plugin-store = "2.0.0-rc.0"+tauri-plugin-os = "2.0.0-rc.0"+tauri-plugin-process = "2.0.0-rc.0"+tauri-plugin-decorum = "1.0.0"+tauri-plugin-dialog = "2.0.0-rc.0"+tauri-plugin-oauth = { git = "https://github.com/FabianLars/tauri-plugin-oauth", branch = "v2" }+tauri-specta = { version = "=2.0.0-rc.14", features = ["derive", "typescript"] }+serde = { version = "1", features = ["derive"] }serde_json = "1"specta = "=2.0.0-rc.19"-tauri-specta = { version = "=2.0.0-rc.14", features = ["derive", "typescript"] }specta-typescript = "0.0.6"-tauri-plugin-decorum = "1.0.0"swift-rs = "1.0.6"nix = { version = "0.29.0", features = ["fs"] }tokio = { version = "1.39.2", features = ["macros", "process", "fs"] }uuid = { version = "1.10.0", features = ["v4"] }scap = { git = "https://github.com/CapSoftware/scap" }-tauri-nspanel = { git = "https://github.com/ahkohd/tauri-nspanel", branch = "v2" }ffmpeg-sidecar = { git = "https://github.com/CapSoftware/ffmpeg-sidecar", branch = "main" }wgpu = "22.1.0"bytemuck = { version = "1.7", features = ["derive"] }@@ -48,12 +54,7 @@ nokhwa = { git = "https://github.com/Brendonovich/nokhwa", rev = "2de5a760d5f1","input-avfoundation","serialize",] }-cap-utils = { path = "../../../crates/utils" }-cap-project = { path = "../../../crates/project" }-cap-rendering = { path = "../../../crates/rendering" }-cap-ffmpeg = { path = "../../../crates/ffmpeg" }axum = { version = "0.7.5", features = ["ws"] }-tauri-plugin-dialog = "2.0.0-rc.0"tracing = "0.1.40"cpal = "0.15.3"indexmap = "2.5.0"@@ -61,9 +62,11 @@ num-traits = "0.2.19"tempfile = "3.12.0"ffmpeg-next = "7.0.4"chrono = "0.4.38"-tauri-plugin-store = "2.0.0-rc.0"-tauri-plugin-os = "2.0.0-rc.0"-tauri-plugin-process = "2.0.0-rc.0"++cap-utils = { path = "../../../crates/utils" }+cap-project = { path = "../../../crates/project" }+cap-rendering = { path = "../../../crates/rendering" }+cap-ffmpeg = { path = "../../../crates/ffmpeg" }[target.'cfg(target_os = "macos")'.dependencies]core-graphics = "0.24.0"diff --git a/apps/desktop-solid/src-tauri/capabilities/default.json b/apps/desktop-solid/src-tauri/capabilities/default.jsonindex 23de10311..322f0b477 100644--- a/apps/desktop-solid/src-tauri/capabilities/default.json+++ b/apps/desktop-solid/src-tauri/capabilities/default.json@@ -4,7 +4,7 @@"description": "Capability for the main window","windows": ["*"],"permissions": [- "core:default",+ "core:event:default","core:window:allow-close","core:window:allow-hide","core:window:allow-show",@@ -21,6 +21,7 @@"fs:default","dialog:allow-save","store:default",- "process:default"+ "process:default",+ "oauth:allow-start"]}diff --git a/apps/desktop-solid/src-tauri/src/lib.rs b/apps/desktop-solid/src-tauri/src/lib.rsindex 84c7f6836..7c5616638 100644--- a/apps/desktop-solid/src-tauri/src/lib.rs+++ b/apps/desktop-solid/src-tauri/src/lib.rs@@ -1197,6 +1197,7 @@ pub fn run() {.plugin(tauri_plugin_store::Builder::new().build()).plugin(tauri_plugin_os::init()).plugin(tauri_plugin_process::init())+ .plugin(tauri_plugin_oauth::init()).invoke_handler(specta_builder.invoke_handler()).setup(move |app| {specta_builder.mount_events(app);diff --git a/apps/desktop-solid/src/App.tsx b/apps/desktop-solid/src/App.tsxindex cd45320c5..9cf373c2b 100644--- a/apps/desktop-solid/src/App.tsx+++ b/apps/desktop-solid/src/App.tsx@@ -1,14 +1,10 @@-import {- Router,- useCurrentMatches,- useMatch,- useResolvedPath,-} from "@solidjs/router";+import { Router } from "@solidjs/router";import { FileRoutes } from "@solidjs/start/router";import { ErrorBoundary, Suspense } from "solid-js";import { QueryClient, QueryClientProvider } from "@tanstack/solid-query";import "@cap/ui-solid/main.css";+import "unfonts.css";const queryClient = new QueryClient();diff --git a/apps/desktop-solid/src/components/Header.tsx b/apps/desktop-solid/src/components/Header.tsxindex 83d529750..381b7b6be 100644--- a/apps/desktop-solid/src/components/Header.tsx+++ b/apps/desktop-solid/src/components/Header.tsx@@ -1,7 +1,7 @@export default function Header() {return (<div- class="flex items-center justify-start space-x-1 h-[44px] shrink-0 px-3 border-gray-200 border-b"+ class="flex items-center justify-start bg-gray-50 space-x-1 h-[44px] shrink-0 px-3 border-gray-200 border-b"data-tauri-drag-region/>);diff --git a/apps/desktop-solid/src/routes/(main).tsx b/apps/desktop-solid/src/routes/(main).tsxnew file mode 100644index 000000000..80785442c--- /dev/null+++ b/apps/desktop-solid/src/routes/(main).tsx@@ -0,0 +1,35 @@+import type { RouteSectionProps } from "@solidjs/router";+import { Suspense } from "solid-js";+import { Transition } from "solid-transition-group";++import Header from "../components/Header";++export default function (props: RouteSectionProps) {+ return (+ <div class="rounded-[1.5rem] bg-gray-100 border border-gray-200 w-screen h-screen flex flex-col overflow-hidden">+ <Header />+ <Transition+ mode="outin"+ enterClass="opacity-0 -translate-y-0.5"+ enterActiveClass="transition-[opacity,transform] duration-200"+ enterToClass="opacity-100 translate-0"+ exitClass="opacity-100"+ exitActiveClass="transition-[opacity,transform] duration-20"+ exitToClass="opacity-0"+ appear={false}+ >+ <Suspense+ fallback={+ <div class="w-full h-full flex items-center justify-center bg-gray-100">+ <div class="animate-spin">+ <IconCapLogo class="size-[4rem]" />+ </div>+ </div>+ }+ >+ {props.children}+ </Suspense>+ </Transition>+ </div>+ );+}diff --git a/apps/desktop-solid/src/routes/(main)/callback.template.ts b/apps/desktop-solid/src/routes/(main)/callback.template.tsnew file mode 100644index 000000000..fd51ff59e--- /dev/null+++ b/apps/desktop-solid/src/routes/(main)/callback.template.ts@@ -0,0 +1,33 @@+export default `+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta http-equiv="X-UA-Compatible" content="IE=edge">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <link rel="preconnect" href="https://fonts.googleapis.com">+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>+ <link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">+ <title>Cap Auth</title>+ <style>+ body {+ width: 100%;+ height: 100%;+ display: flex;+ align-items: center;+ justify-content: center;+ font-family: 'Open Sans', sans-serif;+ margin: 0;+ padding: 0;+ text-align: center;+ }+ </style>+</head>+<body>+ <div style="padding: 30px 0; width: 100%; max-width: 400px; margin: 0 auto; ">+ <svg xmlns="http://www.w3.org/2000/svg" style="width: 100px; height: auto; margin-bottom: 10px;" viewBox="0 0 719 269"><path fill="#0A486B" d="M474.954 156.466c-3.122 16.278-10.217 29.23-21.286 38.856-10.927 9.484-25.118 14.226-42.572 14.226-14.333 0-26.892-3.397-37.677-10.192-10.643-6.936-18.873-16.349-24.692-28.24-5.818-11.89-8.727-25.267-8.727-40.13 0-14.863 2.838-28.31 8.514-40.342 5.819-12.032 14.12-21.445 24.905-28.24C384.204 55.468 396.763 52 411.096 52c16.603 0 30.368 4.53 41.295 13.589 10.927 9.059 18.164 21.304 21.712 36.733l-27.885 1.486c-2.129-8.776-6.244-15.641-12.346-20.596-6.102-5.096-13.765-7.644-22.989-7.644-9.65 0-17.739 2.407-24.266 7.22-6.386 4.812-11.14 11.465-14.262 19.959-3.122 8.351-4.683 17.764-4.683 28.239 0 10.475 1.561 19.818 4.683 28.028 3.122 8.21 7.876 14.792 14.262 19.746 6.527 4.813 14.616 7.219 24.266 7.219 9.65 0 17.526-2.76 23.628-8.28 6.243-5.662 10.359-13.236 12.346-22.72l28.097 1.487zM486.826 127.801c2.271-11.607 7.734-20.596 16.391-26.965 8.656-6.512 19.796-9.768 33.419-9.768 16.177 0 28.452 4.106 36.825 12.316 8.372 8.21 12.559 20.171 12.559 35.883v39.281c0 2.973.567 5.096 1.703 6.37 1.277 1.132 3.051 1.698 5.321 1.698h4.257v19.535l-6.598.212h-.852c-3.831.142-7.734-.142-11.707-.849-3.832-.708-7.237-2.336-10.217-4.884-2.981-2.548-4.683-6.441-5.109-11.678-2.838 5.804-7.45 10.546-13.836 14.226-6.386 3.68-14.191 5.521-23.415 5.521-11.636 0-21.357-2.902-29.162-8.706-7.663-5.945-11.494-13.73-11.494-23.356 0-7.078 1.631-12.811 4.895-17.199 3.406-4.388 8.089-7.856 14.049-10.404 6.102-2.548 14.049-4.742 23.841-6.582l31.716-6.37c-.142-8.635-2.058-15.004-5.747-19.109-3.69-4.247-9.366-6.37-17.029-6.37-5.96 0-10.927 1.628-14.9 4.883-3.832 3.114-6.457 7.715-7.876 13.802l-27.034-1.487zm25.331 47.987c0 4.105 1.703 7.502 5.108 10.191 3.548 2.548 8.586 3.822 15.114 3.822 5.25 0 9.933-1.274 14.048-3.822 4.258-2.547 7.522-6.369 9.792-11.465 2.413-5.238 3.619-11.537 3.619-18.898v-1.061l-21.712 3.822-3.832.637c-5.25.991-9.366 1.981-12.346 2.972-2.838.991-5.179 2.619-7.024 4.884-1.845 2.123-2.767 5.096-2.767 8.918zM611.079 93.616h24.905l.851 23.569-2.128-2.76c2.838-7.503 7.308-13.236 13.41-17.199 6.244-4.105 13.765-6.158 22.563-6.158 10.502 0 19.371 2.62 26.608 7.857 7.237 5.237 12.63 12.315 16.178 21.233 3.689 8.776 5.534 18.684 5.534 29.726 0 11.041-1.845 21.02-5.534 29.938-3.548 8.776-8.941 15.783-16.178 21.02-7.237 5.238-16.106 7.857-26.608 7.857-5.818 0-11.139-.92-15.964-2.761-4.683-1.84-8.728-4.529-12.133-8.068-3.264-3.539-5.818-7.927-7.663-13.165l2.554-2.123V238h-26.395V93.616zm24.266 56.268c0 6.794.994 13.022 2.98 18.684 2.129 5.521 5.322 9.98 9.579 13.377 4.257 3.397 9.437 5.096 15.539 5.096 9.224 0 16.178-3.539 20.861-10.616 4.824-7.078 7.237-15.925 7.237-26.541 0-10.475-2.413-19.322-7.237-26.542-4.683-7.219-11.637-10.828-20.861-10.828-6.102 0-11.282 1.769-15.539 5.308-4.257 3.397-7.45 7.927-9.579 13.589-1.986 5.521-2.98 11.678-2.98 18.473z"></path><path fill="url(#paint0_linear_0_1)" d="M218.623 0H50C22.386 0 0 22.386 0 50v168.623c0 27.614 22.386 50 50 50h168.623c27.614 0 50-22.386 50-50V50c0-27.614-22.386-50-50-50z"></path><path fill="url(#paint1_radial_0_1)" d="M134.646 240.418c58.415 0 105.77-47.355 105.77-105.77s-47.355-105.77-105.77-105.77-105.77 47.355-105.77 105.77 47.355 105.77 105.77 105.77z"></path><path fill="url(#paint2_linear_0_1)" d="M134.983 224.972c49.699 0 89.988-40.289 89.988-89.988 0-49.7-40.289-89.989-89.988-89.989-49.7 0-89.989 40.29-89.989 89.989 0 49.699 40.29 89.988 89.989 89.988z"></path><path fill="url(#paint3_radial_0_1)" d="M134.983 202.81c37.46 0 67.828-30.368 67.828-67.828 0-37.46-30.368-67.827-67.828-67.827-37.46 0-67.827 30.367-67.827 67.827 0 37.46 30.367 67.828 67.827 67.828z"></path><defs><linearGradient id="paint0_linear_0_1" x1="134.311" x2="134.311" y1="0" y2="268.623" gradientUnits="userSpaceOnUse"><stop stop-color="#A8DBF8"></stop><stop offset="1" stop-color="#BCCBFF"></stop></linearGradient><radialGradient id="paint1_radial_0_1" cx="0" cy="0" r="1" gradientTransform="rotate(107.38 31.314 98.475) scale(149.225)" gradientUnits="userSpaceOnUse"><stop offset="0.063" stop-color="#84D3FF"></stop><stop offset="0.411" stop-color="#17ABFE"></stop><stop offset="0.906" stop-color="#0770D1"></stop></radialGradient><linearGradient id="paint2_linear_0_1" x1="134.983" x2="134.983" y1="44.995" y2="224.972" gradientUnits="userSpaceOnUse"><stop stop-color="#BBE8FF"></stop><stop offset="1" stop-color="#018FEF"></stop></linearGradient><radialGradient id="paint3_radial_0_1" cx="0" cy="0" r="1" gradientTransform="rotate(98.584 14.543 129.964) scale(68.5955)" gradientUnits="userSpaceOnUse"><stop stop-color="#7EC3FF"></stop><stop offset="1" stop-color="#EAF5FF"></stop></radialGradient></defs></svg>+ <h1 style="font-size: 21px; line-height: 26px;">You are now signed in. Please re-open the Cap desktop app to continue.</h1>+ </div>+</body>+</html>+`;diff --git a/apps/desktop-solid/src/routes/(main)/index.tsx b/apps/desktop-solid/src/routes/(main)/index.tsxnew file mode 100644index 000000000..fcc82eb4c--- /dev/null+++ b/apps/desktop-solid/src/routes/(main)/index.tsx@@ -0,0 +1,351 @@+import { cx } from "cva";+import {+ Show,+ type ValidComponent,+ createEffect,+ createMemo,+ createSignal,+} from "solid-js";+import { Select as KSelect } from "@kobalte/core/select";+import { SwitchTab, Button } from "@cap/ui-solid";+import { createMutation } from "@tanstack/solid-query";+import { createEventListener } from "@solid-primitives/event-listener";+import { cache, createAsync, redirect } from "@solidjs/router";++import { createCameraForLabel, createCameras } from "../../utils/media";+import {+ createAudioDevicesQuery,+ createCurrentRecordingQuery,+ createOptionsQuery,+ createWindowsQuery,+} from "../../utils/queries";+import { type CaptureWindow, commands, events } from "../../utils/tauri";+import {+ MenuItemList,+ PopperContent,+ topLeftAnimateClasses,+ MenuItem,+ topRightAnimateClasses,+} from "../editor/ui";+import { authStore } from "../../store";++const getAuth = cache(async () => {+ return (await authStore.get()) ?? redirect("/signin");+}, "getAuth");++export default function () {+ const cameras = createCameras();+ const options = createOptionsQuery();+ const windows = createWindowsQuery();+ const audioDevices = createAudioDevicesQuery();+ const currentRecording = createCurrentRecordingQuery();++ const camera = createCameraForLabel(() => options.data?.cameraLabel ?? "");++ const [windowSelectOpen, setWindowSelectOpen] = createSignal(false);++ events.showCapturesPanel.listen(() => {+ commands.showPreviousRecordingsWindow();+ });++ commands.showPreviousRecordingsWindow();++ type CameraOption = MediaDeviceInfo | { deviceId: string; label: string };++ const isRecording = () => !!currentRecording.data;++ const toggleRecording = createMutation(() => ({+ mutationFn: async () => {+ if (!isRecording()) await commands.startRecording();+ else await commands.stopRecording();+ },+ }));++ const auth = createAsync(() => getAuth());++ createEventListener(window, "mousedown", (e: MouseEvent) => {+ if (windowSelectOpen()) {+ const target = e.target as HTMLElement;+ if (!target.closest(".KSelect")) {+ setWindowSelectOpen(false);+ }+ }+ });++ return (+ <div class="flex flex-col p-[1rem] gap-[0.75rem] text-[0.875rem] font-[400] bg-gray-50">+ <Show when={auth() && options.data}>+ {(options) => {+ const selectedWindow = createMemo(() => {+ const d = options().captureTarget;+ if (d.type !== "window") return;+ return (windows.data ?? []).find((data) => data.id === d.id);+ });++ const audioDevice = () =>+ audioDevices.data?.find((d) => d.name === options().audioInputName);++ createEffect(() => console.log(audioDevice()));++ return (+ <>+ <KSelect<CaptureWindow | null>+ options={windows.data ?? []}+ optionValue="id"+ optionTextValue="name"+ placeholder="Window"+ gutter={8}+ open={windowSelectOpen()}+ onOpenChange={(o) => {+ // prevents tab onChange from interfering with dropdown trigger click+ if (o === false && options().captureTarget.type === "screen")+ return;+ setWindowSelectOpen(o);+ }}+ itemComponent={(props) => (+ <MenuItem<typeof KSelect.Item>+ as={KSelect.Item}+ item={props.item}+ >+ <KSelect.ItemLabel class="flex-1">+ {props.item.rawValue?.name}+ </KSelect.ItemLabel>+ </MenuItem>+ )}+ value={selectedWindow() ?? null}+ onChange={(d) => {+ if (!d) return;+ commands.setRecordingOptions({+ ...options(),+ captureTarget: { type: "window", id: d.id },+ });+ setWindowSelectOpen(false);+ }}+ placement="top-end"+ >+ <SwitchTab+ value={options().captureTarget.type}+ disabled={isRecording()}+ onChange={(s) => {+ console.log({ s });+ if (options().captureTarget.type === s) {+ setWindowSelectOpen(false);+ return;+ }+ if (s === "screen") {+ commands.setRecordingOptions({+ ...options(),+ captureTarget: { type: "screen" },+ });+ setWindowSelectOpen(false);+ } else if (s === "window") {+ if (windowSelectOpen()) {+ setWindowSelectOpen(false);+ } else {+ setWindowSelectOpen(true);+ }+ }+ }}+ >+ <SwitchTab.List>+ <SwitchTab.Trigger value="screen">Screen</SwitchTab.Trigger>+ <SwitchTab.Trigger<ValidComponent>+ as={(p) => <KSelect.Trigger<ValidComponent> {...p} />}+ value="window"+ class="w-full text-nowrap overflow-hidden px-2 group KSelect"+ >+ <KSelect.Value<CaptureWindow> class="flex flex-row items-center justify-center">+ {(item) => (+ <>+ <span class="flex-1 truncate">+ {item.selectedOption().name}+ </span>++ <IconCapChevronDown class="size-4 shrink-0 ui-group-expanded:-rotate-180 transform transition-transform" />+ </>+ )}+ </KSelect.Value>+ </SwitchTab.Trigger>+ </SwitchTab.List>+ </SwitchTab>+ <KSelect.Portal>+ <PopperContent<typeof KSelect.Content>+ as={KSelect.Content}+ class={topRightAnimateClasses}+ >+ <KSelect.Listbox+ class="max-h-52 max-w-64"+ as={MenuItemList}+ />+ </PopperContent>+ </KSelect.Portal>+ </KSelect>+ <div class="flex flex-col gap-[0.25rem] items-stretch">+ <label class="text-gray-400 text-[0.875rem]">Camera</label>+ <KSelect<CameraOption>+ options={[{ deviceId: "", label: "No Camera" }, ...cameras()]}+ optionValue="deviceId"+ optionTextValue="label"+ placeholder="No Camera"+ value={camera() ?? { deviceId: "", label: "No Camera" }}+ disabled={isRecording()}+ onChange={(d) => {+ if (!d) return;+ commands.setRecordingOptions({+ ...options(),+ cameraLabel: d.deviceId ? d.label : null,+ });+ }}+ itemComponent={(props) => (+ <MenuItem<typeof KSelect.Item>+ as={KSelect.Item}+ item={props.item}+ >+ <KSelect.ItemLabel class="flex-1">+ {props.item.rawValue.label}+ </KSelect.ItemLabel>+ </MenuItem>+ )}+ >+ <KSelect.Trigger class="h-[2rem] px-[0.375rem] flex flex-row gap-[0.375rem] border rounded-lg border-gray-200 w-full items-center disabled:text-gray-400 transition-colors KSelect">+ <IconCapCamera class="text-gray-400 size-[1.25rem]" />+ <KSelect.Value<CameraOption> class="flex-1 text-left truncate">+ {(state) => <>{state.selectedOption().label}</>}+ </KSelect.Value>+ <button+ type="button"+ class={cx(+ "px-[0.375rem] rounded-full text-[0.75rem]",+ camera()?.deviceId+ ? "bg-blue-50 text-blue-300"+ : "bg-red-50 text-red-300"+ )}+ onPointerDown={(e) => {+ if (!camera()?.deviceId) return;+ e.stopPropagation();+ e.preventDefault();+ }}+ onClick={(e) => {+ if (!camera()?.deviceId) return;+ e.stopPropagation();+ e.preventDefault();++ commands.setRecordingOptions({+ ...options(),+ cameraLabel: null,+ });+ }}+ >+ {camera()?.deviceId ? "On" : "Off"}+ </button>+ </KSelect.Trigger>+ <KSelect.Portal>+ <PopperContent<typeof KSelect.Content>+ as={KSelect.Content}+ class={topLeftAnimateClasses}+ >+ <MenuItemList<typeof KSelect.Listbox>+ as={KSelect.Listbox}+ />+ </PopperContent>+ </KSelect.Portal>+ </KSelect>+ </div>+ <div class="flex flex-col gap-[0.25rem] items-stretch">+ <label class="text-gray-400">Microphone</label>+ <KSelect<{ name: string }>+ options={[{ name: "No Audio" }, ...(audioDevices.data ?? [])]}+ optionValue="name"+ optionTextValue="name"+ placeholder="No Audio"+ value={audioDevice() ?? { name: "No Audio" }}+ disabled={isRecording()}+ onChange={(item) => {+ if (!item) return;+ commands.setRecordingOptions({+ ...options(),+ audioInputName:+ item.name !== "No Audio" ? item.name : null,+ });+ }}+ itemComponent={(props) => (+ <MenuItem<typeof KSelect.Item>+ as={KSelect.Item}+ item={props.item}+ >+ <KSelect.ItemLabel class="flex-1">+ {props.item.rawValue.name}+ </KSelect.ItemLabel>+ </MenuItem>+ )}+ >+ <KSelect.Trigger class="flex flex-row items-center h-[2rem] px-[0.375rem] gap-[0.375rem] border rounded-lg border-gray-200 w-full disabled:text-gray-400 transition-colors KSelect">+ <IconCapMicrophone class="text-gray-400 size-[1.25rem]" />+ <KSelect.Value<{+ name: string;+ }> class="flex-1 text-left truncate">+ {(state) => <>{state.selectedOption().name}</>}+ </KSelect.Value>+ <button+ type="button"+ class={cx(+ "px-[0.375rem] rounded-full text-[0.75rem]",+ options().audioInputName+ ? "bg-blue-50 text-blue-300"+ : "bg-red-50 text-red-300"+ )}+ onPointerDown={(e) => {+ if (!options().audioInputName) return;+ e.stopPropagation();+ e.preventDefault();+ }}+ onClick={(e) => {+ if (!options().audioInputName) return;+ e.stopPropagation();+ e.preventDefault();++ commands.setRecordingOptions({+ ...options(),+ audioInputName: null,+ });+ }}+ >+ {options().audioInputName ? "On" : "Off"}+ </button>+ </KSelect.Trigger>+ <KSelect.Portal>+ <PopperContent<typeof KSelect.Content>+ as={KSelect.Content}+ class={topLeftAnimateClasses}+ >+ <MenuItemList<typeof KSelect.Listbox>+ class="max-h-40 overflow-y-auto"+ as={KSelect.Listbox}+ />+ </PopperContent>+ </KSelect.Portal>+ </KSelect>+ </div>+ <Button+ disabled={toggleRecording.isPending}+ variant={isRecording() ? "destructive" : "primary"}+ size="md"+ onClick={() => toggleRecording.mutate()}+ >+ {isRecording() ? "Stop Recording" : "Start Recording"}+ </Button>+ <a+ href="https://cap.so/dashboard"+ target="_blank"+ rel="noreferrer"+ class="text-gray-400 text-[0.875rem] mx-auto hover:text-gray-500 hover:underline"+ >+ Open Cap on Web+ </a>+ </>+ );+ }}+ </Show>+ </div>+ );+}diff --git a/apps/desktop-solid/src/routes/(main)/signin.tsx b/apps/desktop-solid/src/routes/(main)/signin.tsxnew file mode 100644index 000000000..2058e2a7d--- /dev/null+++ b/apps/desktop-solid/src/routes/(main)/signin.tsx@@ -0,0 +1,70 @@+import { Button } from "@cap/ui-solid";+import * as shell from "@tauri-apps/plugin-shell";+import { listen } from "@tauri-apps/api/event";+import { invoke } from "@tauri-apps/api/core";+import { action, redirect, useAction, useSubmission } from "@solidjs/router";++import callbackTemplate from "./callback.template";+import { authStore } from "../../store";++const signInAction = action(async () => {+ let res: (url: URL) => void;++ const stopListening = await listen(+ "oauth://url",+ (data: { payload: string }) => {+ if (!data.payload.includes("token")) {+ return;+ }++ const urlObject = new URL(data.payload);++ res(urlObject);+ }+ );++ const port: string = await invoke("plugin:oauth|start", {+ config: { response: callbackTemplate },+ });++ await shell.open(`https://cap.so/api/desktop/session/request?port=${port}`);++ const url = await new Promise<URL>((r) => {+ res = r;+ });+ stopListening();++ const token = url.searchParams.get("token");+ const expires = Number(url.searchParams.get("expires"));+ if (!token || !expires) {+ throw new Error("Invalid token or expires");+ }++ await authStore.set({ token, expires });++ return redirect("/");+});++export default function Page() {+ const signIn = useAction(signInAction);+ const submission = useSubmission(signInAction);++ return (+ <div class="flex flex-col p-[1rem] gap-[0.75rem] text-[0.875rem] font-[400] flex-1 bg-gray-100">+ <div class="space-y-[0.375rem] flex-1">+ <IconCapLogo class="size-[3rem]" />+ <h1 class="text-[1rem] font-[700]">Sign in to Cap</h1>+ <p class="text-gray-400">+ Effortless, instant screen sharing. Open source and cross-platform.+ </p>+ </div>+ {submission.pending ? (+ <Button variant="secondary" onClick={() => submission.clear()}>+ Cancel sign in+ </Button>+ ) : (+ <Button onClick={() => signIn()}>Sign in with your browser</Button>+ )}+ </div>+ );+}diff --git a/apps/desktop-solid/src/routes/createPresets.ts b/apps/desktop-solid/src/routes/createPresets.tsindex bdbf1cec3..929b85661 100644--- a/apps/desktop-solid/src/routes/createPresets.ts+++ b/apps/desktop-solid/src/routes/createPresets.ts@@ -1,17 +1,7 @@import { createResource, onCleanup } from "solid-js";-import { Store } from "@tauri-apps/plugin-store";import type { ProjectConfiguration } from "../utils/tauri";--const store = new Store("frontend-stuff");--export type PresetsStore = {- presets: Array<{- name: string;- config: ProjectConfiguration;- }>;- default?: number;-};+import { presetsStore, type PresetsStore } from "../store";export type CreatePreset = {name: string;@@ -21,14 +11,11 @@ export type CreatePreset = {export function createPresets() {const [query, queryActions] = createResource(async () => {- return (- (await store.get<PresetsStore>("presets")) ??- ({ presets: [] } as PresetsStore)- );+ return (await presetsStore.get()) ?? ({ presets: [] } as PresetsStore);});const [cleanup] = createResource(() =>- store.onKeyChange<PresetsStore>("presets", (data) => {+ presetsStore.listen((data) => {if (data) queryActions.mutate(data);}));@@ -40,8 +27,7 @@ export function createPresets() {const newValue = fn(p);- await store.set("presets", newValue);- await store.save();+ await presetsStore.set(newValue);}return {diff --git a/apps/desktop-solid/src/routes/index.tsx b/apps/desktop-solid/src/routes/index.tsxdeleted file mode 100644index 4b98abdd2..000000000--- a/apps/desktop-solid/src/routes/index.tsx+++ /dev/null@@ -1,376 +0,0 @@-import { cx } from "cva";-import {- For,- Show,- Suspense,- type ValidComponent,- createEffect,- createMemo,- createSignal,-} from "solid-js";-import { Select as KSelect } from "@kobalte/core/select";-import { SwitchTab, Button } from "@cap/ui-solid";--import { createCameraForLabel, createCameras } from "../utils/media";-import {- createAudioDevicesQuery,- createCurrentRecordingQuery,- createOptionsQuery,- createWindowsQuery,-} from "../utils/queries";-import { type CaptureWindow, commands, events } from "../utils/tauri";-import Header from "../components/Header";-import {- MenuItemList,- PopperContent,- topLeftAnimateClasses,- MenuItem,- topRightAnimateClasses,-} from "./editor/ui";-import { createMutation } from "@tanstack/solid-query";--export default function () {- const cameras = createCameras();- const options = createOptionsQuery();- const windows = createWindowsQuery();- const audioDevices = createAudioDevicesQuery();- const currentRecording = createCurrentRecordingQuery();-- const camera = createCameraForLabel(() => options.data?.cameraLabel ?? "");-- const [windowSelectOpen, setWindowSelectOpen] = createSignal(false);-- events.showCapturesPanel.listen(() => {- commands.showPreviousRecordingsWindow();- });-- commands.showPreviousRecordingsWindow();-- type CameraOption = MediaDeviceInfo | { deviceId: string; label: string };-- const handleBodyClick = (e: MouseEvent) => {- if (windowSelectOpen()) {- const target = e.target as HTMLElement;- if (!target.closest(".KSelect")) {- setWindowSelectOpen(false);- }- }- };-- const isRecording = () => !!currentRecording.data;-- const toggleRecording = createMutation(() => ({- mutationFn: async () => {- if (!isRecording()) await commands.startRecording();- else await commands.stopRecording();- },- }));-- return (- // biome-ignore lint/a11y/useKeyWithClickEvents: workaround- <div- class="rounded-[1.5rem] bg-gray-50 border border-gray-200 w-screen h-screen flex flex-col overflow-hidden"- onClick={handleBodyClick}- >- <Header />-- <Suspense- fallback={- <div class="w-full h-full flex items-center justify-center bg-gray-100">- <div class="animate-spin">- <IconCapLogo class="size-[4rem]" />- </div>- </div>- }- >- <div class="flex flex-col p-[1rem] gap-[0.75rem] text-[0.875rem] font-[400]">- <Show when={options.data}>- {(options) => {- const selectedWindow = createMemo(() => {- const d = options().captureTarget;- if (d.type !== "window") return;- return (windows.data ?? []).find((data) => data.id === d.id);- });-- const audioDevice = () =>- audioDevices.data?.find(- (d) => d.name === options().audioInputName- );-- createEffect(() => console.log(audioDevice()));-- return (- <>- <KSelect<CaptureWindow | null>- options={windows.data ?? []}- optionValue="id"- optionTextValue="name"- placeholder="Window"- gutter={8}- open={windowSelectOpen()}- onOpenChange={(o) => {- // prevents tab onChange from interfering with dropdown trigger click- if (- o === false &&- options().captureTarget.type === "screen"- )- return;- setWindowSelectOpen(o);- }}- itemComponent={(props) => (- <MenuItem<typeof KSelect.Item>- as={KSelect.Item}- item={props.item}- >- <KSelect.ItemLabel class="flex-1">- {props.item.rawValue?.name}- </KSelect.ItemLabel>- </MenuItem>- )}- value={selectedWindow() ?? null}- onChange={(d) => {- if (!d) return;- commands.setRecordingOptions({- ...options(),- captureTarget: { type: "window", id: d.id },- });- setWindowSelectOpen(false);- }}- placement="top-end"- >- <SwitchTab- value={options().captureTarget.type}- disabled={isRecording()}- onChange={(s) => {- console.log({ s });- if (options().captureTarget.type === s) {- setWindowSelectOpen(false);- return;- }- if (s === "screen") {- commands.setRecordingOptions({- ...options(),- captureTarget: { type: "screen" },- });- setWindowSelectOpen(false);- } else if (s === "window") {- if (windowSelectOpen()) {- setWindowSelectOpen(false);- } else {- setWindowSelectOpen(true);- }- }- }}- >- <SwitchTab.List>- <SwitchTab.Trigger value="screen">- Screen- </SwitchTab.Trigger>- <SwitchTab.Trigger<ValidComponent>- as={(p) => <KSelect.Trigger<ValidComponent> {...p} />}- value="window"- class="w-full text-nowrap overflow-hidden px-2 group KSelect"- >- <KSelect.Value<CaptureWindow> class="flex flex-row items-center justify-center">- {(item) => (- <>- <span class="flex-1 truncate">- {item.selectedOption().name}- </span>-- <IconCapChevronDown class="size-4 shrink-0 ui-group-expanded:-rotate-180 transform transition-transform" />- </>- )}- </KSelect.Value>- </SwitchTab.Trigger>- </SwitchTab.List>- </SwitchTab>- <KSelect.Portal>- <PopperContent<typeof KSelect.Content>- as={KSelect.Content}- class={topRightAnimateClasses}- >- <KSelect.Listbox- class="max-h-52 max-w-64"- as={MenuItemList}- />- </PopperContent>- </KSelect.Portal>- </KSelect>- <div class="flex flex-col gap-[0.25rem] items-stretch">- <label class="text-gray-400 text-[0.875rem]">Camera</label>- <KSelect<CameraOption>- options={[- { deviceId: "", label: "No Camera" },- ...cameras(),- ]}- optionValue="deviceId"- optionTextValue="label"- placeholder="No Camera"- value={camera() ?? { deviceId: "", label: "No Camera" }}- disabled={isRecording()}- onChange={(d) => {- if (!d) return;- commands.setRecordingOptions({- ...options(),- cameraLabel: d.deviceId ? d.label : null,- });- }}- itemComponent={(props) => (- <MenuItem<typeof KSelect.Item>- as={KSelect.Item}- item={props.item}- >- <KSelect.ItemLabel class="flex-1">- {props.item.rawValue.label}- </KSelect.ItemLabel>- </MenuItem>- )}- >- <KSelect.Trigger class="h-[2rem] px-[0.375rem] flex flex-row gap-[0.375rem] border rounded-lg border-gray-200 w-full items-center disabled:text-gray-400 transition-colors KSelect">- <IconCapCamera class="text-gray-400 size-[1.25rem]" />- <KSelect.Value<CameraOption> class="flex-1 text-left truncate">- {(state) => <>{state.selectedOption().label}</>}- </KSelect.Value>- <button- type="button"- class={cx(- "px-[0.375rem] rounded-full text-[0.75rem]",- camera()?.deviceId- ? "bg-blue-50 text-blue-300"- : "bg-red-50 text-red-300"- )}- onPointerDown={(e) => {- if (!camera()?.deviceId) return;- e.stopPropagation();- e.preventDefault();- }}- onClick={(e) => {- if (!camera()?.deviceId) return;- e.stopPropagation();- e.preventDefault();-- commands.setRecordingOptions({- ...options(),- cameraLabel: null,- });- }}- >- {camera()?.deviceId ? "On" : "Off"}- </button>- </KSelect.Trigger>- <KSelect.Portal>- <PopperContent<typeof KSelect.Content>- as={KSelect.Content}- class={topLeftAnimateClasses}- >- <MenuItemList<typeof KSelect.Listbox>- as={KSelect.Listbox}- />- </PopperContent>- </KSelect.Portal>- </KSelect>- </div>- <div class="flex flex-col gap-[0.25rem] items-stretch">- <label class="text-gray-400">Microphone</label>- <KSelect<{ name: string }>- options={[- { name: "No Audio" },- ...(audioDevices.data ?? []),- ]}- optionValue="name"- optionTextValue="name"- placeholder="No Audio"- value={audioDevice() ?? { name: "No Audio" }}- disabled={isRecording()}- onChange={(item) => {- if (!item) return;- commands.setRecordingOptions({- ...options(),- audioInputName:- item.name !== "No Audio" ? item.name : null,- });- }}- itemComponent={(props) => (- <MenuItem<typeof KSelect.Item>- as={KSelect.Item}- item={props.item}- >- <KSelect.ItemLabel class="flex-1">- {props.item.rawValue.name}- </KSelect.ItemLabel>- </MenuItem>- )}- >- <KSelect.Trigger class="flex flex-row items-center h-[2rem] px-[0.375rem] gap-[0.375rem] border rounded-lg border-gray-200 w-full disabled:text-gray-400 transition-colors KSelect">- <IconCapMicrophone class="text-gray-400 size-[1.25rem]" />- <KSelect.Value<{- name: string;- }> class="flex-1 text-left truncate">- {(state) => <>{state.selectedOption().name}</>}- </KSelect.Value>- <button- type="button"- class={cx(- "px-[0.375rem] rounded-full text-[0.75rem]",- options().audioInputName- ? "bg-blue-50 text-blue-300"- : "bg-red-50 text-red-300"- )}- onPointerDown={(e) => {- if (!options().audioInputName) return;- e.stopPropagation();- e.preventDefault();- }}- onClick={(e) => {- if (!options().audioInputName) return;- e.stopPropagation();- e.preventDefault();-- commands.setRecordingOptions({- ...options(),- audioInputName: null,- });- }}- >- {options().audioInputName ? "On" : "Off"}- </button>- </KSelect.Trigger>- <KSelect.Portal>- <PopperContent<typeof KSelect.Content>- as={KSelect.Content}- class={topLeftAnimateClasses}- >- <MenuItemList<typeof KSelect.Listbox>- class="max-h-40 overflow-y-auto"- as={KSelect.Listbox}- />- </PopperContent>- </KSelect.Portal>- </KSelect>- </div>- <Button- disabled={toggleRecording.isPending}- variant={isRecording() ? "destructive" : "primary"}- size="md"- onClick={() => toggleRecording.mutate()}- >- {isRecording() ? "Stop Recording" : "Start Recording"}- </Button>- <a- href="https://cap.so/dashboard"- target="_blank"- rel="noreferrer"- class="text-gray-400 text-[0.875rem] mx-auto hover:text-gray-500 hover:underline"- >- Open Cap on Web- </a>- </>- );- }}- </Show>- </div>- </Suspense>- </div>- );-}diff --git a/apps/desktop-solid/src/store.ts b/apps/desktop-solid/src/store.tsnew file mode 100644index 000000000..e82db4a1e--- /dev/null+++ b/apps/desktop-solid/src/store.ts@@ -0,0 +1,38 @@+import { Store } from "@tauri-apps/plugin-store";++import type { ProjectConfiguration } from "./utils/tauri";++const store = new Store("store");++export type PresetsStore = {+ presets: Array<{+ name: string;+ config: ProjectConfiguration;+ }>;+ default?: number;+};++export const presetsStore = {+ get: () => store.get<PresetsStore>("presets"),+ set: async (value: PresetsStore) => {+ await store.set("presets", value);+ await store.save();+ },+ listen: (fn: (data: PresetsStore | null) => void) =>+ store.onKeyChange<PresetsStore>("presets", fn),+};++export type AuthStore = {+ token: string;+ expires: number;+};++export const authStore = {+ get: () => store.get<AuthStore>("auth"),+ set: async (value: AuthStore | null) => {+ await store.set("auth", value);+ await store.save();+ },+ listen: (fn: (data: AuthStore | null) => void) =>+ store.onKeyChange<AuthStore>("presets", fn),+};diff --git a/packages/ui-solid/src/index.ts b/packages/ui-solid/src/index.tsindex fecccee14..642e4f246 100644--- a/packages/ui-solid/src/index.ts+++ b/packages/ui-solid/src/index.ts@@ -1,4 +1,2 @@-import "unfonts.css";-export * from "./Button";export * from "./SwitchTab";