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: persist power mode preference across app restarts

Louis Beaumontd81ea65c1e47
diff --git a/apps/screenpipe-app-tauri/components/settings/battery-saver-section.tsx b/apps/screenpipe-app-tauri/components/settings/battery-saver-section.tsx
index b821a8fb7..7670dbaf4 100644
--- a/apps/screenpipe-app-tauri/components/settings/battery-saver-section.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/battery-saver-section.tsx
@@ -6,6 +6,7 @@
import React, { useEffect, useState, useCallback } from "react";
import { Battery, BatteryCharging, BatteryLow, Zap, Leaf, Gauge } from "lucide-react";
import { cn } from "@/lib/utils";
+import { useSettings } from "@/lib/hooks/use-settings";
interface PowerState {
battery_pct: number | null;
@@ -41,6 +42,7 @@ const PROFILE_INFO = {
} as const;
export function BatterySaverSection() {
+ const { updateSettings } = useSettings();
const [status, setStatus] = useState<PowerStatus | null>(null);
const [loading, setLoading] = useState(true);
const [updating, setUpdating] = useState(false);
@@ -77,6 +79,8 @@ export function BatterySaverSection() {
if (res.ok) {
const data: PowerStatus = await res.json();
setStatus(data);
+ // Persist to settings store so it survives app restarts
+ await updateSettings({ powerMode: mode });
}
} catch {
// ignore
diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx b/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx
index 3fe3bc9c1..81c698688 100644
--- a/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx
+++ b/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx
@@ -137,6 +137,8 @@ export type Settings = SettingsStore & {
pipeSuggestionsEnabled?: boolean;
/** Hours between pipe suggestion notifications (default: 24) */
pipeSuggestionFrequencyHours?: number;
+ /** User's power mode preference — persisted so it survives app restarts */
+ powerMode?: "auto" | "performance" | "battery_saver";
}
export function getEffectiveFilters(settings: Settings) {
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/embedded_server.rs b/apps/screenpipe-app-tauri/src-tauri/src/embedded_server.rs
index 41f804c72..db5958249 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/embedded_server.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/embedded_server.rs
@@ -18,7 +18,7 @@ use screenpipe_engine::{
analytics,
hot_frame_cache::HotFrameCache,
server::bind_listener,
- start_meeting_watcher, start_power_manager, start_sleep_monitor, start_ui_recording,
+ start_meeting_watcher, start_power_manager_with_pref, start_sleep_monitor, start_ui_recording,
vision_manager::{start_monitor_watcher, stop_monitor_watcher, VisionManager},
RecordingConfig, ResourceMonitor, SCServer,
};
@@ -261,8 +261,16 @@ pub async fn start_embedded_server(
// Create shared pipeline metrics (used by recording + health endpoint + PostHog)
let vision_metrics = Arc::new(screenpipe_screen::PipelineMetrics::new());
- // Start power manager — polls battery/thermal state and broadcasts profile changes
- let power_manager = start_power_manager();
+ // Start power manager — polls battery/thermal state and broadcasts profile changes.
+ // Restore user's persisted power mode preference so it survives app restarts.
+ let initial_power_pref = config
+ .power_mode
+ .as_deref()
+ .and_then(|s| serde_json::from_value::<screenpipe_engine::power::PowerMode>(
+ serde_json::Value::String(s.to_string()),
+ ).ok())
+ .unwrap_or_default();
+ let power_manager = start_power_manager_with_pref(initial_power_pref);
// Capture trigger sender — set by VisionManager when vision is enabled.
// Passed to start_ui_recording so UI events (clicks, app switches) trigger captures.
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/store.rs b/apps/screenpipe-app-tauri/src-tauri/src/store.rs
index 94f78b1cb..37f0a8826 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/store.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/store.rs
@@ -749,6 +749,11 @@ impl SettingsStore {
.get("batchMaxDurationSecs")
.and_then(|v| v.as_u64())
.filter(|&v| v > 0),
+ power_mode: self
+ .extra
+ .get("powerMode")
+ .and_then(|v| v.as_str())
+ .map(|s| s.to_string()),
}
}
diff --git a/crates/screenpipe-engine/src/cli/mod.rs b/crates/screenpipe-engine/src/cli/mod.rs
index f3fbd9b8e..3c564c172 100644
--- a/crates/screenpipe-engine/src/cli/mod.rs
+++ b/crates/screenpipe-engine/src/cli/mod.rs
@@ -361,6 +361,7 @@ impl RecordArgs {
vocabulary: vec![],
ignore_incognito_windows: true,
batch_max_duration_secs: None,
+ power_mode: None,
}
}
}
diff --git a/crates/screenpipe-engine/src/lib.rs b/crates/screenpipe-engine/src/lib.rs
index 1ad8e5f1b..31e581275 100644
--- a/crates/screenpipe-engine/src/lib.rs
+++ b/crates/screenpipe-engine/src/lib.rs
@@ -47,7 +47,7 @@ pub use calendar_speaker_id::start_speaker_identification;
pub use cloud_search::{CloudSearchClient, CloudSearchMetadata, CloudStatus};
pub use meeting_persister::start_meeting_persister;
pub use meeting_watcher::start_meeting_watcher;
-pub use power::{start_power_manager, PowerManagerHandle};
+pub use power::{start_power_manager, start_power_manager_with_pref, PowerManagerHandle};
pub use resource_monitor::{ResourceMonitor, RestartSignal};
pub use screenpipe_core::Language;
pub use server::health_check_handler as health_check;
diff --git a/crates/screenpipe-engine/src/power/manager.rs b/crates/screenpipe-engine/src/power/manager.rs
index a795c1243..18a9ebb33 100644
--- a/crates/screenpipe-engine/src/power/manager.rs
+++ b/crates/screenpipe-engine/src/power/manager.rs
@@ -81,10 +81,18 @@ pub struct PowerStatus {
/// Returns a handle that subsystems use to subscribe to profile changes.
/// The background task runs until the returned handle is dropped.
pub fn start_power_manager() -> Arc<PowerManagerHandle> {
+ start_power_manager_with_pref(PowerMode::default())
+}
+
+/// Start the power manager with a persisted user preference.
+///
+/// Use this when restoring the user's saved power mode from settings
+/// so it survives app restarts.
+pub fn start_power_manager_with_pref(initial_pref: PowerMode) -> Arc<PowerManagerHandle> {
let initial_profile = PowerProfile::performance(); // assume AC until first poll
let (profile_tx, profile_rx) = watch::channel(initial_profile);
let state = Arc::new(RwLock::new(PowerState::default()));
- let user_pref = Arc::new(RwLock::new(PowerMode::default()));
+ let user_pref = Arc::new(RwLock::new(initial_pref));
let handle = Arc::new(PowerManagerHandle {
profile_tx,
diff --git a/crates/screenpipe-engine/src/power/mod.rs b/crates/screenpipe-engine/src/power/mod.rs
index 55e25e396..11cfafa19 100644
--- a/crates/screenpipe-engine/src/power/mod.rs
+++ b/crates/screenpipe-engine/src/power/mod.rs
@@ -21,6 +21,6 @@ pub mod monitor;
pub mod profile;
// Re-export the public API at the module level
-pub use manager::{start_power_manager, PowerManagerHandle, PowerStatus};
+pub use manager::{start_power_manager, start_power_manager_with_pref, PowerManagerHandle, PowerStatus};
pub use monitor::{PowerState, ThermalState};
pub use profile::{PowerMode, PowerProfile, ProfileName};
diff --git a/crates/screenpipe-engine/src/recording_config.rs b/crates/screenpipe-engine/src/recording_config.rs
index 02c577107..6a923ff4a 100644
--- a/crates/screenpipe-engine/src/recording_config.rs
+++ b/crates/screenpipe-engine/src/recording_config.rs
@@ -82,6 +82,10 @@ pub struct RecordingConfig {
/// When set, overrides the engine-aware default (Deepgram=3600s, Whisper/OpenAI=600s).
/// None = use engine-aware defaults.
pub batch_max_duration_secs: Option<u64>,
+
+ /// Persisted power mode preference ("auto", "performance", "battery_saver").
+ /// Restored from settings on startup so the user's choice survives app restarts.
+ pub power_mode: Option<String>,
}
impl RecordingConfig {