~julienxx/asuka

ref: 26daa0efca55c80a5f36fff08056ab245e6f39b8 asuka/src/history.rs -rw-r--r-- 681 bytes
26daa0ef — Arav K Add reload capability 2 months 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
use std::sync::Mutex;
use url::Url;

lazy_static! {
    static ref HISTORY: Mutex<Vec<Url>> = Mutex::new(vec![]);
}

pub fn append(url: &str) {
    let url = Url::parse(url).unwrap();
    HISTORY.lock().unwrap().push(url)
}

pub fn get_current_url() -> Option<Url> {
    let history = HISTORY.lock().unwrap();
    history.last().cloned()
}

pub fn get_previous_url() -> Option<Url> {
    let mut history = HISTORY.lock().unwrap();

    if history.len() > 1 {
        history.pop(); // remove current

        if history.len() > 1 {
            history.pop() // return previous
        } else {
            history.iter().cloned().last()
        }
    } else {
        None
    }
}