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

feat: rollback to previous version

Louis Beaumontc7fbc3ead8f3
diff --git a/Cargo.lock b/Cargo.lock
index bb3d13b33..7b89f8663 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6642,7 +6642,7 @@ dependencies = [
[[package]]
name = "screenpipe-audio"
-version = "0.3.107"
+version = "0.3.109"
dependencies = [
"anyhow",
"bytemuck",
@@ -6695,7 +6695,7 @@ dependencies = [
[[package]]
name = "screenpipe-core"
-version = "0.3.107"
+version = "0.3.109"
dependencies = [
"accessibility",
"accessibility-sys",
@@ -6746,7 +6746,7 @@ dependencies = [
[[package]]
name = "screenpipe-db"
-version = "0.3.107"
+version = "0.3.109"
dependencies = [
"anyhow",
"chrono",
@@ -6770,7 +6770,7 @@ dependencies = [
[[package]]
name = "screenpipe-events"
-version = "0.3.107"
+version = "0.3.109"
dependencies = [
"anyhow",
"chrono",
@@ -6788,7 +6788,7 @@ dependencies = [
[[package]]
name = "screenpipe-integrations"
-version = "0.3.107"
+version = "0.3.109"
dependencies = [
"anyhow",
"image",
@@ -6803,7 +6803,7 @@ dependencies = [
[[package]]
name = "screenpipe-server"
-version = "0.3.107"
+version = "0.3.109"
dependencies = [
"anyhow",
"async-trait",
@@ -6873,7 +6873,7 @@ dependencies = [
[[package]]
name = "screenpipe-vision"
-version = "0.3.107"
+version = "0.3.109"
dependencies = [
"accessibility-sys",
"anyhow",
diff --git a/apps/screenpipe-app-tauri/components/settings/general-settings.tsx b/apps/screenpipe-app-tauri/components/settings/general-settings.tsx
index a12f43041..154b8872d 100644
--- a/apps/screenpipe-app-tauri/components/settings/general-settings.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/general-settings.tsx
@@ -1,22 +1,32 @@
"use client";
-import React from "react";
+import React, { useEffect, useState } from "react";
import { useSettings } from "@/lib/hooks/use-settings";
import { useTheme } from "@/components/theme-provider";
import { Switch } from "@/components/ui/switch";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Separator } from "@/components/ui/separator";
-import { Rocket, Moon, Sun, Monitor, FlaskConical, Shield, ExternalLink, Layers, RefreshCw } from "lucide-react";
+import { Rocket, Moon, Sun, Monitor, FlaskConical, Shield, ExternalLink, Layers, RefreshCw, Undo2 } from "lucide-react";
import { useToast } from "@/components/ui/use-toast";
import { Button } from "@/components/ui/button";
import { Settings } from "@/lib/hooks/use-settings";
import { open } from "@tauri-apps/plugin-shell";
+import { invoke } from "@tauri-apps/api/core";
+import { getVersion } from "@tauri-apps/api/app";
import { UpdateBanner } from "@/components/update-banner";
export default function GeneralSettings() {
const { settings, updateSettings } = useSettings();
const { theme, setTheme } = useTheme();
const { toast } = useToast();
+ const [currentVersion, setCurrentVersion] = useState<string | null>(null);
+ const [rollbackVersion, setRollbackVersion] = useState<string | null>(null);
+ const [isRollingBack, setIsRollingBack] = useState(false);
+
+ useEffect(() => {
+ getVersion().then(setCurrentVersion).catch(() => {});
+ invoke<string | null>("get_rollback_version").then(setRollbackVersion).catch(() => {});
+ }, []);
const handleSettingsChange = (newSettings: Partial<Settings>) => {
if (settings) {
@@ -45,6 +55,27 @@ export default function GeneralSettings() {
},
];
+ const handleRollback = async () => {
+ if (!rollbackVersion || isRollingBack) return;
+ setIsRollingBack(true);
+ try {
+ toast({
+ title: "rolling back...",
+ description: `restoring v${rollbackVersion}. the app will restart.`,
+ duration: 5000,
+ });
+ await invoke("rollback_to_previous_version");
+ } catch (e: any) {
+ setIsRollingBack(false);
+ toast({
+ title: "rollback failed",
+ description: e?.toString() || "unknown error",
+ variant: "destructive",
+ duration: 5000,
+ });
+ }
+ };
+
const handleDownloadBeta = async () => {
// Open the beta download page
await open("https://screenpi.pe/beta");
@@ -114,6 +145,37 @@ export default function GeneralSettings() {
</CardContent>
</Card>
+ <Card className="border-border bg-card">
+ <CardContent className="px-3 py-2.5">
+ <div className="flex items-center justify-between">
+ <div className="flex items-center space-x-2.5">
+ <Undo2 className="h-4 w-4 text-muted-foreground shrink-0" />
+ <div>
+ <h3 className="text-sm font-medium text-foreground">
+ Version{currentVersion ? ` ${currentVersion}` : ""}
+ </h3>
+ <p className="text-xs text-muted-foreground">
+ {rollbackVersion
+ ? `previous: v${rollbackVersion}`
+ : "no previous version saved yet"}
+ </p>
+ </div>
+ </div>
+ {rollbackVersion && (
+ <Button
+ variant="outline"
+ size="sm"
+ onClick={handleRollback}
+ disabled={isRollingBack}
+ className="ml-4 h-7 text-xs"
+ >
+ {isRollingBack ? "rolling back..." : `rollback to v${rollbackVersion}`}
+ </Button>
+ )}
+ </div>
+ </CardContent>
+ </Card>
+
<Card className="border-border bg-card">
<CardContent className="px-3 py-2.5">
<div className="space-y-2.5">
diff --git a/apps/screenpipe-app-tauri/components/updater.tsx b/apps/screenpipe-app-tauri/components/updater.tsx
index dc14f672d..ff3f7f558 100644
--- a/apps/screenpipe-app-tauri/components/updater.tsx
+++ b/apps/screenpipe-app-tauri/components/updater.tsx
@@ -58,6 +58,13 @@ Release notes: ${update.body}
});
try {
+ // Back up current app bundle before replacing it (for rollback)
+ try {
+ await invoke("backup_current_app");
+ } catch (_) {
+ // Non-fatal — proceed with update even if backup fails
+ console.warn("rollback backup failed, continuing with update");
+ }
await update.downloadAndInstall();
toast({
id: toastId,
diff --git a/apps/screenpipe-app-tauri/lib/utils/tauri.ts b/apps/screenpipe-app-tauri/lib/utils/tauri.ts
index 8336c6655..e3973eec5 100644
--- a/apps/screenpipe-app-tauri/lib/utils/tauri.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/tauri.ts
@@ -259,6 +259,29 @@ async resumeArrowShortcuts() : Promise<Result<null, string>> {
else return { status: "error", error: e as any };
}
},
+/**
+ * Get the version of the backed-up app (if any), so the UI can show a rollback button
+ */
+async getRollbackVersion() : Promise<string | null> {
+ return await TAURI_INVOKE("get_rollback_version");
+},
+/**
+ * Roll back to the previous version. Spawns a helper script, then the app must quit.
+ */
+async rollbackToPreviousVersion() : Promise<Result<null, string>> {
+ try {
+ return { status: "ok", data: await TAURI_INVOKE("rollback_to_previous_version") };
+} catch (e) {
+ if(e instanceof Error) throw e;
+ else return { status: "error", error: e as any };
+}
+},
+/**
+ * Back up the current app bundle (called from frontend before JS-driven updates)
+ */
+async backupCurrentApp() : Promise<void> {
+ await TAURI_INVOKE("backup_current_app");
+},
async setTrayUnhealthIcon() : Promise<void> {
await TAURI_INVOKE("set_tray_unhealth_icon");
},
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
index 5019dd684..3e3c0f954 100755
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -9100,7 +9100,7 @@ dependencies = [
[[package]]
name = "screenpipe-audio"
-version = "0.3.108"
+version = "0.3.109"
dependencies = [
"anyhow",
"bytemuck",
@@ -9148,7 +9148,7 @@ dependencies = [
[[package]]
name = "screenpipe-core"
-version = "0.3.108"
+version = "0.3.109"
dependencies = [
"accessibility",
"accessibility-sys",
@@ -9199,7 +9199,7 @@ dependencies = [
[[package]]
name = "screenpipe-db"
-version = "0.3.108"
+version = "0.3.109"
dependencies = [
"anyhow",
"chrono",
@@ -9223,7 +9223,7 @@ dependencies = [
[[package]]
name = "screenpipe-events"
-version = "0.3.108"
+version = "0.3.109"
dependencies = [
"anyhow",
"chrono",
@@ -9239,7 +9239,7 @@ dependencies = [
[[package]]
name = "screenpipe-integrations"
-version = "0.3.108"
+version = "0.3.109"
dependencies = [
"anyhow",
"image 0.25.9",
@@ -9254,7 +9254,7 @@ dependencies = [
[[package]]
name = "screenpipe-server"
-version = "0.3.108"
+version = "0.3.109"
dependencies = [
"anyhow",
"async-trait",
@@ -9319,7 +9319,7 @@ dependencies = [
[[package]]
name = "screenpipe-vision"
-version = "0.3.108"
+version = "0.3.109"
dependencies = [
"accessibility-sys",
"anyhow",
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
index 270609f48..3bbd8bfc5 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
@@ -888,6 +888,47 @@ fn unregister_arrow_shortcuts(app_handle: &tauri::AppHandle) -> Result<(), Strin
Ok(())
}
+/// Get the version of the backed-up app (if any), so the UI can show a rollback button
+#[tauri::command]
+#[specta::specta]
+pub fn get_rollback_version() -> Option<String> {
+ crate::updates::rollback_version()
+}
+
+/// Back up the current app bundle (called from frontend before JS-driven updates)
+#[tauri::command]
+#[specta::specta]
+pub fn backup_current_app() {
+ crate::updates::backup_current_app_cmd();
+}
+
+/// Roll back to the previous version. Spawns a helper script, then the app must quit.
+#[tauri::command]
+#[specta::specta]
+pub async fn rollback_to_previous_version(
+ app_handle: tauri::AppHandle,
+) -> Result<(), String> {
+ use crate::RecordingState;
+ info!("rollback_to_previous_version: starting rollback");
+
+ // Stop recording first
+ if let Err(e) = crate::stop_screenpipe(
+ app_handle.state::<RecordingState>(),
+ app_handle.clone(),
+ ).await {
+ error!("rollback: failed to stop recording: {}", e);
+ // Continue anyway — the rollback script will kill us
+ }
+
+ // Perform the rollback (spawns helper script)
+ crate::updates::perform_rollback()?;
+
+ // Quit the app so the helper script can replace the bundle
+ info!("rollback: quitting app for replacement");
+ app_handle.exit(0);
+ Ok(())
+}
+
/// Suspend arrow shortcuts (called from JS when search/chat modal opens)
#[tauri::command]
#[specta::specta]
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
index 97aa50239..8a3891cae 100755
--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -990,6 +990,10 @@ async fn main() {
commands::unregister_window_shortcuts,
commands::suspend_arrow_shortcuts,
commands::resume_arrow_shortcuts,
+ // Rollback commands
+ commands::get_rollback_version,
+ commands::rollback_to_previous_version,
+ commands::backup_current_app,
// Commands from tray.rs
set_tray_unhealth_icon,
set_tray_health_icon,
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/updates.rs b/apps/screenpipe-app-tauri/src-tauri/src/updates.rs
index 14a7a08a5..3d3cf9b4d 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/updates.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/updates.rs
@@ -3,8 +3,9 @@ use crate::store::SettingsStore;
use crate::RecordingState;
use anyhow::Error;
use dark_light::Mode;
-use log::{error, info};
+use log::{error, info, warn};
use serde_json;
+use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;
use tauri::menu::{MenuItem, MenuItemBuilder};
@@ -18,6 +19,322 @@ use tokio::sync::oneshot;
use tokio::sync::Mutex;
use tokio::time::interval;
+// ---------------------------------------------------------------------------
+// Rollback: backup current app bundle before updates, restore on demand
+// ---------------------------------------------------------------------------
+
+/// Directory where we keep the previous version's app bundle
+fn rollback_dir() -> Option<PathBuf> {
+ dirs::home_dir().map(|h| h.join(".screenpipe").join("rollback"))
+}
+
+/// Read the version string stored alongside the rollback backup
+pub fn rollback_version() -> Option<String> {
+ let dir = rollback_dir()?;
+ let version_file = dir.join("version.txt");
+ std::fs::read_to_string(version_file).ok().map(|s| s.trim().to_string()).filter(|s| !s.is_empty())
+}
+
+/// Public wrapper for the Tauri command (frontend JS-driven updates)
+pub fn backup_current_app_cmd() {
+ backup_current_app();
+}
+
+/// Back up the currently-running app bundle so we can rollback later.
+/// Called right before `download_and_install`.
+fn backup_current_app() {
+ let current_version = env!("CARGO_PKG_VERSION");
+
+ #[cfg(target_os = "macos")]
+ {
+ // Resolve /Applications/screenpipe.app from the running binary
+ // Binary is at <app>/Contents/MacOS/screenpipe
+ let exe = match std::env::current_exe() {
+ Ok(p) => p,
+ Err(e) => { warn!("rollback: cannot resolve exe path: {}", e); return; }
+ };
+ // Walk up: MacOS -> Contents -> screenpipe.app
+ let app_bundle = match exe.parent().and_then(|p| p.parent()).and_then(|p| p.parent()) {
+ Some(p) => p.to_path_buf(),
+ None => { warn!("rollback: cannot derive .app bundle from exe"); return; }
+ };
+ if !app_bundle.exists() {
+ warn!("rollback: app bundle not found at {:?}", app_bundle);
+ return;
+ }
+ let dir = match rollback_dir() {
+ Some(d) => d,
+ None => return,
+ };
+ let dest = dir.join("screenpipe.app");
+ // Atomic-ish: copy to tmp dir first, then rename
+ let tmp_dest = dir.join("screenpipe.app.tmp");
+ // Clean up any leftovers
+ let _ = std::fs::remove_dir_all(&tmp_dest);
+ let _ = std::fs::remove_dir_all(&dest);
+ if let Err(e) = std::fs::create_dir_all(&dir) {
+ warn!("rollback: cannot create rollback dir: {}", e);
+ return;
+ }
+ info!("rollback: backing up {:?} -> {:?}", app_bundle, tmp_dest);
+ match copy_dir_recursive(&app_bundle, &tmp_dest) {
+ Ok(_) => {
+ if let Err(e) = std::fs::rename(&tmp_dest, &dest) {
+ warn!("rollback: rename failed: {}", e);
+ let _ = std::fs::remove_dir_all(&tmp_dest);
+ return;
+ }
+ if let Err(e) = std::fs::write(dir.join("version.txt"), current_version) {
+ warn!("rollback: failed to write version.txt: {}", e);
+ }
+ info!("rollback: backed up v{} successfully", current_version);
+ }
+ Err(e) => {
+ warn!("rollback: copy failed: {}", e);
+ let _ = std::fs::remove_dir_all(&tmp_dest);
+ }
+ }
+ }
+
+ #[cfg(target_os = "windows")]
+ {
+ // On Windows the Tauri updater replaces the exe in-place via NSIS/WiX.
+ // We back up the entire install directory.
+ let exe = match std::env::current_exe() {
+ Ok(p) => p,
+ Err(e) => { warn!("rollback: cannot resolve exe path: {}", e); return; }
+ };
+ let install_dir = match exe.parent() {
+ Some(p) => p.to_path_buf(),
+ None => return,
+ };
+ let dir = match rollback_dir() {
+ Some(d) => d,
+ None => return,
+ };
+ let dest = dir.join("app");
+ let tmp_dest = dir.join("app.tmp");
+ let _ = std::fs::remove_dir_all(&tmp_dest);
+ let _ = std::fs::remove_dir_all(&dest);
+ if let Err(e) = std::fs::create_dir_all(&dir) {
+ warn!("rollback: cannot create rollback dir: {}", e);
+ return;
+ }
+ info!("rollback: backing up {:?} -> {:?}", install_dir, tmp_dest);
+ match copy_dir_recursive(&install_dir, &tmp_dest) {
+ Ok(_) => {
+ if let Err(e) = std::fs::rename(&tmp_dest, &dest) {
+ warn!("rollback: rename failed: {}", e);
+ let _ = std::fs::remove_dir_all(&tmp_dest);
+ return;
+ }
+ if let Err(e) = std::fs::write(dir.join("version.txt"), current_version) {
+ warn!("rollback: failed to write version.txt: {}", e);
+ }
+ info!("rollback: backed up v{} successfully", current_version);
+ }
+ Err(e) => {
+ warn!("rollback: copy failed: {}", e);
+ let _ = std::fs::remove_dir_all(&tmp_dest);
+ }
+ }
+ }
+
+ #[cfg(target_os = "linux")]
+ {
+ // AppImage: back up the AppImage file itself
+ if let Ok(appimage) = std::env::var("APPIMAGE") {
+ let src = PathBuf::from(&appimage);
+ if src.exists() {
+ let dir = match rollback_dir() {
+ Some(d) => d,
+ None => return,
+ };
+ if let Err(e) = std::fs::create_dir_all(&dir) {
+ warn!("rollback: cannot create rollback dir: {}", e);
+ return;
+ }
+ let dest = dir.join(src.file_name().unwrap_or_default());
+ info!("rollback: backing up {:?} -> {:?}", src, dest);
+ if let Err(e) = std::fs::copy(&src, &dest) {
+ warn!("rollback: copy failed: {}", e);
+ return;
+ }
+ if let Err(e) = std::fs::write(dir.join("version.txt"), current_version) {
+ warn!("rollback: failed to write version.txt: {}", e);
+ }
+ info!("rollback: backed up v{} successfully", current_version);
+ }
+ }
+ }
+}
+
+/// Recursively copy a directory
+fn copy_dir_recursive(src: &std::path::Path, dst: &std::path::Path) -> std::io::Result<()> {
+ std::fs::create_dir_all(dst)?;
+ for entry in std::fs::read_dir(src)? {
+ let entry = entry?;
+ let ty = entry.file_type()?;
+ let dest_path = dst.join(entry.file_name());
+ if ty.is_dir() {
+ copy_dir_recursive(&entry.path(), &dest_path)?;
+ } else if ty.is_symlink() {
+ let target = std::fs::read_link(entry.path())?;
+ #[cfg(unix)]
+ std::os::unix::fs::symlink(&target, &dest_path)?;
+ #[cfg(windows)]
+ {
+ if target.is_dir() {
+ std::os::windows::fs::symlink_dir(&target, &dest_path)?;
+ } else {
+ std::os::windows::fs::symlink_file(&target, &dest_path)?;
+ }
+ }
+ } else {
+ std::fs::copy(entry.path(), &dest_path)?;
+ }
+ }
+ Ok(())
+}
+
+/// Perform rollback: restore the backed-up app bundle and relaunch.
+/// Returns an error string if something goes wrong.
+pub fn perform_rollback() -> Result<(), String> {
+ let dir = rollback_dir().ok_or("cannot determine rollback directory")?;
+ let version = rollback_version().ok_or("no previous version available")?;
+
+ #[cfg(target_os = "macos")]
+ {
+ let backup = dir.join("screenpipe.app");
+ if !backup.exists() {
+ return Err("rollback backup not found".into());
+ }
+ // Resolve current .app location
+ let exe = std::env::current_exe().map_err(|e| format!("cannot resolve exe: {}", e))?;
+ let current_app = exe.parent()
+ .and_then(|p| p.parent())
+ .and_then(|p| p.parent())
+ .ok_or("cannot derive .app from exe")?
+ .to_path_buf();
+
+ info!("rollback: restoring v{} from {:?} -> {:?}", version, backup, current_app);
+
+ // We can't replace ourselves while running. Spawn a helper script that:
+ // 1. Waits for us to quit
+ // 2. Replaces the .app bundle
+ // 3. Relaunches
+ let script = format!(
+ r#"#!/bin/bash
+sleep 2
+rm -rf "{current_app}"
+cp -R "{backup}" "{current_app}"
+open "{current_app}"
+rm -f /tmp/screenpipe-rollback.sh
+"#,
+ current_app = current_app.display(),
+ backup = backup.display(),
+ );
+ let script_path = "/tmp/screenpipe-rollback.sh";
+ std::fs::write(script_path, &script).map_err(|e| format!("failed to write rollback script: {}", e))?;
+ std::fs::set_permissions(script_path, std::os::unix::fs::PermissionsExt::from_mode(0o755))
+ .map_err(|e| format!("failed to chmod rollback script: {}", e))?;
+
+ // Launch the script detached
+ std::process::Command::new("/bin/bash")
+ .arg(script_path)
+ .stdin(std::process::Stdio::null())
+ .stdout(std::process::Stdio::null())
+ .stderr(std::process::Stdio::null())
+ .spawn()
+ .map_err(|e| format!("failed to spawn rollback script: {}", e))?;
+
+ info!("rollback: script spawned, app will quit now");
+ Ok(())
+ }
+
+ #[cfg(target_os = "windows")]
+ {
+ let backup = dir.join("app");
+ if !backup.exists() {
+ return Err("rollback backup not found".into());
+ }
+ let exe = std::env::current_exe().map_err(|e| format!("cannot resolve exe: {}", e))?;
+ let install_dir = exe.parent().ok_or("cannot derive install dir")?.to_path_buf();
+ let exe_name = exe.file_name().ok_or("cannot get exe name")?.to_string_lossy().to_string();
+
+ info!("rollback: restoring v{} from {:?} -> {:?}", version, backup, install_dir);
+
+ // PowerShell script to replace files after process exits
+ let script = format!(
+ r#"Start-Sleep -Seconds 2
+Remove-Item -Recurse -Force "{install_dir}\*"
+Copy-Item -Recurse -Force "{backup}\*" "{install_dir}\"
+Start-Process "{install_dir}\{exe_name}"
+"#,
+ install_dir = install_dir.display(),
+ backup = backup.display(),
+ exe_name = exe_name,
+ );
+ let script_path = std::env::temp_dir().join("screenpipe-rollback.ps1");
+ std::fs::write(&script_path, &script).map_err(|e| format!("failed to write rollback script: {}", e))?;
+
+ std::process::Command::new("powershell")
+ .args(["-ExecutionPolicy", "Bypass", "-File"])
+ .arg(&script_path)
+ .stdin(std::process::Stdio::null())
+ .stdout(std::process::Stdio::null())
+ .stderr(std::process::Stdio::null())
+ .spawn()
+ .map_err(|e| format!("failed to spawn rollback script: {}", e))?;
+
+ info!("rollback: script spawned, app will quit now");
+ Ok(())
+ }
+
+ #[cfg(target_os = "linux")]
+ {
+ // Find the backed-up AppImage
+ let entries = std::fs::read_dir(&dir).map_err(|e| format!("cannot read rollback dir: {}", e))?;
+ let appimage_backup = entries
+ .filter_map(|e| e.ok())
+ .find(|e| e.path().extension().map_or(false, |ext| ext == "AppImage"))
+ .map(|e| e.path())
+ .ok_or("no AppImage backup found")?;
+
+ let current_appimage = std::env::var("APPIMAGE").map_err(|_| "not running as AppImage")?;
+
+ info!("rollback: restoring v{} from {:?} -> {:?}", version, appimage_backup, current_appimage);
+
+ let script = format!(
+ r#"#!/bin/bash
+sleep 2
+cp -f "{backup}" "{current}"
+chmod +x "{current}"
+"{current}" &
+rm -f /tmp/screenpipe-rollback.sh
+"#,
+ backup = appimage_backup.display(),
+ current = current_appimage,
+ );
+ let script_path = "/tmp/screenpipe-rollback.sh";
+ std::fs::write(script_path, &script).map_err(|e| format!("failed to write rollback script: {}", e))?;
+ #[cfg(unix)]
+ std::fs::set_permissions(script_path, std::os::unix::fs::PermissionsExt::from_mode(0o755))
+ .map_err(|e| format!("failed to chmod rollback script: {}", e))?;
+
+ std::process::Command::new("/bin/bash")
+ .arg(script_path)
+ .stdin(std::process::Stdio::null())
+ .stdout(std::process::Stdio::null())
+ .stderr(std::process::Stdio::null())
+ .spawn()
+ .map_err(|e| format!("failed to spawn rollback script: {}", e))?;
+
+ info!("rollback: script spawned, app will quit now");
+ Ok(())
+ }
+}
+
/// Check if this is a source/community build (not an official release)
/// Official releases are built with --features official-build in GitHub Actions
pub fn is_source_build(_app: &tauri::AppHandle) -> bool {
@@ -119,6 +436,8 @@ impl UpdatesManager {
#[cfg(not(target_os = "windows"))]
{
+ // Back up current app bundle before replacing it
+ backup_current_app();
update.download_and_install(|_, _| {}, || {}).await?;
*self.update_installed.lock().await = true;
self.update_menu_item.set_enabled(true)?;
@@ -209,6 +528,8 @@ impl UpdatesManager {
error!("Failed to stop recording: {}", err);
}
+ // Back up current app before replacing it
+ backup_current_app();
update.download_and_install(|_, _| {}, || {}).await?;
*self.update_installed.lock().await = true;