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(sync): auto-remember password, fix tray icon crash, catch_unwind in event loop

Louis Beaumont5cb100eadd8b
diff --git a/apps/screenpipe-app-tauri/components/settings/sync-settings.tsx b/apps/screenpipe-app-tauri/components/settings/sync-settings.tsx
index 0e6e33019..855219f6d 100644
--- a/apps/screenpipe-app-tauri/components/settings/sync-settings.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/sync-settings.tsx
@@ -610,6 +610,42 @@ export function SyncSettings() {
return () => clearInterval(pollInterval);
}, [step]);
+ const tryAutoInitSync = async (): Promise<boolean> => {
+ // 1. Check if the server-side sync service is already running (same session, navigated away and back)
+ try {
+ const serverStatus = await fetch("http://localhost:3030/sync/status");
+ if (serverStatus.ok) {
+ const serverData = await serverStatus.json();
+ if (serverData.enabled) {
+ await invoke("set_sync_enabled", { enabled: true });
+ setStep("active");
+ return true;
+ }
+ }
+ } catch {
+ // Server not reachable
+ }
+
+ // 2. Try to auto-init from saved password (app restart case)
+ try {
+ const savedPassword = localStorage.getItem("sync_password");
+ if (savedPassword) {
+ const password = atob(savedPassword);
+ await invoke<boolean>("init_sync", { password });
+ await checkSubscriptionAndLoad();
+ setStep("active");
+ return true;
+ }
+ } catch (e) {
+ console.log("auto-init sync failed, will prompt for password:", e);
+ // Password might be wrong (user changed it on another device)
+ // Clear saved password so we don't keep failing
+ localStorage.removeItem("sync_password");
+ }
+
+ return false;
+ };
+
const checkSubscriptionAndLoad = async (): Promise<boolean> => {
try {
const token = settings.user?.token;
@@ -657,7 +693,11 @@ export function SyncSettings() {
if (statusResult.enabled) {
setStep("active");
} else {
- setStep("password");
+ // Try to auto-init from saved password or running server
+ const autoInited = await tryAutoInitSync();
+ if (!autoInited) {
+ setStep("password");
+ }
}
} catch (backendError) {
console.error("sync backend not ready:", backendError);
@@ -758,6 +798,14 @@ export function SyncSettings() {
setIsLoading(true);
await invoke<boolean>("init_sync", { password });
+ // Remember password for auto-init on next app launch
+ // Stored in app's WebView localStorage (sandboxed, not accessible externally)
+ try {
+ localStorage.setItem("sync_password", btoa(password));
+ } catch {
+ // Non-critical if storage fails
+ }
+
toast({
title: "cloud sync enabled",
description: "your data is now syncing securely",
@@ -864,6 +912,7 @@ export function SyncSettings() {
const handleDeleteCloudData = async () => {
try {
await invoke("delete_cloud_data");
+ localStorage.removeItem("sync_password");
toast({
title: "cloud data deleted",
description: "all your cloud data has been permanently deleted",
@@ -880,6 +929,7 @@ export function SyncSettings() {
const handleLockSync = async () => {
await invoke("lock_sync");
+ localStorage.removeItem("sync_password");
await checkSubscriptionAndLoad();
};
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/health.rs b/apps/screenpipe-app-tauri/src-tauri/src/health.rs
index 3d0ead4e0..4a7e9020e 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/health.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/health.rs
@@ -6,6 +6,7 @@ use std::sync::RwLock;
use std::time::Instant;
use tauri::{path::BaseDirectory, Manager};
use tokio::time::{interval, Duration};
+use tracing::error;
/// How long after startup to treat connection errors as "starting up" instead of "error".
/// The recording server needs time to load whisper models, FFmpeg, etc.
@@ -151,14 +152,26 @@ pub async fn start_health_check(app: tauri::AppHandle) -> Result<()> {
}
};
- let icon_path = app
+ let icon_path = match app
.path()
- .resolve(icon_path, BaseDirectory::Resource)
- .expect("failed to resolve icon path");
+ .resolve(icon_path, BaseDirectory::Resource) {
+ Ok(p) => p,
+ Err(e) => {
+ error!("failed to resolve icon path: {}", e);
+ continue;
+ }
+ };
- let _ = main_tray
- .set_icon(Some(tauri::image::Image::from_path(&icon_path).unwrap()))
- .and_then(|_| main_tray.set_icon_as_template(true));
+ match tauri::image::Image::from_path(&icon_path) {
+ Ok(image) => {
+ let _ = main_tray
+ .set_icon(Some(image))
+ .and_then(|_| main_tray.set_icon_as_template(true));
+ }
+ Err(e) => {
+ error!("failed to load tray icon from {:?}: {}", icon_path, e);
+ }
+ }
}
}
}
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
index 8a3891cae..1b2ffaf2d 100755
--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -1604,7 +1604,11 @@ async fn main() {
setup_dock_menu(app_handle_dock);
}
- app.run(|app_handle, event| match event {
+ app.run(|app_handle, event| {
+ // Wrap in catch_unwind: this closure is called from tao::send_event
+ // which crosses the Obj-C FFI boundary (nounwind). A panic here would abort().
+ let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
+ match event {
tauri::RunEvent::Ready { .. } => {
debug!("Ready event");
// Send app started event
@@ -1694,5 +1698,10 @@ async fn main() {
let _ = ShowRewindWindow::Main.show(&app_handle);
}
_ => {}
+ }
+ })); // end catch_unwind
+ if let Err(e) = result {
+ error!("panic in run event handler: {:?}", e);
+ }
});
}
diff --git a/crates/screenpipe-core/src/sync/client.rs b/crates/screenpipe-core/src/sync/client.rs
index 8d671290f..d066c73e2 100644
--- a/crates/screenpipe-core/src/sync/client.rs
+++ b/crates/screenpipe-core/src/sync/client.rs
@@ -268,20 +268,27 @@ impl SyncClient {
})
}
- /// Upload encrypted data to S3 using a presigned URL.
+ /// Upload encrypted data using a Supabase signed upload URL.
+ ///
+ /// Supabase `createSignedUploadUrl` returns URLs that must be used with PUT
+ /// and require the upload token in the URL path. The URL format is:
+ /// `{supabaseUrl}/storage/v1/object/upload/sign/{bucket}/{path}?token={token}`
pub async fn upload_to_s3(&self, upload_url: &str, data: &[u8]) -> SyncResult<()> {
let response = self
.http
.put(upload_url)
.header("Content-Type", "application/octet-stream")
+ .header("x-upsert", "true")
.body(data.to_vec())
.send()
.await?;
if !response.status().is_success() {
+ let status = response.status();
+ let body = response.text().await.unwrap_or_default();
return Err(SyncError::Server(format!(
- "S3 upload failed with status: {}",
- response.status()
+ "S3 upload failed with status: {} body: {}",
+ status, body
)));
}