Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
wip: Desktop app auth callback from web
Richie McIlroy18d4ca46e793
diff --git a/apps/desktop/next.config.mjs b/apps/desktop/next.config.mjsindex f24a426d6..4e1d83586 100644--- a/apps/desktop/next.config.mjs+++ b/apps/desktop/next.config.mjs@@ -5,6 +5,7 @@ import("dotenv").then(({ config }) => config({ path: "../../.env" }));const nextConfig = {reactStrictMode: true,swcMinify: true,+ output: "export",transpilePackages: ["@cap/ui", "@cap/utils"],eslint: {ignoreDuringBuilds: true,diff --git a/apps/desktop/package.json b/apps/desktop/package.jsonindex c815021e6..fc4d7f5a8 100644--- a/apps/desktop/package.json+++ b/apps/desktop/package.json@@ -10,16 +10,16 @@},"dependencies": {"@cap/database": "workspace:*",- "@cap/utils": "workspace:*","@cap/ui": "workspace:*",+ "@cap/utils": "workspace:*","@tauri-apps/api": "^1.5.0","autoprefixer": "^10.4.16","date-fns": "^3.2.0","dotenv": "^16.3.1","million": "^2.6.4","next": "^14.1.0",- "postcss": "^8.4.31","next-auth": "^4.24.5",+ "postcss": "^8.4.31","react": "^18.2.0","react-dom": "^18.2.0","react-hot-toast": "^2.4.1",diff --git a/apps/desktop/src-tauri/Cargo.lock b/apps/desktop/src-tauri/Cargo.lockindex d7e64bc32..2e7757893 100644--- a/apps/desktop/src-tauri/Cargo.lock+++ b/apps/desktop/src-tauri/Cargo.lock@@ -69,7 +69,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "aafb29b107435aa276664c1db8954ac27a6e105cdad3c88287a199eb0e313c08"dependencies = ["clipboard-win",- "core-graphics",+ "core-graphics 0.22.3","image","log","objc",@@ -459,10 +459,13 @@ dependencies = ["tauri-build","tauri-plugin-context-menu","tauri-plugin-deep-link",+ "tauri-plugin-oauth","tauri-plugin-positioner","tokio","tokio-util","which",+ "window-shadows",+ "window-vibrancy",][[package]]@@ -560,8 +563,24 @@ dependencies = ["block","cocoa-foundation","core-foundation",- "core-graphics",- "foreign-types",+ "core-graphics 0.22.3",+ "foreign-types 0.3.2",+ "libc",+ "objc",+]++[[package]]+name = "cocoa"+version = "0.25.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f6140449f97a6e97f9511815c5632d84c8aacf8ac271ad77c559218161a1373c"+dependencies = [+ "bitflags 1.3.2",+ "block",+ "cocoa-foundation",+ "core-foundation",+ "core-graphics 0.23.1",+ "foreign-types 0.5.0","libc","objc",]@@ -636,7 +655,20 @@ dependencies = ["bitflags 1.3.2","core-foundation","core-graphics-types",- "foreign-types",+ "foreign-types 0.3.2",+ "libc",+]++[[package]]+name = "core-graphics"+version = "0.23.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "970a29baf4110c26fedbc7f82107d42c23f7e88e404c4577ed73fe99ff85a212"+dependencies = [+ "bitflags 1.3.2",+ "core-foundation",+ "core-graphics-types",+ "foreign-types 0.5.0","libc",]@@ -1129,7 +1161,28 @@ version = "0.3.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"dependencies = [- "foreign-types-shared",+ "foreign-types-shared 0.1.1",+]++[[package]]+name = "foreign-types"+version = "0.5.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965"+dependencies = [+ "foreign-types-macros",+ "foreign-types-shared 0.3.1",+]++[[package]]+name = "foreign-types-macros"+version = "0.2.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 2.0.46",][[package]]@@ -1138,6 +1191,12 @@ version = "0.1.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"+[[package]]+name = "foreign-types-shared"+version = "0.3.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b"+[[package]]name = "form_urlencoded"version = "1.2.1"@@ -2500,7 +2559,7 @@ checksum = "8cde4d2d9200ad5909f8dac647e29482e07c3a35de8a13fce7c9c7747ad9f671"dependencies = ["bitflags 2.4.1","cfg-if",- "foreign-types",+ "foreign-types 0.3.2","libc","once_cell","openssl-macros",@@ -3754,9 +3813,9 @@ dependencies = ["bitflags 1.3.2","cairo-rs","cc",- "cocoa",+ "cocoa 0.24.1","core-foundation",- "core-graphics",+ "core-graphics 0.22.3","crossbeam-channel","dirs-next","dispatch",@@ -3830,7 +3889,7 @@ checksum = "fd27c04b9543776a972c86ccf70660b517ecabbeced9fb58d8b961a13ad129af"dependencies = ["anyhow","bytes",- "cocoa",+ "cocoa 0.24.1","dirs-next","embed_plist","encoding_rs",@@ -3942,7 +4001,7 @@ version = "0.7.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "408c121f5a61ef57b6246f87ef6205a9602efffd1c2db8fd5d696f61b055fac2"dependencies = [- "cocoa",+ "cocoa 0.24.1","dispatch","gdk","glib",@@ -3960,8 +4019,7 @@ dependencies = [[[package]]name = "tauri-plugin-deep-link"version = "0.1.2"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "4536f5f6602e8fdfaa7b3b185076c2a0704f8eb7015f4e58461eb483ec3ed1f8"+source = "git+https://github.com/FabianLars/tauri-plugin-deep-link?branch=main#a358ec7db9849fa87b634ec6125353b16557bf13"dependencies = ["dirs","interprocess",@@ -3969,8 +4027,20 @@ dependencies = ["objc2","once_cell","tauri-utils",- "windows-sys 0.48.0",- "winreg 0.50.0",+ "windows-sys 0.52.0",+ "winreg 0.52.0",+]++[[package]]+name = "tauri-plugin-oauth"+version = "0.0.0-alpha.0"+source = "git+https://github.com/FabianLars/tauri-plugin-oauth?branch=main#50dadbf4a81cba51f625587b7722892f0b4316a6"+dependencies = [+ "httparse",+ "log",+ "serde",+ "tauri",+ "url",][[package]]@@ -4013,7 +4083,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "6cae61fbc731f690a4899681c9052dde6d05b159b44563ace8186fc1bfb7d158"dependencies = ["arboard",- "cocoa",+ "cocoa 0.24.1","gtk","percent-encoding","rand 0.8.5",@@ -4801,6 +4871,31 @@ version = "0.4.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"+[[package]]+name = "window-shadows"+version = "0.2.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "67ff424735b1ac21293b0492b069394b0a189c8a463fb015a16dea7c2e221c08"+dependencies = [+ "cocoa 0.25.0",+ "objc",+ "raw-window-handle",+ "windows-sys 0.48.0",+]++[[package]]+name = "window-vibrancy"+version = "0.4.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "af6abc2b9c56bd95887825a1ce56cde49a2a97c07e28db465d541f5098a2656c"+dependencies = [+ "cocoa 0.25.0",+ "objc",+ "raw-window-handle",+ "windows-sys 0.52.0",+ "windows-version",+]+[[package]]name = "windows"version = "0.37.0"@@ -5208,6 +5303,16 @@ dependencies = ["windows-sys 0.48.0",]+[[package]]+name = "winreg"+version = "0.52.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5"+dependencies = [+ "cfg-if",+ "windows-sys 0.48.0",+]+[[package]]name = "wry"version = "0.24.7"@@ -5216,8 +5321,8 @@ checksum = "6ad85d0e067359e409fcb88903c3eac817c392e5d638258abfb3da5ad8ba6fc4"dependencies = ["base64 0.13.1","block",- "cocoa",- "core-graphics",+ "cocoa 0.24.1",+ "core-graphics 0.22.3","crossbeam-channel","dunce","gdk",diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.tomlindex c41cabaf1..d5c038789 100644--- a/apps/desktop/src-tauri/Cargo.toml+++ b/apps/desktop/src-tauri/Cargo.toml@@ -13,7 +13,7 @@ edition = "2021"tauri-build = { version = "1.5.0", features = [] }[dependencies]-tauri = { version = "1.5.0", features = [ "window-set-position", "fs-write-file", "fs-remove-file", "fs-read-file", "fs-rename-file", "fs-exists", "fs-remove-dir", "fs-read-dir", "fs-copy-file", "fs-create-dir", "window-set-ignore-cursor-events", "macos-private-api", "window-unminimize", "window-minimize", "window-close", "window-show", "window-start-dragging", "window-hide", "window-unmaximize", "window-maximize", "window-set-always-on-top", "shell-open", "devtools"] }+tauri = { version = "1.5.0", features = [ "macos-private-api", "window-set-position", "fs-write-file", "fs-remove-file", "fs-read-file", "fs-rename-file", "fs-exists", "fs-remove-dir", "fs-read-dir", "fs-copy-file", "fs-create-dir", "window-set-ignore-cursor-events", "window-unminimize", "window-minimize", "window-close", "window-show", "window-start-dragging", "window-hide", "window-unmaximize", "window-maximize", "window-set-always-on-top", "shell-open", "devtools", "os-all", "http-all"] }serde = { version = "1.0", features = ["derive"] }serde_json = "1.0"tauri-plugin-context-menu = "0.7.0"@@ -24,7 +24,10 @@ tokio = { version = "1.35.1", features = ["full"] }tokio-util = { version = "0.7.10", features = ["io"] }futures = "0.3.30"reqwest = { version = "0.11.23", features = ["json", "multipart", "stream"] }-tauri-plugin-deep-link = "0.1.2"+tauri-plugin-oauth = { git = "https://github.com/FabianLars/tauri-plugin-oauth", branch = "main" }+tauri-plugin-deep-link = { git = "https://github.com/FabianLars/tauri-plugin-deep-link", branch = "main" }+window-vibrancy = "0.4.3"+window-shadows = "0.2.2"[features]# this feature is used for production builds or when `devPath` points to the filesystemdiff --git a/apps/desktop/src-tauri/Info.plist b/apps/desktop/src-tauri/Info.plistindex fe253ec7b..189ee92cd 100644--- a/apps/desktop/src-tauri/Info.plist+++ b/apps/desktop/src-tauri/Info.plist@@ -1,10 +1,45 @@<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0">-<dict>- <key>NSCameraUsageDescription</key>- <string>Request camera access for WebRTC</string>- <key>NSMicrophoneUsageDescription</key>- <string>Request microphone access for WebRTC</string>-</dict>-</plist>+ <dict>+ <key>NSCameraUsageDescription</key>+ <string>Request camera access for WebRTC</string>+ <key>NSMicrophoneUsageDescription</key>+ <string>Request microphone access for WebRTC</string>+ <key>com.apple.security.cs.allow-jit</key>+ <true/>+ <key>com.apple.security.cs.allow-unsigned-executable-memory</key>+ <true/>+ <key>com.apple.security.cs.disable-library-validation</key>+ <true/>+ <key>com.apple.security.cs.allow-dyld-environment-variables</key>+ <true/>+ <key>com.apple.security.automation.apple-events</key>+ <true/>+ <key>com.apple.security.device.usb</key>+ <true/>+ <key>com.apple.security.device.camera</key>+ <true/>+ <key>com.apple.security.device.microphone</key>+ <true/>+ <key>com.apple.security.device.audio-input</key>+ <true/>+ <key>com.apple.security.network.server</key>+ <true/>+ <key>com.apple.security.network.client</key>+ <true/>+ <key>com.apple.security.inherit</key>+ <true/>+ <key>CFBundleURLTypes</key>+ <array>+ <dict>+ <key>CFBundleURLName</key>+ <string>so.cap.desktop</string>+ <key>CFBundleURLSchemes</key>+ <array>+ <string>caprecorder</string>+ </array>+ </dict>+ </array>+ </dict>+</plist>\ No newline at end of filediff --git a/apps/desktop/src-tauri/Release.entitlements b/apps/desktop/src-tauri/Release.entitlementsdeleted file mode 100644index 3bae05e5e..000000000--- a/apps/desktop/src-tauri/Release.entitlements+++ /dev/null@@ -1,41 +0,0 @@-<?xml version="1.0" encoding="UTF-8"?>-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">-<plist version="1.0">- <dict>- <key>com.apple.security.cs.allow-jit</key>- <true/>- <key>com.apple.security.cs.allow-unsigned-executable-memory</key>- <true/>- <key>com.apple.security.cs.disable-library-validation</key>- <true/>- <key>com.apple.security.cs.allow-dyld-environment-variables</key>- <true/>- <key>com.apple.security.automation.apple-events</key>- <true/>- <key>com.apple.security.device.usb</key>- <true/>- <key>com.apple.security.device.camera</key>- <true/>- <key>com.apple.security.device.microphone</key>- <true/>- <key>com.apple.security.device.audio-input</key>- <true/>- <key>com.apple.security.network.server</key>- <true/>- <key>com.apple.security.network.client</key>- <true/>- <key>com.apple.security.inherit</key>- <true/>- <key>CFBundleURLTypes</key>- <array>- <dict>- <key>CFBundleURLName</key>- <string>com.cap.so</string>- <key>CFBundleURLSchemes</key>- <array>- <string>caprecorder</string>- </array>- </dict>- </array>- </dict>-</plist>\ No newline at end of filediff --git a/apps/desktop/src-tauri/src/main.rs b/apps/desktop/src-tauri/src/main.rsindex 3cdfeb4f9..64023c97f 100644--- a/apps/desktop/src-tauri/src/main.rs+++ b/apps/desktop/src-tauri/src/main.rs@@ -6,6 +6,8 @@ use tokio::sync::Mutex;use std::sync::atomic::{AtomicBool};use std::env;use tauri::{Manager};+use window_vibrancy::{apply_blur, apply_vibrancy, NSVisualEffectMaterial};+use window_shadows::set_shadow;use tauri_plugin_positioner::{WindowExt, Position};mod recording;@@ -24,9 +26,7 @@ use ffmpeg_sidecar::{version::ffmpeg_version,};-fn main() {- tauri_plugin_deep_link::prepare("com.cap.so");-+fn main() {std::panic::set_hook(Box::new(|info| {eprintln!("Thread panicked: {:?}", info);}));@@ -66,26 +66,25 @@ fn main() {}tauri::Builder::default()+ .plugin(tauri_plugin_oauth::init()).plugin(tauri_plugin_positioner::init()).setup(move |app| {let handle = app.handle();- let handle_clone = handle.clone();-- tauri_plugin_deep_link::register(- "caprecorder",- move |request| {- dbg!(&request);- println!("Received request: {:?}", request);- handle_clone.emit_all("scheme-request-received", request).unwrap();- },- ).unwrap();if let Some(camera_window) = app.get_window("camera") {let _ = camera_window.move_window(Position::BottomRight);+ set_shadow(&camera_window, true).expect("Unsupported platform!");}if let Some(options_window) = app.get_window("options") {let _ = options_window.move_window(Position::Center);+ #[cfg(target_os = "macos")]+ apply_vibrancy(&options_window, NSVisualEffectMaterial::HudWindow, None, Some(16.0)).expect("Unsupported platform! 'apply_vibrancy' is only supported on macOS");++ #[cfg(target_os = "windows")]+ apply_blur(&options_window, Some((255, 255, 255, 255))).expect("Unsupported platform! 'apply_blur' is only supported on Windows");++ set_shadow(&options_window, true).expect("Unsupported platform!");}let data_directory = handle.path_resolver().app_data_dir().unwrap_or_else(|| PathBuf::new());diff --git a/apps/desktop/src-tauri/tauri.conf.json b/apps/desktop/src-tauri/tauri.conf.jsonindex 39dfc06cb..caf4fad8d 100644--- a/apps/desktop/src-tauri/tauri.conf.json+++ b/apps/desktop/src-tauri/tauri.conf.json@@ -3,12 +3,12 @@"beforeDevCommand": "next dev -p 3001","beforeBuildCommand": "next build","devPath": "http://localhost:3001",- "distDir": "../.next",+ "distDir": "../out","withGlobalTauri": false},"package": {"productName": "Cap",- "version": "0.0.0"+ "version": "0.0.1"},"tauri": {"allowlist": {@@ -17,6 +17,9 @@"all": false,"open": true},+ "os": {+ "all": true+ },"window": {"all": false,"close": true,@@ -43,18 +46,19 @@"removeFile": true,"renameFile": true,"exists": true+ },+ "http": {+ "all": true,+ "request": true,+ "scope": ["http://*", "https://*", "wss://*"]}},"bundle": {"active": true,- "macOS": {- "entitlements": "Release.entitlements",- "exceptionDomain": "",- "frameworks": []- },"targets": "all",- "identifier": "com.cap.so",+ "category": "Utility",+ "identifier": "so.cap.desktop","icon": ["icons/32x32.png","icons/128x128.png",@@ -64,7 +68,7 @@]},"security": {- "csp": null+ "csp": "none"},"macOSPrivateApi": true,"windows": [@@ -102,8 +106,8 @@"title": "Cap","label": "options","url": "/options",- "width": 380,- "height": 460,+ "width": 285,+ "height": 410,"maximized": false,"resizable": false,"fullscreen": false,diff --git a/apps/desktop/src/app/api/auth/[...nextauth]/route.ts b/apps/desktop/src/app/api/auth/[...nextauth]/route.tsdeleted file mode 100644index 565ccb6cb..000000000--- a/apps/desktop/src/app/api/auth/[...nextauth]/route.ts+++ /dev/null@@ -1,6 +0,0 @@-import NextAuth from "next-auth";-import { authOptions } from "@cap/database/auth/auth-options";--const handler = NextAuth(authOptions);--export { handler as GET, handler as POST };diff --git a/apps/desktop/src/app/camera/page.tsx b/apps/desktop/src/app/camera/page.tsxindex d032b3a54..79c99cdaf 100644--- a/apps/desktop/src/app/camera/page.tsx+++ b/apps/desktop/src/app/camera/page.tsx@@ -2,6 +2,10 @@import { Camera } from "@/components/windows/Camera";-export default async function CameraPage() {- return <Camera />;+export default function CameraPage() {+ return (+ <div id="app" data-tauri-drag-region style={{ borderRadius: "50%" }}>+ <Camera />+ </div>+ );}diff --git a/apps/desktop/src/app/layout.tsx b/apps/desktop/src/app/layout.tsxindex ef5428076..af7928a0e 100644--- a/apps/desktop/src/app/layout.tsx+++ b/apps/desktop/src/app/layout.tsx@@ -3,7 +3,7 @@ import "./styles.css";import { MediaDeviceProvider } from "@/utils/recording/MediaDeviceContext";import { Toaster } from "react-hot-toast";-export default async function RootLayout({+export default function RootLayout({children,}: {children: React.ReactNode;@@ -43,9 +43,7 @@ export default async function RootLayout({</head><body><Toaster />- <main className="w-full overflow-hidden">- <MediaDeviceProvider>{children}</MediaDeviceProvider>- </main>+ <MediaDeviceProvider>{children}</MediaDeviceProvider></body></html>);diff --git a/apps/desktop/src/app/options/page.tsx b/apps/desktop/src/app/options/page.tsxindex acd1b2470..5ed29168b 100644--- a/apps/desktop/src/app/options/page.tsx+++ b/apps/desktop/src/app/options/page.tsx@@ -1,14 +1,19 @@-"use server";+"use client";-// import { SignIn } from "@/components/windows/inner/SignIn";+import { SignIn } from "@/components/windows/inner/SignIn";import { Recorder } from "@/components/windows/inner/Recorder";-import { getCurrentUser } from "@cap/database/auth/session";-export default async function CameraPage() {- const session = await getCurrentUser();+import { WindowActions } from "@/components/WindowActions";- if (!session) {- return <Recorder />;- }-- return <Recorder />;+export default function CameraPage() {+ return (+ <div+ id="app"+ data-tauri-drag-region+ style={{ borderRadius: "16px" }}+ className="pt-4"+ >+ <WindowActions />+ <Recorder />+ </div>+ );}diff --git a/apps/desktop/src/app/page.tsx b/apps/desktop/src/app/page.tsxindex 8e5f1fb22..d760bafa1 100644--- a/apps/desktop/src/app/page.tsx+++ b/apps/desktop/src/app/page.tsx@@ -1,7 +1,8 @@-"use server";+"use client";-import { redirect } from "next/navigation";+import { useRouter } from "next/navigation";-export default async function IndexPage() {- redirect("/options");+export default function IndexPage() {+ const router = useRouter();+ router.replace("/options");}diff --git a/apps/desktop/src/app/styles.css b/apps/desktop/src/app/styles.cssindex 40f9a8254..7ff047052 100644--- a/apps/desktop/src/app/styles.css+++ b/apps/desktop/src/app/styles.css@@ -122,14 +122,20 @@ a.bg-primary:hover {}html {+ width: 100%;+ height: 100%;padding: 0;margin: 0;+ background-color: transparent;+ border: none;+ box-shadow: none;+ outline: none;}body {color: #000000;font-family: "Geist", sans-serif !important;- background-color: rgba(255, 255, 255, 0);+ background-color: transparent;position: relative;overflow: hidden;user-select: none;@@ -139,10 +145,24 @@ body {-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: antialiased;font-smooth: always;+ width: 100%;+ height: 100%;+ border: none;+ box-shadow: none;+ outline: none;}-#root {- @apply h-screen overflow-hidden flex items-center justify-center;+#app {+ width: 100%;+ height: 100%;+ display: flex;+ align-items: center;+ justify-content: center;+ border-radius: 16px;+}++#app {+ @apply bg-gradient-to-b from-[rgba(255,255,255,0.9)] to-[rgba(255,255,255,0.4)];}* {diff --git a/apps/desktop/src/components/WindowActions.tsx b/apps/desktop/src/components/WindowActions.tsxnew file mode 100644index 000000000..f2f320dc8--- /dev/null+++ b/apps/desktop/src/components/WindowActions.tsx@@ -0,0 +1,24 @@+import { app } from "@tauri-apps/api/window";++export const WindowActions = () => {+ const actionButtonBase = "w-3 h-3 bg-gray-500 rounded-full m-0 p-0 block";++ return (+ <div className="absolute top-3 left-3 w-full flex items-center justify-start gap-x-2">+ <div>+ <button+ onClick={() => {+ app.exit();+ }}+ className={`bg-red-500 hover:bg-red-700 transition-all ${actionButtonBase}`}+ ></button>+ </div>+ <div>+ <span className={actionButtonBase}></span>+ </div>+ <div>+ <span className={actionButtonBase}></span>+ </div>+ </div>+ );+};diff --git a/apps/desktop/src/components/windows/Options.tsx b/apps/desktop/src/components/windows/Options.tsxindex a5055b775..4a9c74c80 100644--- a/apps/desktop/src/components/windows/Options.tsx+++ b/apps/desktop/src/components/windows/Options.tsx@@ -1,3 +1,5 @@+"use client";+// import { Recorder } from "@/components/windows/inner/Recorder";import { SignIn } from "@/components/windows/inner/SignIn";// import { useAuth } from "@/utils/database/AuthContext";diff --git a/apps/desktop/src/components/windows/inner/Recorder.tsx b/apps/desktop/src/components/windows/inner/Recorder.tsxindex 910e9064e..bf7a09e09 100644--- a/apps/desktop/src/components/windows/inner/Recorder.tsx+++ b/apps/desktop/src/components/windows/inner/Recorder.tsx@@ -9,10 +9,11 @@ import { Window } from "@/components/icons/Window";import { ActionButton } from "@/components/recording/ActionButton";import { Button } from "@/components/Button";import { Logo } from "@/components/icons/Logo";-import { emit } from "@tauri-apps/api/event";+import { emit, listen } from "@tauri-apps/api/event";import { showMenu } from "tauri-plugin-context-menu";import { invoke } from "@tauri-apps/api/tauri";import { Countdown } from "./Countdown";+import callbackTemplate from "./callbackTemplate";// import { AuthSession } from "@supabase/supabase-js";// import { supabase } from "@/utils/database/client";// import type { Database } from "@cap/utils";@@ -214,14 +215,42 @@ export const Recorder = () => {}}, [stoppingRecording]);+ console.log("Test...");++ useEffect(() => {+ const setupListener = async () => {+ await listen("oauth://url", (event: any) => {+ let deep_link = event.payload as string;+ console.log("deep_link:");+ console.log(deep_link);+ });++ // Start tauri oauth plugin. When receive first request+ // When it starts, will return the server port+ // it will kill the server+ invoke("plugin:oauth|start", {+ config: {+ // Optional config, but use here to more friendly callback page+ response: callbackTemplate,+ },+ }).then((port) => {+ open(+ "http://localhost:3000/api/authhere" ++ "response_type=token&" ++ "client_id=<CLIEN_ID_FROM_FIREBASE>&" ++ `redirect_uri=http%3A//localhost:${port}&` ++ "scope=email%20profile%20openid&" ++ "prompt=consent"+ );+ });+ };+ setupListener();+ }, []);+return (<divdata-tauri-drag-region- className="w-[85%] h-[85%] relative flex items-center justify-center overflow-hidden px-6 py-4 rounded-[25px] border-2 border-gray-100"- style={{- backgroundColor: "rgba(255,255,255,0.9)",- boxShadow: "0 0 30px rgba(0,0,0,0.2)",- }}+ className="relative flex items-center justify-center overflow-hidden">{countdownActive && (<Countdown@@ -255,7 +284,7 @@ export const Recorder = () => {</div><div><label className="text-sm font-medium">Webcam / Video</label>- <div>+ <div className="space-y-1"><ActionButtonwidth="full"handler={() => handleContextClick("video")}diff --git a/apps/desktop/src/components/windows/inner/SignIn.tsx b/apps/desktop/src/components/windows/inner/SignIn.tsxindex 64cf18a36..29406cfd1 100644--- a/apps/desktop/src/components/windows/inner/SignIn.tsx+++ b/apps/desktop/src/components/windows/inner/SignIn.tsx@@ -1,79 +1,37 @@"use client";import { Button, Logo } from "@cap/ui";-import { signIn } from "next-auth/react";-import { useSearchParams } from "next/navigation";-import { useEffect, useState } from "react";-import { toast } from "react-hot-toast";+import { useState } from "react";+import { login } from "@/utils/auth";export const SignIn = () => {- const searchParams = useSearchParams();- const next = searchParams?.get("next");- const [email, setEmail] = useState("");const [loading, setLoading] = useState(false);- useEffect(() => {- const error = searchParams?.get("error");- error && toast.error(error);- }, [searchParams]);+ const handleSignIn = async () => {+ setLoading(true);++ login();+ };return (- <div className="w-[85%] h-[85%] flex items-center justify-center overflow-hidden px-2 py-4 rounded-[25px] border-2 border-gray-100 bg-gradient-to-b from-gray-200 to-white flex flex-col items-center justify-center">+ <div+ data-tauri-drag-region+ className="flex items-center justify-center overflow-hidden flex-col items-center justify-center"+ ><div className="wrapper wrapper-sm"><div className="mb-12"><Logo className="w-32 h-auto mx-auto" /></div>- <form- onSubmit={async (e) => {- e.preventDefault();- if (!email) return;-- setLoading(true);- signIn("email", {- email,- redirect: false,- ...(next && next.length > 0 ? { callbackUrl: next } : {}),- })- .then((res) => {- console.log("res");- console.log(res);- setLoading(false);- if (res?.ok && !res?.error) {- setEmail("");- toast.success("Email sent - check your inbox!");- } else {- toast.error("Error sending email - try again?");- }- })- .catch((err) => {- console.log("err");- console.log(err);- setLoading(false);- toast.error("Error sending email - try again?");- });+ <Button+ onClick={() => {+ handleSignIn();}}- className="flex flex-col space-y-3"+ variant="default"+ type="button"+ disabled={loading}>- <div>- <input- id="email"- name="email"- autoFocus- type="email"- placeholder="[email protected]"- autoComplete="email"- required- value={email}- onChange={(e) => {- setEmail(e.target.value);- }}- className="mt-1 block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-black focus:outline-none focus:ring-black sm:text-sm"- />- </div>- <Button variant="default" type="submit" disabled={loading}>- Continue with Email- </Button>- </form>+ Sign in via Cap.so+ </Button></div></div>);diff --git a/apps/desktop/src/components/windows/inner/callbackTemplate.ts b/apps/desktop/src/components/windows/inner/callbackTemplate.tsnew file mode 100644index 000000000..0f1df435f--- /dev/null+++ b/apps/desktop/src/components/windows/inner/callbackTemplate.ts@@ -0,0 +1,25 @@+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>My Notes</title>+ <style>+ body {+ font-family: 'Open Sans', sans-serif;+ margin: auto;+ max-width: 640px;+ text-align: center;+ }+ </style>+</head>+<body>+ <h2>You can now open the app</h2>+</body>+</html>+`;diff --git a/apps/desktop/src/utils/auth/callback.template.ts b/apps/desktop/src/utils/auth/callback.template.tsnew file mode 100644index 000000000..cd4490f08--- /dev/null+++ b/apps/desktop/src/utils/auth/callback.template.ts@@ -0,0 +1,25 @@+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>My Notes</title>+ <style>+ body {+ font-family: 'Open Sans', sans-serif;+ margin: auto;+ max-width: 640px;+ text-align: center;+ }+ </style>+</head>+<body>+ <h2>You are now signed in, and can return to the Cap desktop app.</h2>+</body>+</html>+`;diff --git a/apps/desktop/src/utils/auth/index.ts b/apps/desktop/src/utils/auth/index.tsnew file mode 100644index 000000000..0d21f9afc--- /dev/null+++ b/apps/desktop/src/utils/auth/index.ts@@ -0,0 +1,30 @@+import { invoke } from "@tauri-apps/api";+import { listen } from "@tauri-apps/api/event";+import callbackTemplate from "./callback.template";+import { open } from "@tauri-apps/api/shell";++export const openSignIn = async (port: string) => {+ await open(+ `http://localhost:3000/api/session/verify?redirectUrl=http://localhost:${port}`+ );+};++export const login = () => {+ // Wait for callback from tauri oauth plugin+ listen("oauth://url", (data) => {+ console.log("payload:");+ console.log(data.payload);+ });++ // Start tauri oauth plugin. When receive first request+ // When it starts, will return the server port+ // it will kill the server+ invoke("plugin:oauth|start", {+ config: {+ // Optional config, but use here to more friendly callback page+ response: callbackTemplate,+ },+ }).then((port) => {+ openSignIn(port as string);+ });+};diff --git a/apps/web/app/api/session/verify/route.ts b/apps/web/app/api/session/verify/route.tsnew file mode 100644index 000000000..c39815479--- /dev/null+++ b/apps/web/app/api/session/verify/route.ts@@ -0,0 +1,21 @@+import { type NextRequest } from "next/server";+import { getServerSession } from "next-auth";+import { authOptions } from "@cap/database/auth/auth-options";++export async function GET(req: NextRequest) {+ const session = await getServerSession(authOptions);+ const searchParams = req.nextUrl.searchParams;+ const redirectUrl = searchParams.get("redirectUrl") || "";++ if (session) {+ return Response.redirect(redirectUrl);+ } else {+ // No active session+ return new Response(JSON.stringify({ isLoggedIn: false }), {+ status: 401,+ headers: {+ "Content-Type": "application/json",+ },+ });+ }+}diff --git a/apps/web/app/dashboard/caps/Caps.tsx b/apps/web/app/dashboard/caps/Caps.tsxindex 11052d32b..7e8285d73 100644--- a/apps/web/app/dashboard/caps/Caps.tsx+++ b/apps/web/app/dashboard/caps/Caps.tsx@@ -25,15 +25,10 @@ export const Caps = ({<p className="text-xl max-w-md">Craft your narrative with a Cap—get projects done quicker.</p>- <Button- onClick={() => {- window.open("caprecorder://");- }}- size="lg"- className="mt-8"- variant="default"- >- Record a Cap+ <Button size="lg" className="mt-8" variant="default">+ <a href={`http://localhost:3001/auth?token=`} target="_blank">+ Record a Cap+ </a></Button></div></div>diff --git a/apps/web/app/dashboard/layout.tsx b/apps/web/app/dashboard/layout.tsxindex cecd8302e..6bb596dc2 100644--- a/apps/web/app/dashboard/layout.tsx+++ b/apps/web/app/dashboard/layout.tsx@@ -19,6 +19,8 @@ export default async function DashboardLayout({}) {const session = await getCurrentUser();+ console.log("session", session);+if (!session) {redirect("/login");}diff --git a/apps/web/next.config.mjs b/apps/web/next.config.mjsindex 8345efb4d..796c3e22a 100644--- a/apps/web/next.config.mjs+++ b/apps/web/next.config.mjs@@ -22,6 +22,27 @@ const nextConfig = {"@react-email/tailwind",],},+ async headers() {+ return [+ {+ source: "/api/session/verify",+ headers: [+ {+ key: "Access-Control-Allow-Origin",+ value: "http://localhost:3001",+ },+ {+ key: "Access-Control-Allow-Methods",+ value: "GET",+ },+ {+ key: "Access-Control-Allow-Credentials",+ value: "true",+ },+ ],+ },+ ];+ },};const millionConfig = {diff --git a/apps/web/package.json b/apps/web/package.jsonindex eab10736d..adea981af 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -21,11 +21,13 @@"@react-email/render": "0.0.11","aws-sdk": "^2.1530.0","clsx": "^2.0.0",+ "cookies-next": "^4.1.0","dotenv": "^16.3.1","lucide-react": "^0.294.0","million": "^2.6.4","next": "14.1.0","next-auth": "^4.24.5",+ "nextjs-cors": "^2.2.0","react": "^18.2.0","react-dom": "^18.2.0","react-email": "^1.10.1",diff --git a/packages/database/auth/session.ts b/packages/database/auth/session.tsindex de6d3c3ab..820a32f44 100644--- a/packages/database/auth/session.ts+++ b/packages/database/auth/session.ts@@ -1,8 +1,8 @@-import { getServerSession } from 'next-auth';-import { eq } from 'drizzle-orm';-import { authOptions } from './auth-options';-import { db } from '../';-import { users } from '../schema';+import { getServerSession } from "next-auth";+import { eq } from "drizzle-orm";+import { authOptions } from "./auth-options";+import { db } from "../";+import { users } from "../schema";export const getSession = async () => {const session = await getServerSession(authOptions);@@ -29,4 +29,4 @@ export const getCurrentUser = async () => {.where(eq(users.id, session?.user.id));return currentUser;-};\ No newline at end of file+};diff --git a/packages/database/types/next-auth.d.ts b/packages/database/types/next-auth.d.tsindex 09bb8891e..f892cd593 100644--- a/packages/database/types/next-auth.d.ts+++ b/packages/database/types/next-auth.d.ts@@ -1,18 +1,18 @@-import type { JWT } from 'next-auth/jwt';-import type { Session, User } from 'next-auth';+import type { JWT } from "next-auth/jwt";+import type { Session, User } from "next-auth";type UserId = string;-declare module 'next-auth/jwt' {+declare module "next-auth/jwt" {interface JWT {id: UserId;}}-declare module 'next-auth' {+declare module "next-auth" {interface Session {user: User & {id: UserId;};}-}\ No newline at end of file+}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex e2f34f55b..0978f5082 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -132,6 +132,9 @@ importers:clsx:specifier: ^2.0.0version: 2.1.0+ cookies-next:+ specifier: ^4.1.0+ version: 4.1.0dotenv:specifier: ^16.3.1version: 16.3.1@@ -147,6 +150,9 @@ importers:next-auth:specifier: ^4.24.5+ nextjs-cors:+ specifier: ^2.2.0+ version: 2.2.0([email protected])react:specifier: ^18.2.0version: 18.2.0@@ -3902,6 +3908,10 @@ packages:dependencies:'@babel/types': 7.23.6+ /@types/[email protected]:+ resolution: {integrity: sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q==}+ dev: false+/@types/[email protected]:resolution: {integrity: sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==}dependencies:@@ -3932,6 +3942,10 @@ packages:resolution: {integrity: sha512-hov8bUuiLiyFPGyFPE1lwWhmzYbirOXQNNo40+y3zow8aFVTeyn3VWL0VFFfdNddA8S4Vf0Tc062rzyNr7Paag==}dev: false+ /@types/[email protected]:+ resolution: {integrity: sha512-eEn8RkzZFcT0gb8qyi0CcfSOQnLE+NbGLIIaxGGmjn/N35v/C3M8ohxcpSlNlCv+H8vPpMGmrGDdCkzr8xu2tQ==}+ dev: false+/@types/[email protected]:resolution: {integrity: sha512-g557vgQjUUfN76MZAN/dt1z3dzcUsimuysco0KeluHgrPdJXkP/XdAURgyO2W9fZWHRtRBiVKzKn8vyOAwlG+w==}dependencies:@@ -4855,11 +4869,24 @@ packages:resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==}+ resolution: {integrity: sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==}+ engines: {node: '>= 0.6'}+ dev: false+resolution: {integrity: sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==}engines: {node: '>= 0.6'}dev: false+ resolution: {integrity: sha512-BREVc4TJT4NwXfyKjdjnYFXM6iRns+MYpCd34ClXuYqeisXnkPkbq7Ok9xaqi9mHmV6H2rwPE+p3EpMz4pF/kQ==}+ dependencies:+ '@types/cookie': 0.4.1+ '@types/node': 16.18.74+ cookie: 0.4.2+ dev: false+resolution: {integrity: sha512-yCEafptTtb4bk7GLEQoM8KVJpxAfdBJYaXyzQEgQQQgYrZiDp8SJmGKlYza6CYjEDNstAdNdKA3UuoULlEbS6w==}engines: {node: '>=12.13'}@@ -4872,6 +4899,14 @@ packages:requiresBuild: truedev: true+ resolution: {integrity: sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==}+ engines: {node: '>= 0.10'}+ dependencies:+ object-assign: 4.1.1+ vary: 1.1.2+ dev: false+resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==}dev: true@@ -7571,6 +7606,15 @@ packages:- babel-plugin-macrosdev: false+ resolution: {integrity: sha512-FZu/A+L59J4POJNqwXYyCPDvsLDeu5HjSBvytzS6lsrJeDz5cmnH45zV+VoNic0hjaeER9xGaiIjZIWzEHnxQg==}+ peerDependencies:+ next: ^8.1.1-canary.54 || ^9.0.0 || ^10.0.0-0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0+ dependencies:+ cors: 2.8.5+ dev: false+resolution: {integrity: sha512-rmTZ9kz+f3rCvK2TD1Ue/oZlns7OGoIWP4fc3llxxRXlOkHKoWPPWJOfFYpITabSow43QJbRIoHQXtt10VldyQ==}dependencies:@@ -9471,6 +9515,11 @@ packages:builtins: 5.0.1dev: true+ resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==}+ engines: {node: '>= 0.8'}+ dev: false+resolution: {integrity: sha512-cfgJwcGOsIxXOLU/nELPny2/LUD/lcf1IbfyeKTv2bsupVbTH/xpFtdQlBmIP1GEK2CjjLxYhFfB+QODFAx5aw==}peerDependencies: