Skip to content

Commit

Permalink
release-app fixed issue settings was not refrshing well in pipes and …
Browse files Browse the repository at this point in the history
…moved meeting and speaker id to store
  • Loading branch information
louis030195 committed Dec 18, 2024
1 parent eb8ea53 commit f67af93
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
55 changes: 41 additions & 14 deletions screenpipe-app-tauri/components/pipe-store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ const corePipes: CorePipe[] = [
{
id: "data-table",
name: "data table",
description: "explore your data in a powerful table view with filtering, sorting, and more",
description:
"explore your data in a powerful table view with filtering, sorting, and more",
url: "https://github.com/mediar-ai/screenpipe/tree/main/pipes/data-table",
credits: 0,
paid: false,
Expand Down Expand Up @@ -142,15 +143,17 @@ const corePipes: CorePipe[] = [
{
id: "meeting",
name: "meeting assistant",
description: "organize and summarize your meetings with AI - get transcripts, action items, and key insights, 100% local or using cloud models",
description:
"organize and summarize your meetings with AI - get transcripts, action items, and key insights, 100% local or using cloud models",
url: "https://github.com/mediar-ai/screenpipe/tree/main/pipes/meeting",
credits: 15,
paid: true,
},
{
id: "identify-speakers",
name: "speaker identification",
description: "automatically identify and label different speakers in your recordings using AI voice recognition",
description:
"automatically identify and label different speakers in your recordings using AI voice recognition",
url: "https://github.com/mediar-ai/screenpipe/tree/main/pipes/identify-speakers",
credits: 10,
paid: true,
Expand Down Expand Up @@ -402,9 +405,19 @@ const PipeStore: React.FC = () => {
const handleToggleEnabled = async (pipe: Pipe) => {
try {
const corePipe = corePipes.find((cp) => cp.id === pipe.id);
console.log("attempting to toggle pipe:", {
pipeId: pipe.id,
isEnabled: pipe.enabled,
corePipe,
userToken: !!user?.token,
userCredits: user?.credits?.amount,
});

if (corePipe?.paid && !pipe.enabled) {
// Check if user exists AND has valid token
console.log("handling paid pipe enable flow");

if (!user?.token) {
console.log("user not authenticated, opening auth window");
toast({
title: "authentication required",
description: "please sign in to use paid pipes",
Expand All @@ -414,21 +427,33 @@ const PipeStore: React.FC = () => {
return;
}

// Check if user already purchased this pipe
const hasSubscription = await checkExistingSubscription(pipe.id);
console.log("subscription check:", {
hasSubscription,
pipeId: pipe.id,
});

if (!hasSubscription) {
const userCredits = user.credits?.amount || 0;
console.log("checking credits:", {
userCredits,
requiredCredits: corePipe.credits,
sufficient: userCredits >= corePipe.credits,
});

if (userCredits < corePipe.credits) {
// Show the dialog instead of redirecting
console.log("insufficient credits, showing dialog");
setShowCreditDialog(true);
return;
}

// If enough credits, proceed with purchase
console.log("attempting pipe purchase");
const purchaseSuccess = await handlePipePurchase(
pipe,
corePipe.credits
);
console.log("purchase result:", { purchaseSuccess });

if (!purchaseSuccess) {
toast({
title: "purchase failed",
Expand All @@ -437,6 +462,11 @@ const PipeStore: React.FC = () => {
});
return;
}

await refreshUser();
console.log("user refreshed after purchase:", {
newCredits: user?.credits?.amount,
});
}
}

Expand All @@ -445,7 +475,6 @@ const PipeStore: React.FC = () => {
enabled: !pipe.enabled,
});

// Then replace the loading toast with this:
const t = toast({
title: "loading pipe",
description: "please wait...",
Expand All @@ -458,6 +487,8 @@ const PipeStore: React.FC = () => {
});

const endpoint = pipe.enabled ? "disable" : "enable";
console.log(`calling ${endpoint} endpoint for pipe`);

const response = await fetch(`http://localhost:3030/pipes/${endpoint}`, {
method: "POST",
headers: {
Expand All @@ -467,17 +498,16 @@ const PipeStore: React.FC = () => {
});

const data = await response.json();
console.log("toggle response:", data);

if (!data.success) {
throw new Error(data.error);
}

await new Promise((resolve) => setTimeout(resolve, 1000));

const freshPipes = await fetchInstalledPipes();

await new Promise((resolve) => setTimeout(resolve, 1000));

// find the pipe in the list, and set it as selected with the proper enabled state
const freshPipe = freshPipes.find((p: Pipe) => p.id === pipe.id);
if (freshPipe) {
setSelectedPipe(freshPipe);
Expand All @@ -486,8 +516,6 @@ const PipeStore: React.FC = () => {
toast({
title: `pipe ${endpoint}d`,
});

// Still fetch the latest state from the server to ensure consistency
} catch (error) {
console.error(
`Failed to ${pipe.enabled ? "disable" : "enable"} pipe:`,
Expand Down Expand Up @@ -568,7 +596,6 @@ const PipeStore: React.FC = () => {

await fetchInstalledPipes();
setNewRepoUrl("");

} catch (error) {
console.error("failed to add custom pipe:", error);
toast({
Expand Down
2 changes: 1 addition & 1 deletion screenpipe-app-tauri/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion screenpipe-app-tauri/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "screenpipe-app"
version = "0.18.4"
version = "0.18.5"
description = ""
authors = ["you"]
license = ""
Expand Down

0 comments on commit f67af93

Please sign in to comment.