Skip to content

Commit

Permalink
Merge branch 'main' into next-windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsEeleeya authored Nov 15, 2024
2 parents 47931d4 + 9281903 commit dcfb4af
Show file tree
Hide file tree
Showing 13 changed files with 322 additions and 204 deletions.
3 changes: 2 additions & 1 deletion apps/desktop/src-tauri/src/general_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub struct GeneralSettingsStore {
pub enable_notifications: bool,
#[serde(default)]
pub disable_auto_open_links: bool,
#[serde(default)]
// first launch: store won't exist so show startup
#[serde(default = "true_b")]
pub has_completed_startup: bool,
}

Expand Down
10 changes: 8 additions & 2 deletions apps/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2521,8 +2521,14 @@ pub async fn run() {
let permissions = permissions::do_permissions_check(false);
println!("Permissions check result: {:?}", permissions);

if !permissions.screen_recording.permitted() || !permissions.accessibility.permitted() {
println!("Required permissions not granted, showing permissions window");
if !permissions.screen_recording.permitted()
|| !permissions.accessibility.permitted()
|| GeneralSettingsStore::get(app.handle())
.ok()
.flatten()
.map(|s| !s.has_completed_startup)
.unwrap_or(false)
{
CapWindow::Setup.show(&app_handle).ok();
} else {
println!("Permissions granted, showing main window");
Expand Down
5 changes: 4 additions & 1 deletion apps/desktop/src/routes/(window-chrome).tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export default function (props: RouteSectionProps) {
exitToClass="opacity-0"
> */}
<Suspense fallback={<AbsoluteInsetLoader />}>
<Inner>{props.children}</Inner>
<Inner>
{/* prevents flicker idk */}
<Suspense>{props.children}</Suspense>
</Inner>
</Suspense>
{/* </Transition> */}
</div>
Expand Down
6 changes: 3 additions & 3 deletions apps/desktop/src/routes/(window-chrome)/(main).tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ import {

const getAuth = cache(async () => {
const value = await authStore.get();
if (!value && !import.meta.env.TAURI_ENV_DEBUG) return redirect("/signin");
const local = import.meta.env.VITE_LOCAL_MODE === "true";
if (!value && !local) return redirect("/signin");
const res = await fetch(`${clientEnv.VITE_SERVER_URL}/api/desktop/plan`, {
headers: { authorization: `Bearer ${value?.token}` },
});
if (res.status !== 200 && !import.meta.env.TAURI_ENV_DEBUG)
return redirect("/signin");
if (res.status !== 200 && !local) return redirect("/signin");
return value;
}, "getAuth");

Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/routes/editor/Timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export function Timeline() {
});
}}
/>
<SegmentContent class="bg-blue-50">
<SegmentContent class="bg-blue-50 justify-between">
<span class="text-black-transparent-60 text-[0.625rem] mt-auto">
{formatTime(segment.start)}
</span>
Expand Down
115 changes: 57 additions & 58 deletions apps/web/app/api/settings/billing/subscribe/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,90 +6,89 @@ import { db } from "@cap/database";
import { users } from "@cap/database/schema";

export async function POST(request: NextRequest) {
console.log("Starting subscription process");
const user = await getCurrentUser();
let customerId = user?.stripeCustomerId;
const { priceId } = await request.json();

console.log("Received request with priceId:", priceId);
console.log("Current user:", user?.id);

if (!priceId) {
console.error("Price ID not found");

return new Response(JSON.stringify({ error: true }), {
status: 400,
headers: {
"Content-Type": "application/json",
},
headers: { "Content-Type": "application/json" },
});
}

if (!user) {
console.error("User not found");

return new Response(JSON.stringify({ error: true, auth: false }), {
status: 401,
headers: {
"Content-Type": "application/json",
},
headers: { "Content-Type": "application/json" },
});
}

if (
isUserOnProPlan({
subscriptionStatus: user.stripeSubscriptionStatus as string,
})
) {

if (isUserOnProPlan({ subscriptionStatus: user.stripeSubscriptionStatus as string })) {
console.error("User already has pro plan");
return new Response(JSON.stringify({ error: true, subscription: true }), {
status: 400,
headers: {
"Content-Type": "application/json",
},
headers: { "Content-Type": "application/json" },
});
}

if (!user.stripeCustomerId) {
const customer = await stripe.customers.create({
email: user.email,
metadata: {
userId: user.id,
},
});
try {
if (!user.stripeCustomerId) {
console.log("Creating new Stripe customer for user:", user.id);
const customer = await stripe.customers.create({
email: user.email,
metadata: {
userId: user.id,
},
});

await db
.update(users)
.set({
stripeCustomerId: customer.id,
})
.where(eq(users.id, user.id));
console.log("Created Stripe customer:", customer.id);

customerId = customer.id;
}
await db
.update(users)
.set({
stripeCustomerId: customer.id,
})
.where(eq(users.id, user.id));

const checkoutSession = await stripe.checkout.sessions.create({
customer: customerId as string,
line_items: [
{
price: priceId,
quantity: 1,
},
],
mode: "subscription",
success_url: `${process.env.NEXT_PUBLIC_URL}/dashboard/caps?upgrade=true`,
cancel_url: `${process.env.NEXT_PUBLIC_URL}/pricing`,
allow_promotion_codes: true,
});
console.log("Updated user with Stripe customer ID");
customerId = customer.id;
}

if (checkoutSession.url) {
return new Response(JSON.stringify({ url: checkoutSession.url }), {
status: 200,
headers: {
"Content-Type": "application/json",
},
console.log("Creating checkout session for customer:", customerId);
const checkoutSession = await stripe.checkout.sessions.create({
customer: customerId as string,
line_items: [{ price: priceId, quantity: 1 }],
mode: "subscription",
success_url: `${process.env.NEXT_PUBLIC_URL}/dashboard/caps?upgrade=true`,
cancel_url: `${process.env.NEXT_PUBLIC_URL}/pricing`,
allow_promotion_codes: true,
});
}

return new Response(JSON.stringify({ error: true }), {
status: 400,
headers: {
"Content-Type": "application/json",
},
});
if (checkoutSession.url) {
console.log("Successfully created checkout session");
return new Response(JSON.stringify({ url: checkoutSession.url }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
}

console.error("Checkout session created but no URL returned");
return new Response(JSON.stringify({ error: true }), {
status: 400,
headers: { "Content-Type": "application/json" },
});
} catch (error) {
console.error("Error creating checkout session:", error);
return new Response(JSON.stringify({ error: true }), {
status: 500,
headers: { "Content-Type": "application/json" },
});
}
}
Loading

0 comments on commit dcfb4af

Please sign in to comment.