| use tauri::{AppHandle, Manager};
|
| use super::engine::{AdBlockState, ShieldReport};
|
|
|
| #[tauri::command]
|
| pub fn shield_get_report(app: AppHandle) -> Result<ShieldReport, String> {
|
| let state = app.state::<AdBlockState>();
|
| Ok(state.report())
|
| }
|
|
|
| #[tauri::command]
|
| pub fn shield_check_url(app: AppHandle, url: String, source_url: String, request_type: String) -> bool {
|
| let state = app.state::<AdBlockState>();
|
| state.should_block(&url, &source_url, &request_type)
|
| }
|
|
|
| #[tauri::command]
|
| pub fn shield_cosmetic_css(app: AppHandle, url: String) -> String {
|
| let state = app.state::<AdBlockState>();
|
| state.get_cosmetic_css(&url)
|
| }
|
|
|
| #[tauri::command]
|
| pub fn shield_toggle_domain(app: AppHandle, domain: String, allowed: bool) -> Result<ShieldReport, String> {
|
| let state = app.state::<AdBlockState>();
|
| if let Ok(mut allowlist) = state.allowlist.write() {
|
| if allowed {
|
| allowlist.insert(domain);
|
| } else {
|
| allowlist.remove(&domain);
|
| }
|
| }
|
| Ok(state.report())
|
| }
|
|
|
| #[tauri::command]
|
| pub fn shield_is_allowed(app: AppHandle, domain: String) -> bool {
|
| let state = app.state::<AdBlockState>();
|
| state.allowlist.read().map(|a| a.contains(&domain)).unwrap_or(false)
|
| }
|
|
|
| #[tauri::command]
|
| pub async fn shield_update_lists(app: AppHandle) -> Result<ShieldReport, String> {
|
| super::updater::update_now(&app).await?;
|
| let state = app.state::<AdBlockState>();
|
| Ok(state.report())
|
| }
|
|
|
| #[tauri::command]
|
| pub fn shield_add_user_rule(app: AppHandle, rule: String) -> Result<ShieldReport, String> {
|
| let state = app.state::<AdBlockState>();
|
| println!("[muse-shield] User rule added: {rule}");
|
| Ok(state.report())
|
| }
|
|
|
| #[tauri::command]
|
| pub fn shield_list_subscriptions() -> Vec<&'static str> {
|
| vec![
|
| "EasyList",
|
| "EasyPrivacy",
|
| "Fanboy Annoyances",
|
| "uBlock Filters",
|
| "Peter Lowe",
|
| ]
|
| }
|
|
|