Skip to content

wx events end_session and query_end_session are not propagated on macos #4

@dominicletz

Description

@dominicletz

Problem
When a user wants to shut down his mac, the running erlang application will ignore the shutdown signal and stay open, and this way it will block the macOS shutdown.

Root Cause
The root problem is that :wxFrame.connect(frame, :end_session) in window.ex does not have any effect. And the :end_session event is never delivered to the application. Only :wxFrame.connect(frame, :close_window) is delivered but does not make it possible to differentiate between the user closing a window or the system shutting down.

Current Workaround
Currently, we're checking on receiving the :close_window event whether any window is shown -- if no window is shown, we assume this is a system shutdown and trigger a OS.shutdown() - the problem with this approach is that when a window is open, the window will be closed, but a system shutdown is still being prevented until the user tries again.

Steps to reproduce
Open the sample app and open the main window. Now open the macOS activity monitor and use the "Stop" option to stop the application. The application should be stopped -- but actually, only the window is closed, only a second "Stop" call will make the application stop if now window is shown (the workaround is in effect)

Background
When using the macOS "Activity Monitor" or when doing a system shutdown to stop an app macOS is not sending a Unix signal but instead an apple event to the app to close it.

wxWidgets is internally creating two events for this. From the docs:

    EVT_QUERY_END_SESSION(func):
    Process a wxEVT_QUERY_END_SESSION session event, supplying the member function. This event can be handled in wxApp-derived class only.
    EVT_END_SESSION(func):
    Process a wxEVT_END_SESSION session event, supplying the member function. This event can be handled in wxApp-derived class only.

Reference:
https://github.com/wxWidgets/wxWidgets/blob/master/src/osx/carbon/app.cpp#L209
https://docs.wxwidgets.org/3.0/classwx_close_event.html

Solution Proposal
A) One option to make these events available is to add Connect() calls in wxe_impl.cpp and pipe them through from there (https://github.com/erlang/otp/blob/master/lib/wx/c_src/wxe_impl.cpp#L151)

B) or alternatively make it possible to issue wxEventHandler:connect(:wxApp, :end_session) calls from erlang and trigger the corresponding app Connect() calls. Currently there is no way to reference in :wxApp instance from erlang space so that would be needed to be added.

there might be other options as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions