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

check for updates

Ezra Ellettedc4c5dce40f8
diff --git a/screenpipe-app-tauri/app/page.tsx b/screenpipe-app-tauri/app/page.tsx
index a8abaee0c..8daf26885 100644
--- a/screenpipe-app-tauri/app/page.tsx
+++ b/screenpipe-app-tauri/app/page.tsx
@@ -29,9 +29,9 @@ export default function Home() {
const posthog = usePostHog();
const { toast } = useToast();
- useEffect(() => {
- checkForAppUpdates({ toast });
- }, [toast]);
+ // useEffect(() => {
+ // checkForAppUpdates({ toast });
+ // }, [toast]);
useEffect(() => {
if (settings.userId) {
diff --git a/screenpipe-app-tauri/src-tauri/Cargo.toml b/screenpipe-app-tauri/src-tauri/Cargo.toml
index 766c56aa9..f67b2ef05 100644
--- a/screenpipe-app-tauri/src-tauri/Cargo.toml
+++ b/screenpipe-app-tauri/src-tauri/Cargo.toml
@@ -15,7 +15,13 @@ rust-version = "1.75"
tauri-build = { version = "2.0.0-rc.10", features = [] }
[dependencies]
-tauri = { version = "2.0.0-rc.10", features = [ "macos-private-api", "tray-icon", "devtools", "image-png", "image-ico"] }
+tauri = { version = "2.0.0-rc.10", features = [
+ "macos-private-api",
+ "tray-icon",
+ "devtools",
+ "image-png",
+ "image-ico",
+] }
tauri-utils = { version = "=2.0.0-rc.10", features = [] }
serde_json = "1.0"
@@ -60,7 +66,7 @@ sysinfo = "0.29.0"
fix-path-env = { git = "https://github.com/tauri-apps/fix-path-env-rs" }
# server
-axum = "0.6.0" # or your current version
+axum = "0.6.0" # or your current version
serde = "1.0.160"
@@ -93,13 +99,13 @@ tauri-plugin-cli = "2.0.0-alpha.2"
[target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\"))".dependencies]
tauri-plugin-single-instance = "2.0.0-rc.1"
-# tauri-plugin-updater = "2.0.0-alpha.2"
+tauri-plugin-updater = "2.0.0-alpha.2"
[features]
# cuda = ["screenpipe-server/cuda", "screenpipe-audio/cuda"]
# metal = ["screenpipe-server/metal", "screenpipe-audio/metal"]
cudart = []
-metal = [] # unused
+metal = [] # unused
mkl = []
default = ["custom-protocol"]
@@ -110,7 +116,7 @@ default = ["custom-protocol"]
# rocm = []
# DO NOT REMOVE!!
-custom-protocol = [ "tauri/custom-protocol" ]
+custom-protocol = ["tauri/custom-protocol"]
[package.metadata.cargo-machete]
diff --git a/screenpipe-app-tauri/src-tauri/icons/updates-black.png b/screenpipe-app-tauri/src-tauri/icons/updates-black.png
new file mode 100644
index 000000000..a34989d1a
Binary files /dev/null and b/screenpipe-app-tauri/src-tauri/icons/updates-black.png differ
diff --git a/screenpipe-app-tauri/src-tauri/icons/updates-white.png b/screenpipe-app-tauri/src-tauri/icons/updates-white.png
new file mode 100644
index 000000000..cdff796f2
Binary files /dev/null and b/screenpipe-app-tauri/src-tauri/icons/updates-white.png differ
diff --git a/screenpipe-app-tauri/src-tauri/src/commands.rs b/screenpipe-app-tauri/src-tauri/src/commands.rs
index 08d0bee4d..d2564dd8d 100644
--- a/screenpipe-app-tauri/src-tauri/src/commands.rs
+++ b/screenpipe-app-tauri/src-tauri/src/commands.rs
@@ -99,4 +99,3 @@ pub async fn reset_all_pipes() -> Result<(), String> {
Ok(())
}
-
diff --git a/screenpipe-app-tauri/src-tauri/src/main.rs b/screenpipe-app-tauri/src-tauri/src/main.rs
index a978308b2..75ea4fd26 100755
--- a/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -3,19 +3,19 @@
use commands::load_pipe_config;
use commands::save_pipe_config;
-use sidecar::SidecarManager;
-use tauri::Config;
-use tokio::sync::mpsc;
use serde_json::Value;
+use sidecar::SidecarManager;
use std::env;
use std::fs;
use std::fs::File;
+use std::future::IntoFuture;
use std::path::PathBuf;
use std::sync::Arc;
+use tauri::Config;
use tauri::Manager;
use tauri::Wry;
use tauri::{
- menu::{MenuBuilder, MenuItemBuilder},
+ menu::{MenuBuilder, MenuItemBuilder, PredefinedMenuItem},
tray::{MouseButton, MouseButtonState},
};
use tauri_plugin_autostart::MacosLauncher;
@@ -23,25 +23,29 @@ use tauri_plugin_autostart::ManagerExt;
#[allow(unused_imports)]
use tauri_plugin_shell::process::CommandEvent;
use tauri_plugin_store::{with_store, StoreCollection};
+use tokio::sync::mpsc;
use tokio::sync::Mutex;
use tracing::{debug, error, info};
use tracing_appender::rolling::{RollingFileAppender, Rotation};
use tracing_subscriber::prelude::*;
use tracing_subscriber::EnvFilter;
+use updates::start_update_check;
use uuid::Uuid;
mod analytics;
use crate::analytics::start_analytics;
mod commands;
-mod sidecar;
mod server;
+mod sidecar;
+// mod system_tray;
+mod updates;
pub use commands::open_screen_capture_preferences;
-pub use commands::reset_screen_permissions;
pub use commands::reset_all_pipes;
+pub use commands::reset_screen_permissions;
+pub use server::spawn_server;
pub use sidecar::kill_all_sreenpipes;
pub use sidecar::spawn_screenpipe;
-pub use server::spawn_server;
pub struct SidecarState(Arc<tokio::sync::Mutex<Option<SidecarManager>>>);
@@ -62,7 +66,7 @@ fn show_main_window(app_handle: &tauri::AppHandle) {
let _ = tauri::WebviewWindowBuilder::new(
app_handle,
"main",
- tauri::WebviewUrl::App("index.html".into())
+ tauri::WebviewUrl::App("index.html".into()),
)
.title("Screenpipe")
.build();
@@ -77,11 +81,11 @@ async fn main() {
let app = tauri::Builder::default().on_window_event(|window, event| match event {
tauri::WindowEvent::CloseRequested { api, .. } => {
- window.hide().unwrap();
- api.prevent_close();
+ window.hide().unwrap();
+ api.prevent_close();
}
_ => {}
- })
+ })
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(tauri_plugin_dialog::init())
@@ -103,6 +107,7 @@ async fn main() {
.set_focus()
.expect("Can't focus window!");
}))
+ .plugin(tauri_plugin_updater::Builder::new().build())
.manage(sidecar_state)
.invoke_handler(tauri::generate_handler![
spawn_screenpipe,
@@ -172,7 +177,6 @@ async fn main() {
autostart_manager.is_enabled().unwrap()
);
-
info!("Local data directory: {}", base_dir.display());
// PostHog analytics setup
@@ -184,12 +188,17 @@ async fn main() {
let _ = File::create(path.clone()).unwrap();
}
+ // Set up update check
+ let update_manager = start_update_check(app_handle, 1)?;
+
// Tray setup
if let Some(main_tray) = app.tray_by_id("screenpipe_main") {
let show = MenuItemBuilder::with_id("show", "Show Screenpipe").build(app)?;
+ let menu_divider = PredefinedMenuItem::separator(app)?;
let quit = MenuItemBuilder::with_id("quit", "Quit Screenpipe").build(app)?;
- let menu = MenuBuilder::new(app).items(&[&show, &quit]).build()?;
+ let menu = MenuBuilder::new(app).items(&[&show, update_manager.update_now_menu_item_ref(), &menu_divider, &quit]).build()?;
let _ = main_tray.set_menu(Some(menu));
+
main_tray.on_menu_event(move |app_handle, event| match event.id().as_ref() {
"show" => {
show_main_window(&app_handle);
@@ -197,6 +206,9 @@ async fn main() {
"quit" => {
println!("quit clicked");
app_handle.exit(0);
+ },
+ "update_now" => {
+ update_manager.update_screenpipe();
}
_ => (),
});
@@ -220,6 +232,8 @@ async fn main() {
});
}
+
+
// Store setup and analytics initialization
let stores = app.state::<StoreCollection<Wry>>();
let _ = with_store(app.handle().clone(), stores.clone(), path.clone(), |store| {
@@ -324,7 +338,7 @@ async fn main() {
}
tauri::RunEvent::ExitRequested { .. } => {
debug!("ExitRequested event");
-
+
// Add this to shut down the server
if let Some(server_shutdown_tx) = app_handle.try_state::<mpsc::Sender<()>>() {
let _ = server_shutdown_tx.send(());
diff --git a/screenpipe-app-tauri/src-tauri/src/updates.rs b/screenpipe-app-tauri/src-tauri/src/updates.rs
new file mode 100644
index 000000000..86a51833d
--- /dev/null
+++ b/screenpipe-app-tauri/src-tauri/src/updates.rs
@@ -0,0 +1,106 @@
+use anyhow::Error;
+use log::{error, info};
+use std::sync::Arc;
+use std::time::Duration;
+use tauri::menu::{MenuItem, MenuItemBuilder};
+use tauri::Wry;
+use tauri_plugin_updater::UpdaterExt;
+use tokio::sync::Mutex;
+use tokio::time::interval;
+pub struct UpdatesManager {
+ interval: Duration,
+ update_available: Arc<Mutex<bool>>,
+ app: tauri::AppHandle,
+ update_menu_item: MenuItem<Wry>,
+ update_installed: Arc<Mutex<bool>>,
+}
+
+impl UpdatesManager {
+ pub fn new(app: &tauri::AppHandle, interval_hours: u64) -> Result<Self, Error> {
+ Ok(Self {
+ interval: Duration::from_secs(interval_hours * 3600),
+ update_available: Arc::new(Mutex::new(false)),
+ update_installed: Arc::new(Mutex::new(false)),
+ app: app.clone(),
+ update_menu_item: MenuItemBuilder::with_id("update_now", "Screenpipe is up to date")
+ .enabled(false)
+ .build(app)?,
+ })
+ }
+
+ pub async fn check_for_updates(&self) -> Result<bool, Box<dyn std::error::Error>> {
+ if let Some(update) = self.app.updater()?.check().await? {
+ *self.update_available.lock().await = true;
+
+ self.update_menu_item
+ .set_text("Downloading Latest Version of Screenpipe")?;
+
+ if let Some(tray) = self.app.tray_by_id("screenpipe_main") {
+ if let Ok(image) = tauri::image::Image::from_path("icons/updates-white.png") {
+ if let Err(err) = tray.set_icon(Some(image)) {
+ error!("Problem setting icon: {}", err);
+ }
+ }
+ }
+
+ update.download_and_install(|_, _| {}, || {}).await?;
+
+ *self.update_installed.lock().await = true;
+ self.update_menu_item.set_enabled(true)?;
+ self.update_menu_item.set_text("Update Now")?;
+
+ return Result::Ok(true);
+ }
+
+ Result::Ok(false)
+ }
+
+ pub fn update_now_menu_item_ref(&self) -> &MenuItem<Wry> {
+ &self.update_menu_item
+ }
+
+ pub fn update_screenpipe(&self) -> Option<Error> {
+ self.app.restart();
+ }
+
+ pub async fn start_periodic_event(&self) {
+ let mut interval = interval(self.interval);
+
+ loop {
+ interval.tick().await;
+ if !*self.update_available.lock().await {
+ if let Err(e) = self.check_for_updates().await {
+ error!("Failed to check for updates: {}", e);
+ }
+ }
+ }
+ }
+}
+
+pub fn start_update_check(
+ app: &tauri::AppHandle,
+ interval_hours: u64,
+) -> Result<Arc<UpdatesManager>, Box<dyn std::error::Error>> {
+ let updates_manager = Arc::new(UpdatesManager::new(app, interval_hours)?);
+
+ // Send initial event at boot
+ tokio::spawn({
+ let updates_manager = updates_manager.clone();
+ async move {
+ if let Err(e) = updates_manager.check_for_updates().await {
+ error!("Failed to check for updates: {}", e);
+ }
+ info!("Update check started");
+ }
+ });
+
+ // Start periodic events
+ tokio::spawn({
+ let updates_manager = updates_manager.clone();
+ async move {
+ updates_manager.start_periodic_event().await;
+ }
+ });
+
+ Ok(updates_manager)
+}
diff --git a/screenpipe-app-tauri/src-tauri/tauri.conf.json b/screenpipe-app-tauri/src-tauri/tauri.conf.json
index 6effe87eb..2346010ad 100644
--- a/screenpipe-app-tauri/src-tauri/tauri.conf.json
+++ b/screenpipe-app-tauri/src-tauri/tauri.conf.json
@@ -11,12 +11,7 @@
"active": true,
"category": "DeveloperTool",
"copyright": "",
- "targets": [
- "app",
- "dmg",
- "appimage",
- "nsis"
- ],
+ "targets": ["app", "dmg", "appimage", "nsis"],
"externalBin": [],
"icon": [
"icons/32x32.png",
@@ -26,37 +21,21 @@
"icons/512x512.png",
"icons/1024x1024.png",
"icons/icon.icns",
- "icons/icon.ico"
+ "icons/icon.ico",
+ "icons/updates-white.png",
+ "icons/updates-black.png"
],
"longDescription": "",
- "resources": [
- "assets/*"
- ],
+ "resources": ["assets/*"],
"shortDescription": "",
"fileAssociations": [
{
"description": "Video files",
- "ext": [
- "mp4",
- "mkv",
- "avi",
- "mov",
- "wmv",
- "webm"
- ]
+ "ext": ["mp4", "mkv", "avi", "mov", "wmv", "webm"]
},
{
"description": "Audio files",
- "ext": [
- "mp3",
- "wav",
- "aac",
- "flac",
- "oga",
- "ogg",
- "opic",
- "opus"
- ]
+ "ext": ["mp3", "wav", "aac", "flac", "oga", "ogg", "opic", "opus"]
}
]
},
@@ -107,4 +86,4 @@
},
"macOSPrivateApi": true
}
-}
\ No newline at end of file
+}