Skip to content

Commit

Permalink
- add background callback register function and hook into ios backgro…
Browse files Browse the repository at this point in the history
…und notifcation functions
  • Loading branch information
polymonster committed Mar 16, 2024
1 parent 9a9d1b1 commit 32e7029
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/pen/include/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace pen
bool os_set_keychain_item(const Str& identifier, const Str& key, const Str& value);
Str os_get_keychain_item(const Str& identifier, const Str& key);
bool os_is_backgrounded();
void os_register_background_callback(void (*callback)(bool));

// music
struct music_item
Expand Down
24 changes: 24 additions & 0 deletions core/pen/source/ios/os.mm
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ -(MPRemoteCommandHandlerStatus)like;
pen_text_field* text_field = nullptr;
bool show_on_screen_keyboard = false;
pen::music_player_remote music_remote;
void (*background_callback)(bool) = nullptr;
};
os_context s_context;

Expand Down Expand Up @@ -172,6 +173,24 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N
}
}

- (void)applicationWillResignActive:(UIApplication *)app
{
// pairs with applicationDidBecomeActive
if(s_context.background_callback)
{
s_context.background_callback(true);
}
}

- (void)applicationDidBecomeActive:(UIApplication *)app
{
// pairs with applicationWillResignActive
if(s_context.background_callback)
{
s_context.background_callback(true);
}
}

-(MPRemoteCommandHandlerStatus)play {
if(s_context.music_remote.pause)
{
Expand Down Expand Up @@ -799,4 +818,9 @@ void music_set_now_playing_time_info(u32 position_ms, u32 duration_ms)
bool os_is_backgrounded() {
return [[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground;
}

void os_register_background_callback(void (*callback)(bool))
{
s_context.background_callback = callback;
}
}

0 comments on commit 32e7029

Please sign in to comment.