File size: 1,965 Bytes
3d7d9b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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",
    ]
}