application-quit-handler in System Menus

When the current eventspace is the initial eventspace, this procedure retrieves or installs a thunk that is called when the user requests that the application quit (e.g., through the Quit menu item in Mac OS X). The thunk is always called in the initial eventspace's handler thread (as a callback).

The default handler queues a call to the can-exit? method of the most recently active frame in the initial eventspace (and then calls the frame's on-exit method if the result is true). If the initial eventspace has no recently active frame that is still shown, then the default handler takes no action unless no other windows are shown in any other eventspace and a 'root menu-bar% has been created; in that case, it calls exit with no arguments.