Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(app): poll for subscription status after checkout

Louis Beaumont6ccae497dbc0
diff --git a/apps/screenpipe-app-tauri/components/settings/account-section.tsx b/apps/screenpipe-app-tauri/components/settings/account-section.tsx
index ab37607b4..f48d9b00a 100644
--- a/apps/screenpipe-app-tauri/components/settings/account-section.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/account-section.tsx
@@ -95,6 +95,40 @@ export function AccountSection() {
const data = await response.json();
if (data.url) {
openUrl(data.url);
+
+ // Poll for subscription status every 1 second after checkout
+ let pollCount = 0;
+ const maxPolls = 300; // 5 minutes
+ const checkInterval = setInterval(async () => {
+ pollCount++;
+ try {
+ const subResponse = await fetch(
+ `https://screenpi.pe/api/cloud-sync/subscription?userId=${settings.user?.id}&email=${encodeURIComponent(settings.user?.email || "")}`,
+ {
+ headers: { Authorization: `Bearer ${settings.user?.token}` },
+ }
+ );
+ if (subResponse.ok) {
+ const subData = await subResponse.json();
+ if (subData.hasSubscription) {
+ clearInterval(checkInterval);
+ // Update user state with subscription
+ updateSettings({
+ user: { ...settings.user!, cloud_subscribed: true },
+ });
+ toast({
+ title: "subscription activated",
+ description: "welcome to screenpipe pro!",
+ });
+ }
+ }
+ } catch (e) {
+ console.error("polling error:", e);
+ }
+ if (pollCount >= maxPolls) {
+ clearInterval(checkInterval);
+ }
+ }, 1000);
} else {
throw new Error(data.error || "failed to create checkout");
}
diff --git a/apps/screenpipe-app-tauri/components/settings/sync-settings.tsx b/apps/screenpipe-app-tauri/components/settings/sync-settings.tsx
index 74605a608..0e6e33019 100644
--- a/apps/screenpipe-app-tauri/components/settings/sync-settings.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/sync-settings.tsx
@@ -575,7 +575,7 @@ function ActiveSyncSettings({
}
export function SyncSettings() {
- const { settings, isSettingsLoaded } = useSettings();
+ const { settings, isSettingsLoaded, updateSettings } = useSettings();
const [step, setStep] = useState<"loading" | "onboarding" | "password" | "active">("loading");
const [subscription, setSubscription] = useState<SubscriptionStatus | null>(null);
const [status, setStatus] = useState<SyncStatus | null>(null);
@@ -605,7 +605,7 @@ export function SyncSettings() {
description: "you can now set up your encryption password",
});
}
- }, 5000); // Poll every 5 seconds
+ }, 1000); // Poll every 1 second
return () => clearInterval(pollInterval);
}, [step]);
@@ -638,6 +638,12 @@ export function SyncSettings() {
});
if (data.hasSubscription) {
+ // Update user.cloud_subscribed so account-section shows correct state
+ if (settings.user && !settings.user.cloud_subscribed) {
+ await updateSettings({
+ user: { ...settings.user, cloud_subscribed: true },
+ });
+ }
try {
const [statusResult, configResult, devicesResult] = await Promise.all([
invoke<SyncStatus>("get_sync_status"),
@@ -716,7 +722,7 @@ export function SyncSettings() {
// Poll for subscription status - stop when subscription is detected
let pollCount = 0;
- const maxPolls = 100; // 5 minutes at 3 second intervals
+ const maxPolls = 300; // 5 minutes at 1 second intervals
const checkInterval = setInterval(async () => {
pollCount++;
console.log(`polling for subscription... attempt ${pollCount}`);
@@ -732,7 +738,7 @@ export function SyncSettings() {
console.log("stopping subscription poll - max attempts reached");
clearInterval(checkInterval);
}
- }, 3000);
+ }, 1000);
} else {
throw new Error(data.error || "failed to create checkout");
}