//! Folder monitor — watches a directory for new files and emits
//! `folder-monitor-new-files` with absolute paths to the renderer.
//!
//! Reflects the v1 `lib/folder-monitor.js` design: debounced notify events,
//! extension include/exclude filter, skip-duplicates against a seen-set,
//! optional recursive watch, initial scan on start.
use notify::{EventKind, RecursiveMode, Watcher};
use notify_debouncer_full::{new_debouncer, DebouncedEvent, DebounceEventResult};
use parking_lot::Mutex;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::Duration;
use tauri::{AppHandle, Emitter};
use tokio::sync::mpsc;
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct FolderMonitorSettings {
pub enabled: bool,
pub folder_path: String,
#[serde(default)]
pub recursive: bool,
#[serde(default = "default_filter_mode")]
pub filter_mode: String,
#[serde(default)]
pub extensions: String,
#[serde(default = "truthy")]
pub skip_duplicates: bool,
#[serde(default = "default_delay")]
pub delay_sec: u64,
}
fn default_filter_mode() -> String { "include".into() }
fn truthy() -> bool { true }
fn default_delay() -> u64 { 3 }
pub struct FolderMonitor {
app: AppHandle,
stop_tx: Mutex