Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Add feedback collection window / API route

Richie McIlroy7bb37cf09cdd
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index d6ebd1ee4..cddae2a0b 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -1144,7 +1144,7 @@ fn open_main_window(app: AppHandle) {
let Some(window) = WebviewWindow::builder(&app, "main", tauri::WebviewUrl::App("/".into()))
.title("Cap")
- .inner_size(300.0, 325.0)
+ .inner_size(300.0, 375.0)
.resizable(false)
.maximized(false)
.shadow(true)
@@ -1164,6 +1164,28 @@ fn open_main_window(app: AppHandle) {
window.set_traffic_lights_inset(14.0, 22.0).unwrap();
}
+#[tauri::command]
+#[specta::specta]
+async fn open_feedback_window(app: AppHandle) {
+ let window =
+ WebviewWindow::builder(&app, "feedback", tauri::WebviewUrl::App("/feedback".into()))
+ .title("Cap Feedback")
+ .inner_size(400.0, 400.0)
+ .resizable(false)
+ .maximized(false)
+ .shadow(true)
+ .accept_first_mouse(true)
+ .transparent(true)
+ .hidden_title(true)
+ .title_bar_style(tauri::TitleBarStyle::Overlay)
+ .build()
+ .unwrap();
+
+ window.create_overlay_titlebar().unwrap();
+ #[cfg(target_os = "macos")]
+ window.set_traffic_lights_inset(14.0, 22.0).unwrap();
+}
+
#[tauri::command]
#[specta::specta]
async fn upload_rendered_video(
@@ -1280,7 +1302,8 @@ pub fn run() {
permissions::do_permissions_check,
permissions::request_permission,
upload_rendered_video,
- get_recording_meta
+ get_recording_meta,
+ open_feedback_window
])
.events(tauri_specta::collect_events![
RecordingOptionsChanged,
diff --git a/apps/desktop/src/routes/(main)/feedback.tsx b/apps/desktop/src/routes/(main)/feedback.tsx
new file mode 100644
index 000000000..bcedc74cc
--- /dev/null
+++ b/apps/desktop/src/routes/(main)/feedback.tsx
@@ -0,0 +1,121 @@
+import { Button } from "@cap/ui-solid";
+import { clientEnv } from "../../utils/env";
+import { createSignal, onMount, Show } from "solid-js";
+import { authStore } from "../../store";
+import { getCurrentWindow } from "@tauri-apps/api/window";
+
+export default function Page() {
+ let textareaRef: HTMLTextAreaElement | undefined;
+ const [isSubmitting, setIsSubmitting] = createSignal(false);
+ const [feedbackText, setFeedbackText] = createSignal("");
+ const [isSubmitted, setIsSubmitted] = createSignal(false);
+
+ onMount(() => {
+ if (textareaRef) {
+ textareaRef.focus();
+ }
+ });
+
+ const handleSubmit = async (e: Event) => {
+ e.preventDefault();
+ if (!feedbackText().trim()) return;
+
+ setIsSubmitting(true);
+ try {
+ const auth = await authStore.get();
+
+ if (!auth) {
+ console.error("User not authenticated");
+ window.close();
+ return;
+ }
+
+ const formData = new FormData();
+ formData.append("feedback", feedbackText());
+
+ const response = await fetch(
+ `${clientEnv.VITE_SERVER_URL}/api/desktop/feedback?origin=${window.location.origin}`,
+ {
+ method: "POST",
+ headers: {
+ Authorization: `Bearer ${auth.token}`,
+ },
+ body: formData,
+ }
+ );
+
+ if (!response.ok) {
+ throw new Error("Failed to submit feedback");
+ }
+
+ const data = await response.json();
+ console.log("Feedback submitted:", data);
+ setFeedbackText("");
+ setIsSubmitted(true);
+ } catch (error) {
+ console.error("Error submitting feedback:", error);
+ } finally {
+ setIsSubmitting(false);
+ }
+ };
+
+ return (
+ <div class="flex flex-col p-[1rem] gap-[0.75rem] text-[0.875rem] font-[400] flex-1 bg-gray-100">
+ <Show
+ when={!isSubmitted()}
+ fallback={
+ <div class="flex flex-col items-center justify-center h-full text-center">
+ <div>
+ <IconLucideSmile class="size-[5rem] text-gray-200 mb-[1rem]" />
+ </div>
+ <h2 class="text-[1.15rem] font-[500] mb-[1.5rem]">
+ Thank you, your feedback has been received.
+ </h2>
+ <Button
+ onClick={() => {
+ const window = getCurrentWindow();
+ window.close();
+ }}
+ type="button"
+ >
+ Close Window
+ </Button>
+ </div>
+ }
+ >
+ <h2 class="text-[1rem] font-[600] mb-[0.25rem]">
+ Feedback / Report a bug
+ </h2>
+ <p class="text-gray-400 mb-[1rem]">
+ Help us improve Cap by submitting feedback or reporting bugs. We'll
+ get right on it.
+ </p>
+ <form>
+ <textarea
+ ref={textareaRef}
+ value={feedbackText()}
+ onInput={(e) => setFeedbackText(e.currentTarget.value)}
+ class="w-full h-[150px] p-[0.5rem] border border-gray-300 rounded-md resize-none focus:outline-none focus:ring-2 focus:ring-blue-500"
+ placeholder="Please enter your feedback here..."
+ autofocus
+ ></textarea>
+ <Button
+ onClick={handleSubmit}
+ type="button"
+ class="mt-[1rem] flex items-center justify-between gap-[0.5rem]"
+ disabled={isSubmitting()}
+ >
+ {isSubmitting() ? (
+ <>
+ Submitting...
+ <IconLucideLoaderCircle class="size-[1rem] animate-spin" />
+ </>
+ ) : (
+ "Submit Feedback"
+ )}
+ </Button>
+ </form>
+ </Show>
+ </div>
+ );
+}
diff --git a/apps/desktop/src/routes/(main)/index.tsx b/apps/desktop/src/routes/(main)/index.tsx
index 2f70e2bcd..daa9dfe05 100644
--- a/apps/desktop/src/routes/(main)/index.tsx
+++ b/apps/desktop/src/routes/(main)/index.tsx
@@ -80,7 +80,7 @@ export default function () {
createUpdateCheck();
return (
- <div class="flex flex-col p-[1rem] gap-[0.75rem] text-[0.875rem] font-[400] bg-gray-50">
+ <div class="flex justify-center flex-col p-[1rem] gap-[0.75rem] text-[0.875rem] font-[400] bg-gray-50 h-full">
<Show when={options.data}>
{(options) => {
const camera = createCameraForLabel(
@@ -101,6 +101,20 @@ export default function () {
return (
<>
+ <div class="absolute top-3 right-3">
+ <Button
+ variant="secondary"
+ size="xs"
+ onClick={() => {
+ commands.openFeedbackWindow();
+ }}
+ >
+ Feedback
+ </Button>
+ </div>
+ <div class="flex items-center justify-between">
+ <IconCapLogoFull class="w-[90px] h-auto" />
+ </div>
<KSelect<CaptureWindow | null>
options={windows.data ?? []}
optionValue="id"
diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.ts
index fe10f512a..37a0336f5 100644
--- a/apps/desktop/src/utils/tauri.ts
+++ b/apps/desktop/src/utils/tauri.ts
@@ -170,6 +170,9 @@ async uploadRenderedVideo(videoId: string, project: ProjectConfiguration) : Prom
},
async getRecordingMeta(id: string) : Promise<RecordingMeta> {
return await TAURI_INVOKE("get_recording_meta", { id });
+},
+async openFeedbackWindow() : Promise<void> {
+ await TAURI_INVOKE("open_feedback_window");
}
}
diff --git a/apps/web/app/api/desktop/feedback/route.ts b/apps/web/app/api/desktop/feedback/route.ts
new file mode 100644
index 000000000..a9d339581
--- /dev/null
+++ b/apps/web/app/api/desktop/feedback/route.ts
@@ -0,0 +1,140 @@
+import { type NextRequest } from "next/server";
+import { getCurrentUser } from "@cap/database/auth/session";
+import { cookies } from "next/headers";
+
+const allowedOrigins = [
+ process.env.NEXT_PUBLIC_URL,
+ "http://localhost:3001",
+ "http://localhost:3000",
+ "tauri://localhost",
+ "http://tauri.localhost",
+ "https://tauri.localhost",
+];
+
+export async function OPTIONS(req: NextRequest) {
+ const params = req.nextUrl.searchParams;
+ const origin = params.get("origin") || null;
+ const originalOrigin = req.nextUrl.origin;
+
+ return new Response(null, {
+ status: 200,
+ headers: {
+ "Access-Control-Allow-Origin":
+ origin && allowedOrigins.includes(origin)
+ ? origin
+ : allowedOrigins.includes(originalOrigin)
+ ? originalOrigin
+ : "null",
+ "Access-Control-Allow-Credentials": "true",
+ "Access-Control-Allow-Methods": "POST, OPTIONS",
+ "Access-Control-Allow-Headers": "Content-Type, Authorization, sentry-trace, baggage",
+ },
+ });
+}
+
+export async function POST(req: NextRequest) {
+
+ const token = req.headers.get("authorization")?.split(" ")[1];
+ if (token) {
+ cookies().set({
+ name: "next-auth.session-token",
+ value: token,
+ path: "/",
+ sameSite: "none",
+ secure: true,
+ httpOnly: true,
+ });
+ }
+
+ const user = await getCurrentUser();
+ const params = req.nextUrl.searchParams;
+ const origin = params.get("origin") || null;
+ const originalOrigin = req.nextUrl.origin;
+
+
+ if (!user) {
+ return new Response(JSON.stringify({ error: "User not authenticated" }), {
+ status: 401,
+ headers: {
+ "Content-Type": "application/json",
+ "Access-Control-Allow-Origin":
+ origin && allowedOrigins.includes(origin)
+ ? origin
+ : allowedOrigins.includes(originalOrigin)
+ ? originalOrigin
+ : "null",
+ "Access-Control-Allow-Credentials": "true",
+ },
+ });
+ }
+
+ const formData = await req.formData();
+ const feedbackText = formData.get("feedback") as string;
+
+
+ if (!feedbackText) {
+ return new Response(JSON.stringify({ error: "Feedback text is required" }), {
+ status: 400,
+ headers: {
+ "Content-Type": "application/json",
+ "Access-Control-Allow-Origin":
+ origin && allowedOrigins.includes(origin)
+ ? origin
+ : allowedOrigins.includes(originalOrigin)
+ ? originalOrigin
+ : "null",
+ "Access-Control-Allow-Credentials": "true",
+ },
+ });
+ }
+
+ try {
+ // Send feedback to Discord channel
+ const discordWebhookUrl = process.env.DISCORD_FEEDBACK_WEBHOOK_URL;
+ if (!discordWebhookUrl) {
+ throw new Error("Discord webhook URL is not configured");
+ }
+
+ const response = await fetch(discordWebhookUrl, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ content: `New feedback from ${user.email}:\n${feedbackText}`,
+ }),
+ });
+
+ if (!response.ok) {
+ throw new Error(`Failed to send feedback to Discord: ${response.statusText}`);
+ }
+
+ return new Response(JSON.stringify({ success: true, message: "Feedback submitted successfully" }), {
+ status: 200,
+ headers: {
+ "Content-Type": "application/json",
+ "Access-Control-Allow-Origin":
+ origin && allowedOrigins.includes(origin)
+ ? origin
+ : allowedOrigins.includes(originalOrigin)
+ ? originalOrigin
+ : "null",
+ "Access-Control-Allow-Credentials": "true",
+ },
+ });
+ } catch (error) {
+ return new Response(JSON.stringify({ error: "Failed to submit feedback" }), {
+ status: 500,
+ headers: {
+ "Content-Type": "application/json",
+ "Access-Control-Allow-Origin":
+ origin && allowedOrigins.includes(origin)
+ ? origin
+ : allowedOrigins.includes(originalOrigin)
+ ? originalOrigin
+ : "null",
+ "Access-Control-Allow-Credentials": "true",
+ },
+ });
+ }
+}
\ No newline at end of file
diff --git a/packages/ui-solid/icons/logo-full.svg b/packages/ui-solid/icons/logo-full.svg
new file mode 100644
index 000000000..61f9aa7c5
--- /dev/null
+++ b/packages/ui-solid/icons/logo-full.svg
@@ -0,0 +1,8 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="103" height="40" viewBox="0 0 103 40" fill="none">
+<rect x="0.25" y="0.25" width="39.5" height="39.5" rx="7.75" fill="white"/>
+<rect x="0.25" y="0.25" width="39.5" height="39.5" rx="7.75" stroke="#E7EAF0" stroke-width="0.5"/>
+<path d="M20 36C28.8365 36 36 28.8365 36 20C36 11.1635 28.8365 4 20 4C11.1635 4 4 11.1635 4 20C4 28.8365 11.1635 36 20 36Z" fill="#4785FF"/>
+<path d="M20.0001 33C27.1797 33 33 27.1797 33 20.0001C33 12.8203 27.1797 7 20.0001 7C12.8203 7 7 12.8204 7 20.0001C7 27.1797 12.8204 33 20.0001 33Z" fill="#ADC9FF"/>
+<path d="M20.0001 30.0002C25.5229 30.0002 30.0002 25.5229 30.0002 20.0001C30.0002 14.4773 25.5229 10.0002 20.0001 10.0002C14.4773 10.0002 10.0002 14.4773 10.0002 20.0001C10.0002 25.5229 14.4773 30.0002 20.0001 30.0002Z" fill="white"/>
+<path d="M58.416 30.448C53.012 30.448 49.204 26.584 49.204 20.088C49.204 13.704 52.872 9.672 58.472 9.672C63.54 9.672 66.256 12.332 67.096 16.84L63.288 17.036C62.812 14.432 61.216 12.836 58.472 12.836C55.084 12.836 52.984 15.664 52.984 20.088C52.984 24.568 55.14 27.284 58.444 27.284C61.384 27.284 62.952 25.576 63.4 22.72L67.208 22.916C66.424 27.592 63.456 30.448 58.416 30.448ZM74.6451 30.336C71.5091 30.336 69.4371 28.852 69.4371 26.248C69.4371 23.672 71.0331 22.3 74.3091 21.656L79.2651 20.676C79.2651 18.576 78.2851 17.484 76.4091 17.484C74.6451 17.484 73.6931 18.296 73.3571 19.808L69.6891 19.64C70.2771 16.504 72.6851 14.712 76.4091 14.712C80.6651 14.712 82.8491 16.952 82.8491 20.928V26.36C82.8491 27.172 83.1291 27.396 83.6891 27.396H84.1651V30C83.9411 30.056 83.3531 30.112 82.8771 30.112C81.2531 30.112 80.0491 29.524 79.7411 27.676C79.0131 29.272 77.1091 30.336 74.6451 30.336ZM75.3731 27.732C77.7531 27.732 79.2651 26.22 79.2651 23.952V23.112L75.4011 23.896C73.8051 24.204 73.1611 24.876 73.1611 25.912C73.1611 27.088 73.9451 27.732 75.3731 27.732ZM86.8741 34.2V15.048H90.3181L90.3741 17.26C91.2421 15.608 92.8941 14.712 94.8541 14.712C99.1101 14.712 101.21 18.212 101.21 22.524C101.21 26.836 99.0821 30.336 94.8261 30.336C92.9221 30.336 91.2701 29.412 90.4581 27.956V34.2H86.8741ZM93.9861 27.424C96.1701 27.424 97.4861 25.604 97.4861 22.524C97.4861 19.444 96.1701 17.624 93.9861 17.624C91.8021 17.624 90.4581 19.276 90.4581 22.524C90.4581 25.772 91.7741 27.424 93.9861 27.424Z" fill="#12161F"/>
+</svg>
\ No newline at end of file
diff --git a/packages/ui-solid/src/auto-imports.d.ts b/packages/ui-solid/src/auto-imports.d.ts
index adbf431b1..5cf331415 100644
--- a/packages/ui-solid/src/auto-imports.d.ts
+++ b/packages/ui-solid/src/auto-imports.d.ts
@@ -27,6 +27,7 @@ declare global {
const IconCapInset: typeof import('~icons/cap/inset.jsx')['default']
const IconCapLayout: typeof import('~icons/cap/layout.jsx')['default']
const IconCapLogo: typeof import('~icons/cap/logo.jsx')['default']
+ const IconCapLogoFull: typeof import('~icons/cap/logo-full.jsx')['default']
const IconCapMessageBubble: typeof import('~icons/cap/message-bubble.jsx')['default']
const IconCapMicrophone: typeof import('~icons/cap/microphone.jsx')['default']
const IconCapMoreVertical: typeof import('~icons/cap/more-vertical.jsx')['default']
@@ -46,4 +47,6 @@ declare global {
const IconCapUpload: typeof import('~icons/cap/upload.jsx')['default']
const IconLucideCheck: typeof import('~icons/lucide/check.jsx')['default']
const IconLucideLoaderCircle: typeof import('~icons/lucide/loader-circle.jsx')['default']
+ const IconLucideMessageSquareText: typeof import('~icons/lucide/message-square-text.jsx')['default']
+ const IconLucideSmile: typeof import('~icons/lucide/smile.jsx')['default']
}