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

Make pipes update in background (#1313)

giraffekey15de77c00d86
diff --git a/screenpipe-app-tauri/components/login-dialog.tsx b/screenpipe-app-tauri/components/login-dialog.tsx
index bac3e9a45..767161920 100644
--- a/screenpipe-app-tauri/components/login-dialog.tsx
+++ b/screenpipe-app-tauri/components/login-dialog.tsx
@@ -44,9 +44,9 @@ export const LoginDialog: React.FC<LoginDialogProps> = ({ open, onOpenChange })
export const useLoginCheck = () => {
const [showLoginDialog, setShowLoginDialog] = useState(false);
- const checkLogin = (user: any | null) => {
+ const checkLogin = (user: any | null, showDialog: boolean = true) => {
if (!user?.token) {
- setShowLoginDialog(true);
+ if (showDialog) setShowLoginDialog(true);
return false;
}
return true;
diff --git a/screenpipe-app-tauri/components/pipe-store.tsx b/screenpipe-app-tauri/components/pipe-store.tsx
index 5a4767469..c97a06d91 100644
--- a/screenpipe-app-tauri/components/pipe-store.tsx
+++ b/screenpipe-app-tauri/components/pipe-store.tsx
@@ -12,6 +12,7 @@ import {
PurchaseHistoryItem,
} from "@/lib/api/store";
import { open as openUrl } from "@tauri-apps/plugin-shell";
+import { listen } from "@tauri-apps/api/event";
import { InstalledPipe, PipeWithStatus } from "./pipe-store/types";
import { PipeDetails } from "./pipe-store/pipe-details";
import { PipeCard } from "./pipe-store/pipe-card";
@@ -73,7 +74,12 @@ export const PipeStore: React.FC = () => {
}, 1000); // Debounce for 1 second
return () => clearTimeout(timeoutId);
- }, [searchQuery, filteredPipes.length]);
+ }, [searchQuery, filteredPipes.length])
+
+ listen("update-all-pipes", async () => {
+ if (!checkLogin(settings.user, false)) return;
+ await handleUpdateAllPipes(true)
+ });
const fetchStorePlugins = async () => {
try {
@@ -457,22 +463,25 @@ export const PipeStore: React.FC = () => {
}
};
- const handleUpdateAllPipes = async () => {
+ const handleUpdateAllPipes = async (delayToast: boolean = false) => {
try {
if (!checkLogin(settings.user)) return;
posthog.capture("update_all_pipes", {});
- const t = toast({
- title: "checking for updates",
- description: (
- <div className="space-y-2">
- <Progress value={0} className="h-1" />
- <p className="text-xs">checking installed pipes...</p>
- </div>
- ),
- duration: 100000,
- });
+ let t
+ if (!delayToast) {
+ t = toast({
+ title: "checking for updates",
+ description: (
+ <div className="space-y-2">
+ <Progress value={0} className="h-1" />
+ <p className="text-xs">checking installed pipes...</p>
+ </div>
+ ),
+ duration: 100000,
+ });
+ }
// Filter installed pipes that have updates available
const pipesToUpdate = pipes.filter(
@@ -480,27 +489,42 @@ export const PipeStore: React.FC = () => {
);
if (pipesToUpdate.length === 0) {
- t.update({
- id: t.id,
- title: "no updates available",
- description: "all pipes are up to date",
- duration: 2000,
- });
+ if (t) {
+ t.update({
+ id: t.id,
+ title: "no updates available",
+ description: "all pipes are up to date",
+ duration: 2000,
+ });
+ }
return;
}
// Update progress message
- t.update({
- id: t.id,
- title: `updating ${pipesToUpdate.length} pipes`,
- description: (
- <div className="space-y-2">
- <Progress value={0} className="h-1" />
- <p className="text-xs">starting updates...</p>
- </div>
- ),
- duration: 100000,
- });
+ if (t) {
+ t.update({
+ id: t.id,
+ title: `updating ${pipesToUpdate.length} pipes`,
+ description: (
+ <div className="space-y-2">
+ <Progress value={0} className="h-1" />
+ <p className="text-xs">starting updates...</p>
+ </div>
+ ),
+ duration: 100000,
+ });
+ } else {
+ t = toast({
+ title: `updating ${pipesToUpdate.length} pipes`,
+ description: (
+ <div className="space-y-2">
+ <Progress value={0} className="h-1" />
+ <p className="text-xs">starting updates...</p>
+ </div>
+ ),
+ duration: 100000,
+ });
+ }
// Update each pipe sequentially
for (let i = 0; i < pipesToUpdate.length; i++) {
@@ -1003,7 +1027,7 @@ export const PipeStore: React.FC = () => {
<Button
variant="outline"
size="icon"
- onClick={handleUpdateAllPipes}
+ onClick={() => handleUpdateAllPipes()}
className="flex items-center gap-2"
disabled={
!pipes.some(
diff --git a/screenpipe-app-tauri/src-tauri/src/updates.rs b/screenpipe-app-tauri/src-tauri/src/updates.rs
index eb055d9bf..dd9c4a9b3 100644
--- a/screenpipe-app-tauri/src-tauri/src/updates.rs
+++ b/screenpipe-app-tauri/src-tauri/src/updates.rs
@@ -5,7 +5,7 @@ use log::{error, info};
use std::sync::Arc;
use std::time::Duration;
use tauri::menu::{MenuItem, MenuItemBuilder};
-use tauri::{Manager, Wry};
+use tauri::{Emitter, Manager, Wry};
use tauri_plugin_dialog::DialogExt;
use tauri_plugin_dialog::MessageDialogButtons;
use tauri_plugin_updater::UpdaterExt;
@@ -44,6 +44,11 @@ impl UpdatesManager {
return Result::Ok(false);
}
}
+
+ if let Err(err) = self.app.emit("update-all-pipes", ()) {
+ error!("Failed to update all pipes: {}", err);
+ }
+
if let Some(update) = self.app.updater()?.check().await? {
*self.update_available.lock().await = true;