diff --git a/.env.example b/.env.example index 318d355bc1c..9e67c7ec7e5 100644 --- a/.env.example +++ b/.env.example @@ -71,6 +71,8 @@ NEXTAUTH_SECRET= # Audio transcription # DEEPGRAM_API_KEY= +# Cap AI +# OPENAI_API_KEY= # Only needed by cap.so cloud # NEXT_LOOPS_KEY= diff --git a/Cargo.lock b/Cargo.lock index f3d00a1739d..2da95d14281 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -929,7 +929,7 @@ dependencies = [ [[package]] name = "cap-desktop" -version = "0.3.46" +version = "0.3.48" dependencies = [ "anyhow", "axum", @@ -7585,9 +7585,9 @@ dependencies = [ [[package]] name = "tauri-plugin-http" -version = "2.2.0" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e62a9bde54d6a0218b63f5a248f02056ad4316ba6ad81dfb9e4f73715df5deb1" +checksum = "696ef548befeee6c6c17b80ef73e7c41205b6c2204e87ef78ccc231212389a5c" dependencies = [ "data-url", "http", diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 8a598bec870..ff39e3669c1 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -41,7 +41,7 @@ "@tauri-apps/plugin-deep-link": "^2.2.0", "@tauri-apps/plugin-dialog": "2.0.1", "@tauri-apps/plugin-fs": "2.2.0", - "@tauri-apps/plugin-http": "^2.0.1", + "@tauri-apps/plugin-http": "^2.4.4", "@tauri-apps/plugin-notification": "2.0.0", "@tauri-apps/plugin-opener": "^2.2.6", "@tauri-apps/plugin-os": "2.0.0", @@ -64,7 +64,8 @@ "unplugin-icons": "^0.19.2", "uuid": "^9.0.1", "vinxi": "^0.5.6", - "webcodecs": "^0.1.0" + "webcodecs": "^0.1.0", + "zod": "^3.24.2" }, "devDependencies": { "@fontsource/geist-sans": "^5.0.3", diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index c2c5c09b0a5..14f40f18c1e 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cap-desktop" -version = "0.3.46" +version = "0.3.48" description = "Beautiful screen recordings, owned by you." authors = ["you"] edition = "2021" diff --git a/apps/desktop/src-tauri/src/auth.rs b/apps/desktop/src-tauri/src/auth.rs index 40984ce823f..40695416144 100644 --- a/apps/desktop/src-tauri/src/auth.rs +++ b/apps/desktop/src-tauri/src/auth.rs @@ -10,13 +10,19 @@ use crate::web_api; #[derive(Serialize, Deserialize, Type, Debug)] pub struct AuthStore { - pub token: String, + pub secret: AuthSecret, pub user_id: Option, - pub expires: i32, pub plan: Option, pub intercom_hash: Option, } +#[derive(Serialize, Deserialize, Type, Debug)] +#[serde(untagged)] +pub enum AuthSecret { + ApiKey { api_key: String }, + Session { token: String, expires: i32 }, +} + #[derive(Serialize, Deserialize, Type, Debug)] pub struct Plan { pub upgraded: bool, @@ -108,12 +114,6 @@ impl AuthStore { return Err("Store not found".to_string()); }; - let value = value.map(|mut auth| { - // Set expiration to 100 years in the future - auth.expires = (chrono::Utc::now() + chrono::Duration::days(36500)).timestamp() as i32; - auth - }); - store.set("auth", json!(value)); store.save().map_err(|e| e.to_string()) } diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs index 110dbe01058..c50d9f452ee 100644 --- a/apps/desktop/src-tauri/src/lib.rs +++ b/apps/desktop/src-tauri/src/lib.rs @@ -1715,7 +1715,7 @@ async fn check_upgraded_and_update(app: AppHandle) -> Result { } } - let Ok(Some(mut auth)) = AuthStore::get(&app) else { + let Ok(Some(auth)) = AuthStore::get(&app) else { println!("No auth found, clearing auth store"); AuthStore::set(&app, None).map_err(|e| e.to_string())?; return Ok(false); @@ -1732,7 +1732,6 @@ async fn check_upgraded_and_update(app: AppHandle) -> Result { "Fetching plan for user {}", auth.user_id.as_deref().unwrap_or("unknown") ); - let plan_url = app.make_app_url("/api/desktop/plan"); let response = app .authed_api_request("/api/desktop/plan", |client, url| client.get(url)) .await @@ -1759,9 +1758,8 @@ async fn check_upgraded_and_update(app: AppHandle) -> Result { .unwrap_or(false); println!("Pro status: {}", is_pro); let updated_auth = AuthStore { - token: auth.token, + secret: auth.secret, user_id: auth.user_id, - expires: auth.expires, intercom_hash: auth.intercom_hash, plan: Some(Plan { upgraded: is_pro, diff --git a/apps/desktop/src-tauri/src/presets.rs b/apps/desktop/src-tauri/src/presets.rs index 3b846e94389..56ba8db4dc7 100644 --- a/apps/desktop/src-tauri/src/presets.rs +++ b/apps/desktop/src-tauri/src/presets.rs @@ -4,6 +4,7 @@ use serde_json::json; use specta::Type; use tauri::{AppHandle, Wry}; use tauri_plugin_store::StoreExt; +use tracing::error; #[derive(Serialize, Deserialize, Type, Debug, Default)] #[serde(rename_all = "camelCase")] @@ -26,7 +27,10 @@ impl PresetsStore { // Handle potential deserialization errors gracefully match serde_json::from_value(store) { Ok(settings) => Ok(Some(settings)), - Err(_) => Err("Failed to deserialize presets store".to_string()), + Err(_) => { + error!("Failed to deserialize presets store"); + Ok(None) + } } } _ => Ok(None), diff --git a/apps/desktop/src-tauri/src/web_api.rs b/apps/desktop/src-tauri/src/web_api.rs index c8478523df2..9afb4ec38ad 100644 --- a/apps/desktop/src-tauri/src/web_api.rs +++ b/apps/desktop/src-tauri/src/web_api.rs @@ -3,8 +3,8 @@ use tauri::{Emitter, Manager, Runtime}; use tauri_specta::Event; use crate::{ - auth::{AuthStore, AuthenticationInvalid}, - ArcLock, MutableState, + auth::{AuthSecret, AuthStore, AuthenticationInvalid}, + ArcLock, }; async fn do_authed_request( @@ -14,7 +14,16 @@ async fn do_authed_request( ) -> Result { let client = reqwest::Client::new(); - let mut req = build(client, url).header("Authorization", format!("Bearer {}", auth.token)); + let mut req = build(client, url).header( + "Authorization", + format!( + "Bearer {}", + match &auth.secret { + AuthSecret::ApiKey { api_key } => api_key, + AuthSecret::Session { token, .. } => token, + } + ), + ); if let Some(s) = std::option_env!("VITE_VERCEL_AUTOMATION_BYPASS_SECRET") { req = req.header("x-vercel-protection-bypass", s); diff --git a/apps/desktop/src/components/SignInButton.tsx b/apps/desktop/src/components/SignInButton.tsx index 3ef0ab41eb5..755f724ca6c 100644 --- a/apps/desktop/src/components/SignInButton.tsx +++ b/apps/desktop/src/components/SignInButton.tsx @@ -4,6 +4,7 @@ import { invoke } from "@tauri-apps/api/core"; import { listen } from "@tauri-apps/api/event"; import { onOpenUrl } from "@tauri-apps/plugin-deep-link"; import * as shell from "@tauri-apps/plugin-shell"; +import { z } from "zod"; import { getCurrentWindow } from "@tauri-apps/api/window"; import { ComponentProps } from "solid-js"; @@ -12,27 +13,12 @@ import { identifyUser, trackEvent } from "~/utils/analytics"; import { clientEnv } from "~/utils/env"; import { commands } from "~/utils/tauri"; import callbackTemplate from "./callback.template"; +import { createSignInMutation } from "~/utils/auth"; export function SignInButton( props: Omit, "onClick"> ) { - const signIn = createMutation(() => ({ - mutationFn: async (abort: AbortController) => { - const platform = import.meta.env.DEV ? "web" : "desktop"; - - let session; - - if (platform === "web") - session = await createLocalServerSession(abort.signal); - else session = await createDeepLinkSession(abort.signal); - - await shell.open(session.url.toString()); - - await processAuthData(await session.complete()); - - getCurrentWindow().setFocus(); - }, - })); + const signIn = createSignInMutation(); return ( - - - Previous Recordings - - } - > + getCurrentWindow().hide(); + }} + class="flex items-center justify-center w-5 h-5 -ml-[1.5px]" + > + + + + Previous Recordings}> - + type="button" + onClick={async () => { + await commands.showWindow({ Settings: { page: "recordings" } }); + getCurrentWindow().hide(); + }} + class="flex justify-center items-center w-5 h-5" + > + + + @@ -794,7 +782,6 @@ function MicrophoneSelect(props: { const [dbs, setDbs] = createSignal(); const [isInitialized, setIsInitialized] = createSignal(false); - const requestPermission = useRequestPermission(); const permissionGranted = () => @@ -1036,7 +1023,7 @@ function TargetSelectInfoPill(props: { ? "On" : "Off"} -); + ); } function InfoPill( @@ -1112,10 +1099,7 @@ function ChangelogButton() { }); return ( - + - }> - -
-

- Your account is upgraded to Cap Pro and already includes a - commercial license. -

-
-
- - {(license) => ( -
-

- Your License -

-
- -
-                  {license().licenseKey}
-                
-
- - {(expiry) => ( -
- - - {new Date(expiry()).toUTCString()} - -
- )} -
- - {/*

- Instance ID: {license().instanceId} -

*/} -
- -
-
- )} -
-
- - ); -} - -function LicenseKeyActivate(props: { - onActivated: ( - value: ClientInferResponseBody< - (typeof licenseContract)["activateCommercialLicense"], - 200 - > & { licenseKey: string } - ) => void; -}) { - const [store] = createResource(() => generalSettingsStore.get()); - - return ( - - - {(generalSettings) => { - const [licenseKey, setLicenseKey] = createSignal(""); - - const activateLicenseKey = createMutation(() => ({ - mutationFn: async (vars: { licenseKey: string }) => { - const resp = await licenseApiClient.activateCommercialLicense({ - headers: { - licensekey: vars.licenseKey, - instanceid: generalSettings().instanceId!, - }, - body: { reset: false }, - }); - - if (resp.status === 200) return resp.body; - if ( - typeof resp.body === "object" && - resp.body && - "message" in resp.body - ) - throw resp.body.message; - throw new Error((resp.body as any).toString()); - }, - onSuccess: (value, { licenseKey }) => - props.onActivated({ ...value, licenseKey }), - })); - - return ( -
-

- Got a license key? Enter it below -

- setLicenseKey(e.currentTarget.value)} - /> - - {/*

- Instance ID: {generalSettings().instanceId} -

*/} -
- ); - }} -
-
- ); -} - -type CommercialLicenseType = "yearly" | "lifetime"; -function CommercialLicensePurchase() { - const openCheckoutInExternalBrowser = createMutation(() => ({ - mutationFn: async ({ type }: { type: CommercialLicenseType }) => { - const resp = await licenseApiClient.createCommercialCheckoutUrl({ - body: { type }, - }); - - if (resp.status === 200) tauriShell.open(resp.body.url); - else throw resp.body; - }, - })); - - const [type, setType] = createSignal("yearly"); - - return ( - <> -
-
-
-

- Commercial License -

-

- For professional use without cloud features. -

-
-
-

- {type() === "yearly" ? "$29/year" : "$58"} -

-
- {type() === "lifetime" && ( -

- billed once -

- )} - {type() === "lifetime" && ( -

- or, $29/year. -

- )} -
-
-
-
-
-
- - Switch to {type() === "yearly" ? "lifetime" : "yearly"} - - -
-
-
- -
-
-
-
-
    - {[ - "Commercial Use of Cap Recorder + Editor", - "Community Support", - ].map((feature) => ( -
  • -
    - -
    - - {feature} - -
  • - ))} -
-
-
-
-
-
- { - await generalSettingsStore.set({ - commercialLicense: { - activatedOn: Date.now(), - expiryDate: value.expiryDate ?? null, - refresh: value.refresh, - licenseKey: value.licenseKey, - }, - }); - }} - /> - - ); -} diff --git a/apps/desktop/src/routes/(window-chrome)/settings.tsx b/apps/desktop/src/routes/(window-chrome)/settings.tsx index 3aee9259737..c3f8864981b 100644 --- a/apps/desktop/src/routes/(window-chrome)/settings.tsx +++ b/apps/desktop/src/routes/(window-chrome)/settings.tsx @@ -46,6 +46,11 @@ export default function Settings(props: RouteSectionProps) { name: "Integrations", icon: IconLucideUnplug, }, + { + href: "license", + name: "License", + icon: IconLucideGift, + }, { href: "experimental", name: "Experimental", diff --git a/apps/desktop/src/routes/(window-chrome)/settings/experimental.tsx b/apps/desktop/src/routes/(window-chrome)/settings/experimental.tsx index c6740bcfae2..38b44c65f6b 100644 --- a/apps/desktop/src/routes/(window-chrome)/settings/experimental.tsx +++ b/apps/desktop/src/routes/(window-chrome)/settings/experimental.tsx @@ -41,10 +41,10 @@ function Inner(props: { initialStore: GeneralSettingsStore | null }) {
-

+

Experimental Features

-

+

These features are still in development and may not work as expected.

diff --git a/apps/desktop/src/routes/(window-chrome)/settings/feedback.tsx b/apps/desktop/src/routes/(window-chrome)/settings/feedback.tsx index 775f70e8578..70d390088a6 100644 --- a/apps/desktop/src/routes/(window-chrome)/settings/feedback.tsx +++ b/apps/desktop/src/routes/(window-chrome)/settings/feedback.tsx @@ -1,12 +1,14 @@ import { Button } from "@cap/ui-solid"; import { action, useAction, useSubmission } from "@solidjs/router"; import { createSignal } from "solid-js"; +import { type as ostype } from "@tauri-apps/plugin-os"; +import { getVersion } from "@tauri-apps/api/app"; import { apiClient, protectedHeaders } from "~/utils/web-api"; const sendFeedbackAction = action(async (feedback: string) => { const response = await apiClient.desktop.submitFeedback({ - body: { feedback }, + body: { feedback, os: ostype() as any, version: await getVersion() }, headers: await protectedHeaders(), }); @@ -21,50 +23,56 @@ export default function FeedbackTab() { const sendFeedback = useAction(sendFeedbackAction); return ( -
-

Send Feedback

-

- Help us improve Cap by submitting feedback or reporting bugs. We'll get - right on it. -

-
{ - e.preventDefault(); - sendFeedback(feedback()); - }} - > -
-
-