Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat(desktop): allow users to add new apps automatically (#4356)
Elijah Potter35096b011f8c
diff --git a/harper-desktop/src-tauri/src/commands.rs b/harper-desktop/src-tauri/src/commands.rsindex 705c03255..fe6dfcb38 100644--- a/harper-desktop/src-tauri/src/commands.rs+++ b/harper-desktop/src-tauri/src/commands.rs@@ -35,6 +35,8 @@ pub fn application_message_handler<R: Runtime>() -> impl Fn(Invoke<R>) -> bool {ignore_lint,add_to_dictionary,get_integrations,+ get_auto_enable_new_apps,+ set_auto_enable_new_apps,add_integration,remove_integration,set_integration_enabled,@@ -270,6 +272,26 @@ async fn get_integrations(.collect())}+#[tauri::command]+async fn get_auto_enable_new_apps(config: State<'_, Arc<Mutex<Config>>>) -> Result<bool, String> {+ Ok(config.lock().await.auto_enable_new_apps)+}++#[tauri::command]+async fn set_auto_enable_new_apps(+ auto_enable_new_apps: bool,+ config: State<'_, Arc<Mutex<Config>>>,+) -> Result<(), String> {+ let mut config = config.lock().await;+ let previous = config.auto_enable_new_apps;+ config.auto_enable_new_apps = auto_enable_new_apps;+ if let Err(error) = config.save_to_system().await {+ config.auto_enable_new_apps = previous;+ return Err(error.to_string());+ }+ Ok(())+}+#[tauri::command]async fn add_integration(bundle_id: String,diff --git a/harper-desktop/src-tauri/src/communication/client.rs b/harper-desktop/src-tauri/src/communication/client.rsindex f98818ed4..4e418c5d7 100644--- a/harper-desktop/src-tauri/src/communication/client.rs+++ b/harper-desktop/src-tauri/src/communication/client.rs@@ -95,6 +95,31 @@ where}}+ pub async fn get_auto_enable_new_apps(&mut self) -> Result<bool, ProtocolError> {+ match self.send_request(Request::GetAutoEnableNewApps).await? {+ Response::GetAutoEnableNewApps { enabled } => Ok(enabled),+ _ => Err(ProtocolError::UnexpectedResponse {+ expected: "GetAutoEnableNewApps",+ }),+ }+ }++ /// Checks the parent's current app policy, registering and persisting an unknown app if allowed.+ /// Explicitly disabled integrations are preserved even if the caller's snapshot is stale.+ pub async fn resolve_integration(&mut self, bundle_id: &str) -> Result<bool, ProtocolError> {+ match self+ .send_request(Request::ResolveIntegration {+ bundle_id: bundle_id.to_owned(),+ })+ .await?+ {+ Response::ResolveIntegration { enabled } => Ok(enabled),+ _ => Err(ProtocolError::UnexpectedResponse {+ expected: "ResolveIntegration",+ }),+ }+ }+pub async fn ignore_lint(&mut self, ignored_lints: &IgnoredLints) -> Result<(), ProtocolError> {self.send_ack_request(Request::IgnoreLint {ignored_lints: ignored_lints.clone(),diff --git a/harper-desktop/src-tauri/src/communication/message.rs b/harper-desktop/src-tauri/src/communication/message.rsindex 590efd974..7dce346a7 100644--- a/harper-desktop/src-tauri/src/communication/message.rs+++ b/harper-desktop/src-tauri/src/communication/message.rs@@ -11,6 +11,8 @@ pub enum Request {GetDebounceMs,GetIgnoredLints,GetIntegrations,+ GetAutoEnableNewApps,+ ResolveIntegration { bundle_id: String },SetLintConfig { config: FlatConfig },IgnoreLint { ignored_lints: IgnoredLints },AddToDictionary { word: String },@@ -28,6 +30,8 @@ pub enum Response {GetDebounceMs { debounce_ms: u64 },GetIgnoredLints { ignored_lints: IgnoredLints },GetIntegrations { integrations: Vec<Integration> },+ GetAutoEnableNewApps { enabled: bool },+ ResolveIntegration { enabled: bool },Ack,}diff --git a/harper-desktop/src-tauri/src/communication/server.rs b/harper-desktop/src-tauri/src/communication/server.rsindex 5041146de..ad974870b 100644--- a/harper-desktop/src-tauri/src/communication/server.rs+++ b/harper-desktop/src-tauri/src/communication/server.rs@@ -68,6 +68,22 @@ whereRequest::GetIntegrations => Response::GetIntegrations {integrations: self.config.lock().await.integrations.clone(),},+ Request::GetAutoEnableNewApps => Response::GetAutoEnableNewApps {+ enabled: self.config.lock().await.auto_enable_new_apps,+ },+ Request::ResolveIntegration { bundle_id } => {+ let mut config = self.config.lock().await;+ let previous_len = config.integrations.len();+ let enabled = config.resolve_integration(bundle_id);+ if config.integrations.len() != previous_len+ && let Err(error) = config.save_to_system().await+ {+ config.remove_integration(bundle_id.trim());+ eprintln!("failed to save discovered integration: {error}");+ return Response::ResolveIntegration { enabled: false };+ }+ Response::ResolveIntegration { enabled }+ }Request::SetLintConfig { config } => {let mut stored_config = self.config.lock().await;stored_config.lint_config = config.clone();diff --git a/harper-desktop/src-tauri/src/config/integration.rs b/harper-desktop/src-tauri/src/config/integration.rsindex 653a7926f..290edf91e 100644--- a/harper-desktop/src-tauri/src/config/integration.rs+++ b/harper-desktop/src-tauri/src/config/integration.rs@@ -33,9 +33,4 @@ impl Integration {}).collect()}- pub fn is_integration_enabled_in(integrations: &[Self], bundle_id: &str) -> bool {- integrations- .iter()- .any(|integration| integration.bundle_id == bundle_id && integration.enabled)- }}diff --git a/harper-desktop/src-tauri/src/config/mod.rs b/harper-desktop/src-tauri/src/config/mod.rsindex c94733141..37fbae32c 100644--- a/harper-desktop/src-tauri/src/config/mod.rs+++ b/harper-desktop/src-tauri/src/config/mod.rs@@ -1,6 +1,7 @@mod error;mod integration;+use crate::{PlatformBroker, os_broker::OsBroker};pub use error::Error;use harper_core::{Dialect, IgnoredLints,@@ -19,6 +20,7 @@ pub struct Config {pub ignored_lints: IgnoredLints,pub lint_config: FlatConfig,pub integrations: Vec<Integration>,+ pub auto_enable_new_apps: bool,pub onboarding_completed: bool,pub debounce_ms: u64,pub auto_update: bool,@@ -34,6 +36,7 @@ impl Config {ignored_lints: IgnoredLints::new(),lint_config: FlatConfig::new_curated(),integrations: Integration::curated_integrations(),+ auto_enable_new_apps: false,onboarding_completed: false,debounce_ms: 0,auto_update: true,@@ -55,6 +58,29 @@ impl Config {.any(|integration| integration.bundle_id == bundle_id && integration.enabled)}+ /// Resolves an app's enabled state, registering unknown apps when automatic enablement is on.+ /// Existing disabled entries are never re-enabled; removed entries can be discovered again.+ /// Harper itself is excluded from discovery, but explicitly configured entries are respected.+ /// The caller is responsible for persisting any newly registered integration.+ pub fn resolve_integration(&mut self, bundle_id: &str) -> bool {+ let bundle_id = bundle_id.trim();+ if bundle_id.is_empty() {+ return false;+ }+ if let Some(integration) = self+ .integrations+ .iter()+ .find(|item| item.bundle_id == bundle_id)+ {+ return integration.enabled;+ }+ if !self.auto_enable_new_apps || PlatformBroker::is_harper_desktop(bundle_id) {+ return false;+ }+ self.add_integration(bundle_id.to_owned());+ true+ }+pub fn add_integration(&mut self, bundle_id: String) {let bundle_id = bundle_id.trim();if bundle_id.is_empty()@@ -163,6 +189,7 @@ impl Config {"ignored_lints": &self.ignored_lints,"lint_config": &self.lint_config,"integrations": &self.integrations,+ "auto_enable_new_apps": self.auto_enable_new_apps,"onboarding_completed": self.onboarding_completed,"debounce_ms": self.debounce_ms,"auto_update": self.auto_update,@@ -185,6 +212,8 @@ impl Config {lint_config: deserialize_field(object, "lint_config")?,integrations: deserialize_optional_field(object, "integrations")?.unwrap_or_else(Integration::curated_integrations),+ auto_enable_new_apps: deserialize_optional_field(object, "auto_enable_new_apps")?+ .unwrap_or(false),onboarding_completed: deserialize_optional_field(object, "onboarding_completed")?.unwrap_or(true),debounce_ms: deserialize_optional_field(object, "debounce_ms")?.unwrap_or(0),diff --git a/harper-desktop/src-tauri/src/lib.rs b/harper-desktop/src-tauri/src/lib.rsindex 7dbe3f3b2..d7371e4d6 100644--- a/harper-desktop/src-tauri/src/lib.rs+++ b/harper-desktop/src-tauri/src/lib.rs@@ -82,15 +82,17 @@ pub(crate) type PlatformBroker = os_broker::NoopBroker;////// The Tauri process stores its single broker as managed state, while the highlighter subprocess/// creates its own broker because it is a separate process.-fn platform_broker(integrations: Arc<StdMutex<Vec<Integration>>>) -> PlatformBroker {+fn platform_broker(+ is_integration_enabled: impl FnMut(&str) -> bool + Send + 'static,+) -> PlatformBroker {#[cfg(any(target_os = "macos", target_os = "windows"))]{- PlatformBroker::new(integrations)+ PlatformBroker::new(is_integration_enabled)}#[cfg(not(any(target_os = "macos", target_os = "windows")))]{- let _ = integrations;+ let _ = is_integration_enabled;PlatformBroker::default()}}@@ -161,8 +163,7 @@ pub fn run_tauri() {}};- let integrations = Arc::new(StdMutex::new(config.integrations.clone()));- let broker = platform_broker(integrations);+ let broker = platform_broker(|_| false);let highlighter_service_enabled = config.highlighter_service_enabled;let config = Arc::new(Mutex::new(config));@@ -231,8 +232,8 @@ pub fn run_tauri() {/// Run as a highlighter process./// Can configure whether to run standalone, or with a parent Tauri processpub fn run_highlighter(has_parent: bool) {- let client = Rc::new(RefCell::new(Client::current_process()));- let sync_runtime = Rc::new(+ let client = Arc::new(StdMutex::new(Client::current_process()));+ let sync_runtime = Arc::new(Builder::new_current_thread().enable_all().build()@@ -240,7 +241,10 @@ pub fn run_highlighter(has_parent: bool) {);let startup_config = if has_parent {- fetch_highlighter_config(&mut client.borrow_mut(), &sync_runtime)+ fetch_highlighter_config(+ &mut client.lock().expect("IPC client lock poisoned"),+ &sync_runtime,+ )} else {Ok(Config::default())};@@ -257,11 +261,33 @@ pub fn run_highlighter(has_parent: bool) {let ignored_lints = Rc::new(RefCell::new(startup_config.ignored_lints));let user_dictionary = Rc::new(RefCell::new(startup_config.mutable_dictionary));let dialect = Rc::new(RefCell::new(startup_config.dialect));- let integrations = Arc::new(StdMutex::new(startup_config.integrations));+ let integrations = Arc::new(StdMutex::new(IntegrationState {+ integrations: startup_config.integrations,+ auto_enable_new_apps: startup_config.auto_enable_new_apps,+ }));let debounce_ms = Rc::new(RefCell::new(startup_config.debounce_ms));let linter = Rc::new(RefCell::new(startup_linter));- let broker = platform_broker(integrations.clone());+ let integration_client = client.clone();+ let integration_runtime = sync_runtime.clone();+ let is_integration_enabled = integration_callback(integrations.clone(), move |bundle_id| {+ if !has_parent {+ return true;+ }+ match integration_runtime.block_on(+ integration_client+ .lock()+ .expect("IPC client lock poisoned")+ .resolve_integration(bundle_id),+ ) {+ Ok(enabled) => enabled,+ Err(error) => {+ eprintln!("failed to register integration: {error}");+ false+ }+ }+ });+ let broker = platform_broker(is_integration_enabled);let lint_ignored_lints = ignored_lints.clone();let lint_linter = linter.clone();@@ -324,9 +350,12 @@ pub fn run_highlighter(has_parent: bool) {}let snapshot = ignore_ignored_lints.borrow().clone();- if let Err(error) =- ignore_runtime.block_on(ignore_client.borrow_mut().ignore_lint(&snapshot))- {+ if let Err(error) = ignore_runtime.block_on(+ ignore_client+ .lock()+ .expect("IPC client lock poisoned")+ .ignore_lint(&snapshot),+ ) {eprintln!("failed to sync ignored lints: {error}");}};@@ -343,6 +372,7 @@ pub fn run_highlighter(has_parent: bool) {ignored_lints: IgnoredLints::new(),lint_config,integrations: Vec::new(),+ auto_enable_new_apps: false,onboarding_completed: false,debounce_ms: *dictionary_debounce_ms.borrow(),auto_update: true,@@ -351,16 +381,22 @@ pub fn run_highlighter(has_parent: bool) {};*dictionary_linter.borrow_mut() = config.create_linter();- if let Err(error) =- dictionary_runtime.block_on(dictionary_client.borrow_mut().add_to_dictionary(word))- {+ if let Err(error) = dictionary_runtime.block_on(+ dictionary_client+ .lock()+ .expect("IPC client lock poisoned")+ .add_to_dictionary(word),+ ) {eprintln!("failed to sync dictionary update: {error}");}};- let disable_rule = move |rule_name: &str| match disable_runtime- .block_on(disable_client.borrow_mut().disable_rule(rule_name))- {+ let disable_rule = move |rule_name: &str| match disable_runtime.block_on(+ disable_client+ .lock()+ .expect("IPC client lock poisoned")+ .disable_rule(rule_name),+ ) {Ok(config) => disable_linter.borrow_mut().config = config,Err(error) => eprintln!("failed to disable rule {rule_name}: {error}"),};@@ -370,7 +406,10 @@ pub fn run_highlighter(has_parent: bool) {return;}- match fetch_highlighter_config(&mut refresh_client.borrow_mut(), &refresh_runtime) {+ match fetch_highlighter_config(+ &mut refresh_client.lock().expect("IPC client lock poisoned"),+ &refresh_runtime,+ ) {Ok(config) => apply_highlighter_config(config,&refresh_ignored_lints,@@ -401,6 +440,46 @@ pub fn run_highlighter(has_parent: bool) {}}+/// Highlighter-local app policy snapshot, replaced on each config poll.+/// Also caches discovery decisions (including denials) until the next poll to avoid per-frame IPC.+struct IntegrationState {+ integrations: Vec<Integration>,+ auto_enable_new_apps: bool,+}++/// Builds the broker's policy callback. Known apps are checked locally; only unknown apps with+/// automatic enablement on reach `resolve`, which persists registration in the parent process.+/// Harper itself is excluded from discovery, but explicitly configured entries are respected.+/// Standalone callers can approve registration locally without IPC.+fn integration_callback(+ state: Arc<StdMutex<IntegrationState>>,+ mut resolve: impl FnMut(&str) -> bool + Send + 'static,+) -> impl FnMut(&str) -> bool + Send + 'static {+ move |bundle_id| {+ let bundle_id = bundle_id.trim();+ if bundle_id.is_empty() {+ return false;+ }+ let mut state = state.lock().expect("integration state lock poisoned");+ if let Some(integration) = state+ .integrations+ .iter()+ .find(|item| item.bundle_id == bundle_id)+ {+ return integration.enabled;+ }+ if !state.auto_enable_new_apps || PlatformBroker::is_harper_desktop(bundle_id) {+ return false;+ }+ let enabled = resolve(bundle_id);+ state.integrations.push(Integration {+ bundle_id: bundle_id.to_owned(),+ enabled,+ });+ enabled+ }+}+fn fetch_highlighter_config(client: &mut Client<Stdin, Stdout>,runtime: &Runtime,@@ -411,6 +490,7 @@ fn fetch_highlighter_config(let ignored_lints = client.get_ignored_lints().await?;let lint_config = client.get_lint_config().await?;let integrations = client.get_integrations().await?;+ let auto_enable_new_apps = client.get_auto_enable_new_apps().await?;let debounce_ms = client.get_debounce_ms().await?;Ok(Config {@@ -419,6 +499,7 @@ fn fetch_highlighter_config(ignored_lints,lint_config,integrations,+ auto_enable_new_apps,onboarding_completed: false,debounce_ms,auto_update: true,@@ -433,7 +514,7 @@ fn apply_highlighter_config(ignored_lints: &Rc<RefCell<IgnoredLints>>,user_dictionary: &Rc<RefCell<MutableDictionary>>,dialect: &Rc<RefCell<Dialect>>,- integrations: &Arc<StdMutex<Vec<Integration>>>,+ integrations: &Arc<StdMutex<IntegrationState>>,debounce_ms: &Rc<RefCell<u64>>,linter: &Rc<RefCell<LintGroup>>,) {@@ -442,7 +523,12 @@ fn apply_highlighter_config(*user_dictionary.borrow_mut() = config.mutable_dictionary;*dialect.borrow_mut() = config.dialect;match integrations.lock() {- Ok(mut integrations) => *integrations = config.integrations,+ Ok(mut integrations) => {+ *integrations = IntegrationState {+ integrations: config.integrations,+ auto_enable_new_apps: config.auto_enable_new_apps,+ }+ }Err(error) => eprintln!("failed to update integrations: {error}"),}*debounce_ms.borrow_mut() = config.debounce_ms;diff --git a/harper-desktop/src-tauri/src/mac_broker/mod.rs b/harper-desktop/src-tauri/src/mac_broker/mod.rsindex a2085f769..ba287e013 100644--- a/harper-desktop/src-tauri/src/mac_broker/mod.rs+++ b/harper-desktop/src-tauri/src/mac_broker/mod.rs@@ -29,11 +29,10 @@ use std::time::Duration;use std::{collections::{BTreeMap, HashMap},error::Error as StdError,- sync::{Arc, Mutex},+ sync::Mutex,time::Instant,};-use crate::config::Integration;use crate::os_broker::{AccessibilityPermissionStatus, AppSearchResult, OsBroker};use crate::rect::ActionableLint;@@ -52,6 +51,9 @@ use self::window_stability::{settled_window_state, window_frame_changed,};+/// Must match `identifier` in `tauri.conf.json`.+const BUNDLE_ID: &str = "com.elijahpotter.harper-desktop";+/// macOS implementation of the OS data the highlighter needs.////// `MacBroker` owns focus memory because clicking the overlay can make the highlighter process the@@ -61,17 +63,19 @@ pub struct MacBroker {/// Tauri requires a Send broker; retained AX handles must stay on their capturing thread./// The wrapper enforces that restriction for access and drop. Only the highlighter populates it.last_focused: Option<SendWrapper<FocusedTarget>>,- integrations: Arc<Mutex<Vec<Integration>>>,+ is_integration_enabled: Box<dyn FnMut(&str) -> bool + Send>,application_icon_cache: Mutex<HashMap<String, Vec<u8>>>,window_movement: Option<WindowMovementState>,accessibility_activation: Option<AccessibilityActivationState>,}impl MacBroker {- pub fn new(integrations: Arc<Mutex<Vec<Integration>>>) -> Self {+ /// Creates a broker with an app policy that may register newly encountered bundle IDs.+ /// The policy is called before reading the app's text and may change as settings are refreshed.+ pub fn new(is_integration_enabled: impl FnMut(&str) -> bool + Send + 'static) -> Self {Self {last_focused: None,- integrations,+ is_integration_enabled: Box::new(is_integration_enabled),application_icon_cache: Mutex::new(HashMap::new()),window_movement: None,accessibility_activation: None,@@ -278,12 +282,6 @@ impl MacBroker {}}-impl Default for MacBroker {- fn default() -> Self {- Self::new(Arc::new(Mutex::new(Integration::curated_integrations())))- }-}-impl Drop for MacBroker {fn drop(&mut self) {self.reset_accessibility_activation();@@ -293,6 +291,10 @@ impl Drop for MacBroker {pub(super) type LintCallback<'a> = dyn FnMut(&str) -> BTreeMap<String, Vec<Lint>> + 'a;impl OsBroker for MacBroker {+ fn is_harper_desktop(app_id: &str) -> bool {+ app_id == BUNDLE_ID+ }+fn get_boxes(&mut self, lint_text: &mut LintCallback) -> Option<Vec<ActionableLint>> {let focused_pid = match focused_window_pid::focused_window_pid() {Ok(pid) => pid,@@ -327,17 +329,7 @@ impl OsBroker for MacBroker {}};- let integration_enabled = match self.integrations.lock() {- Ok(integrations) => {- Integration::is_integration_enabled_in(&integrations, &bundle_identifier)- }- Err(error) => {- eprintln!("Unable to read integrations: {error}");- return None;- }- };-- if !integration_enabled {+ if !(self.is_integration_enabled)(&bundle_identifier) {self.window_movement = None;self.reset_accessibility_activation();return Some(Vec::new());diff --git a/harper-desktop/src-tauri/src/os_broker.rs b/harper-desktop/src-tauri/src/os_broker.rsindex 6e998e6a3..f868af4e0 100644--- a/harper-desktop/src-tauri/src/os_broker.rs+++ b/harper-desktop/src-tauri/src/os_broker.rs@@ -19,6 +19,18 @@ pub enum AccessibilityPermissionStatus {/// those APIs are platform-specific. This trait keeps the event loop and renderer independent from/// macOS accessibility and pointer APIs.pub trait OsBroker {+ /// Identifies Harper for automatic-discovery exclusion, not for manual integration policy.+ ///+ /// Uses the configured bundle ID on macOS and the current executable path on Windows.+ /// Unsupported platforms return `false`. No broker instance is needed; `Self: Sized` keeps+ /// the trait usable as `dyn OsBroker`.+ fn is_harper_desktop(_app_id: &str) -> bool+ where+ Self: Sized,+ {+ false+ }+/// Get the actionable lint boxes from the OS, provided a linting source.////// `None` means the accessibility read failed and the last successful result should be retained.diff --git a/harper-desktop/src-tauri/src/windows_broker/mod.rs b/harper-desktop/src-tauri/src/windows_broker/mod.rsindex 5a6751c58..52cbbc399 100644--- a/harper-desktop/src-tauri/src/windows_broker/mod.rs+++ b/harper-desktop/src-tauri/src/windows_broker/mod.rs@@ -1,6 +1,5 @@use crate::windows_broker::automation_service::AutomationService;use crate::{- config::Integration,os_broker::{AccessibilityPermissionStatus, AppSearchResult, OsBroker},rect::ActionableLint,};@@ -32,24 +31,26 @@ mod automation_service;pub struct WindowsBroker {service: Arc<Mutex<AutomationService>>,- integrations: Arc<Mutex<Vec<Integration>>>,+ is_integration_enabled: Box<dyn FnMut(&str) -> bool + Send>,}impl WindowsBroker {- pub fn new(integrations: Arc<Mutex<Vec<Integration>>>) -> Self {+ /// Creates a broker with an app policy that may register newly encountered executable paths.+ /// The policy is called before reading the app's text and may change as settings are refreshed.+ pub fn new(is_integration_enabled: impl FnMut(&str) -> bool + Send + 'static) -> Self {Self {service: Arc::new(Mutex::new(AutomationService::create_and_start())),- integrations,+ is_integration_enabled: Box::new(is_integration_enabled),}}- pub fn should_lint_focused_window(&self) -> Option<bool> {+ pub fn should_lint_focused_window(&mut self) -> Option<bool> {let mut service = self.service.lock().ok()?;let focused_window = service.resolve_focused_window()?;let path = get_window_path(focused_window).ok()?;- let integrations = self.integrations.lock().ok()?;+ drop(service);- if !Integration::is_integration_enabled_in(&integrations, &path.to_string_lossy()) {+ if !(self.is_integration_enabled)(&path.to_string_lossy()) {return Some(false);}@@ -66,6 +67,19 @@ impl WindowsBroker {}impl OsBroker for WindowsBroker {+ fn is_harper_desktop(app_id: &str) -> bool {+ let Ok(executable) = std::env::current_exe()+ .and_then(std::fs::canonicalize)+ .inspect_err(|error| eprintln!("failed to identify Harper executable: {error}"))+ else {+ return false;+ };+ std::fs::canonicalize(app_id).is_ok_and(|path| {+ path.to_string_lossy()+ .eq_ignore_ascii_case(&executable.to_string_lossy())+ })+ }+fn get_boxes(&mut self,lint_text: &mut dyn FnMut(&str) -> BTreeMap<String, Vec<Lint>>,diff --git a/harper-desktop/src/lib/client.ts b/harper-desktop/src/lib/client.tsindex 4df61c0eb..1613a6ad5 100644--- a/harper-desktop/src/lib/client.ts+++ b/harper-desktop/src/lib/client.ts@@ -156,6 +156,14 @@ export class Client {return await invoke<Integration[]>('get_integrations');}+ static async getAutoEnableNewApps(): Promise<boolean> {+ return await invoke<boolean>('get_auto_enable_new_apps');+ }++ static async setAutoEnableNewApps(autoEnableNewApps: boolean): Promise<void> {+ await invoke('set_auto_enable_new_apps', { autoEnableNewApps });+ }+static async addIntegration(bundleId: string): Promise<void> {await invoke('add_integration', { bundleId });}diff --git a/harper-desktop/src/lib/settings/pages/IntegrationsPage.svelte b/harper-desktop/src/lib/settings/pages/IntegrationsPage.svelteindex 81a98252b..f18d3e5a7 100644--- a/harper-desktop/src/lib/settings/pages/IntegrationsPage.svelte+++ b/harper-desktop/src/lib/settings/pages/IntegrationsPage.svelte@@ -1,5 +1,14 @@<script lang="ts">-import { Button, Checkbox, IconButton, Panel, SettingRow, Toggle, TrashIcon } from 'components';+import {+ Button,+ Checkbox,+ CheckIcon,+ IconButton,+ Panel,+ SettingRow,+ Toggle,+ TrashIcon,+} from 'components';import { onMount } from 'svelte';import { Client, type Integration } from '$lib/client';import AppIcon from '../components/AppIcon.svelte';@@ -14,15 +23,52 @@ let integrationApps: IntegrationRow[] = [];let integrationsError = '';let isIntegrationsLoading = true;let isIntegrationsSaving = false;+let autoEnableNewApps = false;+let isAutoEnableLoading = true;+let isAutoEnableSaving = false;+let autoEnableError = '';let appPickerOpen = false;let newBundleId = '';$: existingBundleIds = integrations.map((integration) => integration.bundle_id);onMount(() => {- void loadIntegrations();+ const refresh = () => {+ if (!isIntegrationsSaving) void loadIntegrations();+ if (!isAutoEnableSaving) void loadAutoEnableNewApps();+ };+ refresh();+ window.addEventListener('focus', refresh);+ return () => window.removeEventListener('focus', refresh);});+async function loadAutoEnableNewApps() {+ isAutoEnableLoading = true;+ autoEnableError = '';+ try {+ autoEnableNewApps = await Client.getAutoEnableNewApps();+ } catch (error) {+ autoEnableError = `Unable to load automatic app enablement: ${error}`;+ } finally {+ isAutoEnableLoading = false;+ }+}++async function setAutoEnableNewApps(enabled: boolean) {+ const previous = autoEnableNewApps;+ autoEnableNewApps = enabled;+ isAutoEnableSaving = true;+ autoEnableError = '';+ try {+ await Client.setAutoEnableNewApps(enabled);+ } catch (error) {+ autoEnableNewApps = previous;+ autoEnableError = `Unable to save automatic app enablement: ${error}`;+ } finally {+ isAutoEnableSaving = false;+ }+}+async function loadIntegrations() {isIntegrationsLoading = true;integrationsError = '';@@ -190,15 +236,25 @@ function closeAppPicker() {<div class="eyebrow">New apps</div><SettingRow top><strong>Enable new apps automatically</strong>- <p>When you launch a supported app for the first time, turn integration on by default.</p>+ <p>Automatically add and enable new apps when Harper encounters them. Disabled apps stay disabled; removed apps can be added again.</p><Checkboxslot="control"appearance="settings"- checked={false}- disabled- title="Not wired yet"- />+ checked={autoEnableNewApps}+ disabled={isAutoEnableLoading || isAutoEnableSaving}+ aria-label="Enable new apps automatically"+ on:click={() => setAutoEnableNewApps(!autoEnableNewApps)}+ >+ {#if autoEnableNewApps}<CheckIcon className="control-icon" />{/if}+ </Checkbox></SettingRow>+ {#if autoEnableError}+ <p class="result-summary" role="alert">{autoEnableError}</p>+ {:else if isAutoEnableLoading}+ <p class="result-summary">Loading automatic app enablement...</p>+ {:else if isAutoEnableSaving}+ <p class="result-summary">Saving automatic app enablement...</p>+ {/if}</div></section>