If I understood the documentation correctly, then:
1.) You have to override the default behavior (ie. in the _ready function):
func _ready():
get_tree().set_auto_accept_quit(false)
(...)
2.)You can handle the quit request in the _notification function:
func _notification(what):
if (what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST):
#
# code of saving
#
get_tree().quit()