#talk to the front end

6 messages · Page 1 of 1 (latest)

bright tundra
#

I have a function in the backend that I want to pause when it rich some values type and send the value to the front end and then wait for confirmation for proceeding.
It is doable?

nimble vector
bright tundra
#

ok i got something but i kind of stuck when i send the value back to front end the app wont listen again and the procces is stuck in the middle:
fn main() {
//
.menu(build_menu())
.setup(|app| {
let windowClone1 = window.clone();
let _id = app.listen_global("start_process", move |event| {
let json_paths = event.payload().unwrap();
get_paths_values(windowClone1.clone(), json_paths);
});
})
}

pub fn get_paths_values(manager: Window, paths: &str) {
/// soome code
///
let window = manager.get_window("main").unwrap();
let (tx, rx) = std::sync::mpsc::channel::<()>();
let mut values_text = Vec::new();
for (i, path) in paths_copy.iter().enumerate() {
if values_text.len() == max_values|| (i == paths_copy.len() - 1 && values_text.len() > 0) {
window.emit_all("new_values_batch", serde_json::to_value(&values_text).unwrap()).unwrap();
values_text.clear();
let manager_clone = manager.clone();
///**** HERE IT STOPS
thread::spawn(move || {
let _proc= manager_clone.listen_global("keep_proceed", move |_event| {
tx_clone.send(()).unwrap();
});
// manager_clone.unlisten(_proc);
});

        rx.recv().unwrap();
       
    }
}
if songs.len() > 0 {
    window.emit_all("new_values_batch", serde_json::to_value(&values_text).unwrap()).unwrap();
}

window.emit_all("done_process", serde_json::to_value(()).unwrap()).unwrap();

}

nimble vector
#

can you wrap your code in backticks? like this:
```rs
your code here
```

#

otherwise discord renders it a bit weird

#

did you try moving the thread::spawn above the emit_all line?