Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

wip: Million.js support + Layout RSC shift

Richie McIlroya956147156cd
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index a855c6f91..7fe5e6234 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -14,6 +14,7 @@
"autoprefixer": "^10.4.16",
"date-fns": "^3.2.0",
"dotenv": "^16.3.1",
+ "million": "^2.6.4",
"postcss": "^8.4.31",
"react": "^18.2.0",
"react-dom": "^18.2.0",
diff --git a/apps/desktop/src/components/windows/Camera.tsx b/apps/desktop/src/components/windows/Camera.tsx
index a0713de51..cf10dbc83 100644
--- a/apps/desktop/src/components/windows/Camera.tsx
+++ b/apps/desktop/src/components/windows/Camera.tsx
@@ -7,73 +7,76 @@ export const Camera = () => {
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
- if (videoRef.current && selectedVideoDevice) {
+ let activeStream: MediaStream | null = null;
+
+ const setupCamera = async () => {
+ if (!videoRef.current || !selectedVideoDevice) {
+ setIsLoading(false);
+ return;
+ }
+
setIsLoading(true);
+ try {
+ const devices = await navigator.mediaDevices.enumerateDevices();
+ const videoDevices = devices.filter(
+ (device) => device.kind === "videoinput"
+ );
+ const deviceId = videoDevices[selectedVideoDevice.index].deviceId;
+
+ const stream = await navigator.mediaDevices.getUserMedia({
+ video: {
+ deviceId: deviceId,
+ frameRate: { ideal: 30 },
+ width: { ideal: 1920 },
+ height: { ideal: 1080 },
+ },
+ });
- navigator.mediaDevices
- .enumerateDevices()
- .then((devices) => {
- const videoDevices = devices.filter(
- (device) => device.kind === "videoinput"
- );
- return videoDevices[selectedVideoDevice.index].deviceId;
- })
- .then((deviceId) =>
- navigator.mediaDevices
- .getUserMedia({
- video: {
- deviceId: deviceId,
- frameRate: { ideal: 30 },
- width: { ideal: 1920 },
- height: { ideal: 1080 },
- },
- })
- //Save fps and widthXheight settings to local storage
- .then((stream) => {
- const videoTrack = stream.getVideoTracks()[0];
- const settings = videoTrack.getSettings();
- const videoProperties = {
- framerate: settings.frameRate ? String(settings.frameRate) : "",
- resolution: `${settings.width}x${settings.height}`,
- };
- localStorage.setItem(
- "videoDeviceProperties",
- JSON.stringify(videoProperties)
- );
- return stream;
- })
- .then((stream) => {
- let video = videoRef.current;
- if (video) {
- video.srcObject = stream;
- video.onplaying = () => {
- setIsLoading(false);
- };
- video.play().catch((error) => {
- console.error("Error attempting to play the video:", error);
- });
- }
- })
- .catch((err) => {
- console.error(err);
- setIsLoading(false);
- })
+ // Save stream
+ activeStream = stream;
+
+ const videoTrack = stream.getVideoTracks()[0];
+ const settings = videoTrack.getSettings();
+ const videoProperties = {
+ framerate: settings.frameRate ? String(settings.frameRate) : "",
+ resolution: `${settings.width}x${settings.height}`,
+ };
+ localStorage.setItem(
+ "videoDeviceProperties",
+ JSON.stringify(videoProperties)
);
+ const video = videoRef.current;
+ video.srcObject = stream;
+ video.onplaying = () => {
+ setIsLoading(false);
+ };
+ await video.play();
+ } catch (err) {
+ console.error(err);
+ setIsLoading(false);
+ }
+ };
+
+ setupCamera();
+
+ // Cleanup function to stop the stream and reset loading state
+ return () => {
+ if (activeStream) {
+ activeStream.getTracks().forEach((track) => track.stop());
+ activeStream = null;
+ }
+ // Avoid loading when the component is not actually loading
setIsLoading(false);
- }
+ };
}, [selectedVideoDevice, videoRef]);
- if (videoRef && selectedVideoDevice && isLoading === true) {
- setIsLoading(false);
- }
-
return (
<div
data-tauri-drag-region
className="w-[200px] h-[200px] bg-gray-200 rounded-full m-0 p-0 relative overflow-hidden flex items-center justify-center"
>
- {isLoading === true ? (
+ {isLoading ? (
<svg
xmlns="http://www.w3.org/2000/svg"
stroke="#fff"
diff --git a/apps/desktop/src/components/windows/inner/Recorder.tsx b/apps/desktop/src/components/windows/inner/Recorder.tsx
index 8d081b244..afb22011a 100644
--- a/apps/desktop/src/components/windows/inner/Recorder.tsx
+++ b/apps/desktop/src/components/windows/inner/Recorder.tsx
@@ -20,6 +20,7 @@ import { getLatestVideoId, saveLatestVideoId } from "@/utils/database/utils";
import { openLinkInBrowser } from "@/utils/helpers";
import { uuidParse } from "@cap/utils";
import toast, { Toaster } from "react-hot-toast";
+import { LogicalSize, WebviewWindow, appWindow } from "@tauri-apps/api/window";
export const Recorder = ({ session }: { session: AuthSession | null }) => {
const {
@@ -71,8 +72,8 @@ export const Recorder = ({ session }: { session: AuthSession | null }) => {
};
const handleOverlayFinished = () => {
- // appWindow.minimize();
- // WebviewWindow.getByLabel("camera")?.minimize();
+ appWindow.setSize(new LogicalSize(0, 0));
+ WebviewWindow.getByLabel("camera")?.setSize(new LogicalSize(0, 0));
setIsRecording(true);
setCountdownActive(false);
};
diff --git a/apps/desktop/vite.config.ts b/apps/desktop/vite.config.ts
index f16256975..c34eca456 100644
--- a/apps/desktop/vite.config.ts
+++ b/apps/desktop/vite.config.ts
@@ -1,3 +1,4 @@
+import million from "million/compiler";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tsconfigPaths from "vite-tsconfig-paths";
@@ -16,7 +17,7 @@ requiredEnvVariables.forEach((envVar) => {
// https://vitejs.dev/config/
export default defineConfig(async () => ({
- plugins: [react(), tsconfigPaths()],
+ plugins: [million.vite({ optimize: true }), react(), tsconfigPaths()],
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
//
diff --git a/apps/web/app/dashboard/layout.tsx b/apps/web/app/dashboard/layout.tsx
index eeb38f7c3..61aac2b18 100644
--- a/apps/web/app/dashboard/layout.tsx
+++ b/apps/web/app/dashboard/layout.tsx
@@ -5,6 +5,8 @@ import {
getSession,
getActiveSpace,
} from "@/utils/database/supabase/server";
+import SupabaseProvider from "@/utils/database/supabase/provider";
+import SupabaseListener from "@/utils/database/supabase/listener";
export const revalidate = 0;
@@ -24,8 +26,14 @@ export default async function DashboardLayout({
console.log("session", session);
return (
- <DynamicSharedLayout spaceData={spaceData?.data} activeSpace={activeSpace}>
- <div className="full-layout">{children}</div>
- </DynamicSharedLayout>
+ <SupabaseProvider session={session}>
+ <DynamicSharedLayout
+ spaceData={spaceData?.data}
+ activeSpace={activeSpace}
+ >
+ <SupabaseListener serverAccessToken={session?.access_token} />
+ <div className="full-layout">{children}</div>
+ </DynamicSharedLayout>
+ </SupabaseProvider>
);
}
diff --git a/apps/web/app/layout.tsx b/apps/web/app/layout.tsx
index f364c8ba3..5426b78c4 100644
--- a/apps/web/app/layout.tsx
+++ b/apps/web/app/layout.tsx
@@ -1,33 +1,16 @@
-import "server-only";
+"use client";
import SupabaseListener from "@/utils/database/supabase/listener";
import SupabaseProvider from "@/utils/database/supabase/provider";
import "@/app/globals.css";
-import { Metadata } from "next/types";
import { Toaster } from "react-hot-toast";
import { Navbar } from "@/components/Navbar";
import { Footer } from "@/components/Footer";
-import { createSupabaseServerClient } from "@/utils/database/supabase/server";
-import { cookies } from "next/headers";
-
-export const metadata: Metadata = {
- title: "Cap — Beautiful, shareable screen recordings",
- description: "Cap — Beautiful, shareable screen recordings",
-};
-
-// do not cache this layout
-export const revalidate = 0;
export default async function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
- const supabase = await createSupabaseServerClient();
-
- const {
- data: { session },
- } = await supabase.auth.getSession();
-
return (
<html lang="en">
<head>
@@ -60,15 +43,12 @@ export default async function RootLayout({
<meta name="theme-color" content="#ffffff" />
</head>
<body>
- <SupabaseProvider session={session}>
- <Toaster />
- <main className="w-full overflow-hidden">
- <Navbar />
- <SupabaseListener serverAccessToken={session?.access_token} />
- {children}
- <Footer />
- </main>
- </SupabaseProvider>
+ <Toaster />
+ <main className="w-full overflow-hidden">
+ <Navbar />
+ {children}
+ <Footer />
+ </main>
</body>
</html>
);
diff --git a/apps/web/next.config.js b/apps/web/next.config.mjs
similarity index 75%
rename from apps/web/next.config.js
rename to apps/web/next.config.mjs
index 3c249a010..426ca9ae9 100644
--- a/apps/web/next.config.js
+++ b/apps/web/next.config.mjs
@@ -1,6 +1,8 @@
+import million from "million/compiler";
+
/** @type {import('next').NextConfig} */
-require("dotenv").config({ path: "../../.env" });
+import("dotenv").then(({ config }) => config({ path: "../../.env" }));
if (
!process.env.NEXT_PUBLIC_SUPABASE_URL ||
@@ -28,4 +30,8 @@ const nextConfig = {
},
};
-module.exports = nextConfig;
+const millionConfig = {
+ auto: true,
+};
+
+export default million.next(nextConfig, millionConfig);
diff --git a/apps/web/package.json b/apps/web/package.json
index 3be3d2dbc..0ef69653c 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -25,6 +25,7 @@
"clsx": "^2.0.0",
"dotenv": "^16.3.1",
"lucide-react": "^0.294.0",
+ "million": "^2.6.4",
"next": "14.0.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
diff --git a/package.json b/package.json
index 9eb73523c..1a2ee9246 100644
--- a/package.json
+++ b/package.json
@@ -10,7 +10,7 @@
"eslint": "^7.32.0",
"prettier": "^2.5.1",
"turbo": "^1.10.16",
- "supabase": "^1.123.4",
+ "supabase": "^1.131.4",
"dotenv-cli": "latest"
},
"packageManager": "[email protected]",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index b4520b71b..09199f6a7 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -21,8 +21,8 @@ importers:
specifier: ^2.5.1
version: 2.8.8
supabase:
- specifier: ^1.123.4
- version: 1.123.4
+ specifier: ^1.131.4
+ version: 1.131.4
turbo:
specifier: ^1.10.16
version: 1.10.16
@@ -44,6 +44,9 @@ importers:
dotenv:
specifier: ^16.3.1
version: 16.3.1
+ million:
+ specifier: ^2.6.4
+ version: 2.6.4
postcss:
specifier: ^8.4.31
version: 8.4.31
@@ -144,9 +147,12 @@ importers:
lucide-react:
specifier: ^0.294.0
version: 0.294.0([email protected])
+ million:
+ specifier: ^2.6.4
+ version: 2.6.4
next:
specifier: 14.0.4
react:
specifier: ^18.2.0
version: 18.2.0
@@ -1152,6 +1158,26 @@ packages:
dependencies:
'@babel/types': 7.23.4
+ resolution: {integrity: sha512-EB2MELswq55OHUoRZLGg/zC7QWUKfNLpE57m/S2yr1uEneIgsTgrSzXP3NXEsMkVn76OlaVVnzN+ugObuYGwhg==}
+ engines: {node: '>=6.9.0'}
+ peerDependencies:
+ '@babel/core': ^7.0.0-0
+ dependencies:
+ '@babel/core': 7.23.3
+ '@babel/helper-plugin-utils': 7.22.5
+ dev: false
+
+ resolution: {integrity: sha512-9EiNjVJOMwCO+43TqoTrgQ8jMwcAd0sWyXi9RPfIsLTj4R2MADDDQXELhffaUx/uJv2AYcxBgPwH6j4TIA4ytQ==}
+ engines: {node: '>=6.9.0'}
+ peerDependencies:
+ '@babel/core': ^7.0.0-0
+ dependencies:
+ '@babel/core': 7.23.3
+ '@babel/helper-plugin-utils': 7.22.5
+ dev: false
+
resolution: {integrity: sha512-qXRvbeKDSfwnlJnanVRp0SfuWE5DQhwQr5xtLBzp56Wabyo+4CMosF6Kfp+eOD/4FYpql64XVJ2W0pVLlJZxOQ==}
engines: {node: '>=6.9.0'}
@@ -3686,7 +3712,6 @@ packages:
resolution: {integrity: sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==}
engines: {node: '>=0.4.0'}
hasBin: true
- dev: true
resolution: {integrity: sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==}
@@ -6123,6 +6148,11 @@ packages:
json-buffer: 3.0.1
dev: true
+ resolution: {integrity: sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==}
+ engines: {node: '>=6'}
+ dev: false
+
resolution: {integrity: sha512-tN0MCzyWnoz/4nHS6uxdlFWoUZT7ABptwKPQ52Ea7URk6vll88bWBVhodtnlfEuCcKWNGoc+uGbw1cwa9IKh/w==}
dev: true
@@ -6256,6 +6286,22 @@ packages:
braces: 3.0.2
picomatch: 2.3.1
+ resolution: {integrity: sha512-voUkdd/jHWrG+7NS+mX49Pat+POKdgGW78V7pYMSrTaOjUitR6ySEcAci8hn17Rsx1IMI3+5w41dkADM1J1ZEg==}
+ hasBin: true
+ dependencies:
+ '@babel/core': 7.23.3
+ '@babel/generator': 7.23.4
+ '@babel/plugin-syntax-jsx': 7.23.3(@babel/[email protected])
+ '@babel/plugin-syntax-typescript': 7.23.3(@babel/[email protected])
+ '@babel/types': 7.23.4
+ kleur: 4.1.5
+ rollup: 3.29.4
+ unplugin: 1.6.0
+ transitivePeerDependencies:
+ - supports-color
+ dev: false
+
resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==}
engines: {node: '>=6'}
@@ -6355,7 +6401,7 @@ packages:
engines: {node: '>= 0.4.0'}
dev: true
resolution: {integrity: sha512-qbwypnM7327SadwFtxXnQdGiKpkuhaRLE2uq62/nRul9cj9KhQ5LhHmlziTNqUidZotw/Q1I9OjirBROdUJNgA==}
engines: {node: '>=18.17.0'}
hasBin: true
@@ -6378,7 +6424,7 @@ packages:
postcss: 8.4.31
react: 18.2.0
react-dom: 18.2.0([email protected])
- styled-jsx: 5.1.1([email protected])
+ styled-jsx: 5.1.1(@babel/[email protected])([email protected])
watchpack: 2.4.0
optionalDependencies:
'@next/swc-darwin-arm64': 14.0.4
@@ -7530,7 +7576,7 @@ packages:
resolution: {integrity: sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA==}
dev: false
resolution: {integrity: sha512-pW7uC1l4mBZ8ugbiZrcIsiIvVx1UmTfw7UkC3Um2tmfUq9Bhk8IiyEIPl6F8agHgjzku6j0xQEZbfA5uSgSaCw==}
engines: {node: '>= 12.0.0'}
peerDependencies:
@@ -7543,6 +7589,7 @@ packages:
babel-plugin-macros:
optional: true
dependencies:
+ '@babel/core': 7.23.3
client-only: 0.0.1
react: 18.2.0
dev: false
@@ -7588,6 +7635,20 @@ packages:
- supports-color
dev: true
+ resolution: {integrity: sha512-tKfq4GofGT21gW8McyHHbFL3QezWx/mBcJO4r18fl5IgHKFlegCRrDr7YUq94aVwu9aKpQYtuHJiVK+QFEsbpg==}
+ engines: {npm: '>=8'}
+ hasBin: true
+ requiresBuild: true
+ dependencies:
+ bin-links: 4.0.3
+ https-proxy-agent: 7.0.2
+ node-fetch: 3.3.2
+ tar: 6.2.0
+ transitivePeerDependencies:
+ - supports-color
+ dev: true
+
resolution: {integrity: sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==}
engines: {node: '>=4'}
@@ -8032,6 +8093,15 @@ packages:
engines: {node: '>= 10.0.0'}
dev: true
+ resolution: {integrity: sha512-BfJEpWBu3aE/AyHx8VaNE/WgouoQxgH9baAiH82JjX8cqVyi3uJQstqwD5J+SZxIK326SZIhsSZlALXVBCknTQ==}
+ dependencies:
+ acorn: 8.11.2
+ chokidar: 3.5.3
+ webpack-sources: 3.2.3
+ webpack-virtual-modules: 0.6.1
+ dev: false
+
resolution: {integrity: sha512-xebP81SNcPuNpPP3uzeW1NYXxI3rxyJzF3pD6sH4jE7o/IX+WtSpwnVU+qIsDPyk0d3hmFQ7mjqc6AtV604hbg==}
hasBin: true
@@ -8284,6 +8354,15 @@ packages:
resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}
+ resolution: {integrity: sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==}
+ engines: {node: '>=10.13.0'}
+ dev: false
+
+ resolution: {integrity: sha512-poXpCylU7ExuvZK8z+On3kX+S8o/2dQ/SVYueKA0D4WEMXROXgY8Ez50/bQEUmvoSMMrWcrJqCHuhAbsiwg7Dg==}
+ dev: false
+
resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==}
dependencies: