Add APP_PAUSED and APP_RESUMED MainLoop notifications

This commit is contained in:
Zach Coleman 2023-11-22 11:43:40 -05:00 committed by Relintai
parent 7101e4aed7
commit 92a8e047e0
5 changed files with 37 additions and 4 deletions

View File

@ -201,11 +201,12 @@
</constant>
<constant name="NOTIFICATION_APP_RESUMED" value="1014">
Notification received from the OS when the app is resumed.
Specific to the Android platform.
Specific to mobile platforms.
</constant>
<constant name="NOTIFICATION_APP_PAUSED" value="1015">
Notification received from the OS when the app is paused.
Specific to the Android platform.
Specific to mobile platforms.
[b]Note:[/b] On iOS, you only have approximately 5 seconds to finish a task started by this signal. If you go over this allotment, iOS will kill the app instead of pausing it.
</constant>
</constants>
</class>

View File

@ -1085,11 +1085,12 @@
</constant>
<constant name="NOTIFICATION_APP_RESUMED" value="1014">
Notification received from the OS when the app is resumed.
Specific to the Android platform.
Specific to mobile platforms.
</constant>
<constant name="NOTIFICATION_APP_PAUSED" value="1015">
Notification received from the OS when the app is paused.
Specific to the Android platform.
Specific to mobile platforms.
[b]Note:[/b] On iOS, you only have approximately 5 seconds to finish a task started by this signal. If you go over this allotment, iOS will kill the app instead of pausing it.
</constant>
<constant name="PAUSE_MODE_INHERIT" value="0" enum="PauseMode">
Inherits pause mode from the node's parent. For the root node, it is equivalent to [constant PAUSE_MODE_STOP]. Default.

View File

@ -175,6 +175,14 @@ static ViewController *mainViewController = nil;
OSIPhone::get_singleton()->on_focus_in();
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
OSIPhone::get_singleton()->on_enter_background();
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
OSIPhone::get_singleton()->on_exit_background();
}
- (void)dealloc {
self.window = nil;
}

View File

@ -194,6 +194,9 @@ public:
void on_focus_out();
void on_focus_in();
void on_enter_background();
void on_exit_background();
};
#endif // OS_IPHONE_H

View File

@ -802,4 +802,24 @@ void OSIPhone::on_focus_in() {
}
}
void OSIPhone::on_enter_background() {
// Do not check for is_focused, because on_focus_out will always be fired first by applicationWillResignActive.
if (get_main_loop()) {
get_main_loop()->notification(MainLoop::NOTIFICATION_APP_PAUSED);
}
on_focus_out();
}
void OSIPhone::on_exit_background() {
if (!is_focused) {
on_focus_in();
if (get_main_loop()) {
get_main_loop()->notification(MainLoop::NOTIFICATION_APP_RESUMED);
}
}
}
#endif