-
i have a requirement to reload application when config file changed: fn main() {
args::get_args();
let file_change_signal_receiver = init_file_monitor();
loop {
let (reload_signal_sender, reload_signal_receiver) = async_channel::bounded::<()>(1);
let th = thread::spawn(move || {
let application =
gtk::Application::new(None::<String>, ApplicationFlags::HANDLES_OPEN);
// when args passed, `open` will be signaled instead of `activate`
application.connect_open(
glib::clone!(@strong reload_signal_receiver as r => move |app, _, _| {
println!("open");
init_app(app, &r);
}),
);
application.connect_activate(
glib::clone!(@strong reload_signal_receiver as r => move |app| {
println!("activate");
init_app(app, &r);
}),
);
if application.run_with_args::<String>(&[]).value() == 1 {
process::exit(1);
};
});
if let Err(e) = file_change_signal_receiver.recv_blocking() {
log::error!("Error: {e}");
break;
} else {
println!("receive reload signal");
reload_signal_sender.try_send(()).ok(); // app will `quit()` after reload signal sent, and app may `quit()` if other error occurred so i just `try_send` and ignore the result
th.join().unwrap();
}
println!("Reload!!!");
}
} but reload will raise error:
which i found out is because of I will be thankful if someone can help me out with this. |
Beta Was this translation helpful? Give feedback.
Answered by
sdroege
Jul 2, 2024
Replies: 1 comment 1 reply
-
You can only use GTK from a single thread. Either you have to continue using the initial thread, or you have to restart your process. Also note that on macOS you must use GTK from the thread that called |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ogios
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can only use GTK from a single thread. Either you have to continue using the initial thread, or you have to restart your process.
Also note that on macOS you must use GTK from the thread that called
main()
.