blob: 77090a368467ee01cc3e1c7d234e31d452803040 (
plain)
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
|
use std::path;
use std::thread;
use crate::context::AppContext;
use crate::event::AppEvent;
use crate::fs::JoshutoDirList;
#[derive(Debug, Clone)]
pub enum PreviewDirState {
Loading,
Error { message: String },
}
impl PreviewDirState {
pub fn is_loading(&self) -> bool {
matches!(*self, Self::Loading)
}
}
pub struct Background {}
impl Background {
pub fn load_preview(context: &mut AppContext, p: path::PathBuf) -> thread::JoinHandle<()> {
let event_tx = context.events.event_tx.clone();
let options = context.config_ref().display_options_ref().clone();
let tab_options = context
.tab_context_ref()
.curr_tab_ref()
.option_ref()
.clone();
let tab_id = context.tab_context_ref().curr_tab_id();
// add to loading state
context
.tab_context_mut()
.curr_tab_mut()
.history_metadata_mut()
.insert(p.clone(), PreviewDirState::Loading);
thread::spawn(move || {
let path_clone = p.clone();
let dir_res = JoshutoDirList::from_path(p, &options, &tab_options);
let res = AppEvent::PreviewDir {
id: tab_id,
path: path_clone,
res: Box::new(dir_res),
};
let _ = event_tx.send(res);
})
}
}
|