Multi window example should include example of how to bubble the close event on the main window to all children windows.
Specific Demand
This is required because in certain circumstances you may launch a headless window (as seen in the overlay example) as a popup window. Closing the main window will actually do nothing on MacOS specifically if a headless window still exists from the same process.
Implement Suggestion
Not quite sure on the exact fix but I assume simply calling close on all open windows prior to emitting the actual close event would be adequate.
The way I've solved that is by moving a flume receiver into the the window. Then, when the parent window closes, it has a Vec<Sender<Action>> and sends a close method to each child window. The way to get a channel into a Window was a bit tricky because the documentation is sparse:
fn open_window(cx: Scope) -> Sender<Action> {
let (sender, receiver) = flume::unbounded::<Action>();
let dom = VirtualDom::new(new_window);
let s = LogicalSize::new(800., 600.);
let builder = WindowBuilder::new()
.with_inner_size(s);
let dom_scope = dom.base_scope();
dom_scope.provide_context(receiver);
let config = Config::new()
.with_window(builder);
self.context.new_window(dom, config);
}
fn new_window(cx: Scope) -> Element {
let Some(receiver) = cx.consume_context::<Receiver<Action>>() else {
return cx.render(rsx!(div {"Unknown Error "}));
};
cx.render(rsx!(window_state.window(cx, receiver)))
}
Great solution! This is an API surface we need to overhaul, but since it's breaking, we can't do it until the next major release.
The trickiness is that the window that tao gives has a drop handler, so if you open a window and then close the scope, it disappears immediately, hence the idea that the window that spawned the window is the owner.
However, I think we can address this specific issue in a minor release.