From 886282bd6a73369af4d96d6730ea5e8a74328cc9 Mon Sep 17 00:00:00 2001 From: Eric Warmenhoven Date: Fri, 17 Jan 2025 13:23:42 -0500 Subject: [PATCH] macos: fix some sandbox handling for app store --- frontend/drivers/platform_darwin.m | 4 ++-- menu/cbs/menu_cbs_ok.c | 5 ++++- menu/menu_displaylist.c | 2 +- ui/drivers/cocoa/apple_platform.h | 5 +++++ ui/drivers/cocoa/cocoa_common.m | 7 +++++++ ui/drivers/ui_cocoa.m | 25 ++++++++++++++++--------- 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/frontend/drivers/platform_darwin.m b/frontend/drivers/platform_darwin.m index e27c38fccccc..970dd376e6a7 100644 --- a/frontend/drivers/platform_darwin.m +++ b/frontend/drivers/platform_darwin.m @@ -704,7 +704,7 @@ static enum frontend_architecture frontend_darwin_get_arch(void) static int frontend_darwin_parse_drive_list(void *data, bool load_content) { int ret = -1; -#if TARGET_OS_IPHONE +#if TARGET_OS_IPHONE || defined(HAVE_APPLE_STORE) #ifdef HAVE_MENU struct string_list *str_list = NULL; file_list_t *list = (file_list_t*)data; @@ -733,7 +733,7 @@ static int frontend_darwin_parse_drive_list(void *data, bool load_content) FILE_TYPE_DIRECTORY, 0, 0, NULL); string_list_free(str_list); -#if TARGET_OS_IOS +#if !TARGET_OS_TV if ( filebrowser_get_type() == FILEBROWSER_NONE || filebrowser_get_type() == FILEBROWSER_SCAN_FILE || filebrowser_get_type() == FILEBROWSER_SELECT_FILE) diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index aa97852ba8ce..be032c88c2c9 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -6467,9 +6467,12 @@ static int action_ok_open_uwp_permission_settings(const char *path, static int action_ok_open_picker(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) { -#if TARGET_OS_IOS +#ifdef IOS ios_show_file_sheet(); return 0; +#elif defined(OSX) && defined(HAVE_APPLE_STORE) + osx_show_file_sheet(); + return 0; #else char *new_path = NULL; int ret = generic_action_ok_displaylist_push( diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 3eb3247300a1..b386968eaaae 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -492,7 +492,7 @@ static int filebrowser_parse( MENU_ENUM_LABEL_NO_ITEMS, MENU_SETTING_NO_ITEM, 0, 0, NULL); -#ifdef IOS +#if defined(IOS) || (defined(OSX) && defined(HAVE_APPLE_STORE)) { /* Check if we're allowed to escape our sandbox */ struct string_list *str_list = string_list_new(); diff --git a/ui/drivers/cocoa/apple_platform.h b/ui/drivers/cocoa/apple_platform.h index 86bb97ee19a0..4128b396586f 100644 --- a/ui/drivers/cocoa/apple_platform.h +++ b/ui/drivers/cocoa/apple_platform.h @@ -15,6 +15,10 @@ extern void ios_show_file_sheet(void); extern bool ios_running_on_ipad(void); #endif +#if TARGET_OS_OSX +extern void osx_show_file_sheet(void); +#endif + #ifdef __OBJC__ #import @@ -56,6 +60,7 @@ typedef enum apple_view_type * the displays should not sleep. */ - (bool)setDisableDisplaySleep:(bool)disable; +- (void)openDocument:(id)sender; @end #endif diff --git a/ui/drivers/cocoa/cocoa_common.m b/ui/drivers/cocoa/cocoa_common.m index 20569fa70930..7656c90ea069 100644 --- a/ui/drivers/cocoa/cocoa_common.m +++ b/ui/drivers/cocoa/cocoa_common.m @@ -802,6 +802,13 @@ void ios_show_file_sheet(void) } #endif +#if TARGET_OS_OSX && defined(HAVE_APPLE_STORE) +void osx_show_file_sheet(void) +{ + [apple_platform openDocument:nil]; +} +#endif + void *cocoa_screen_get_chosen(void) { unsigned monitor_index; diff --git a/ui/drivers/ui_cocoa.m b/ui/drivers/ui_cocoa.m index c40c45885711..8da4b6624571 100644 --- a/ui/drivers/ui_cocoa.m +++ b/ui/drivers/ui_cocoa.m @@ -918,16 +918,23 @@ static void open_document_handler( if (!result) return; - path_set(RARCH_PATH_CONTENT, state->result); - - if (core_name) + if (filebrowser_get_type() == FILEBROWSER_SCAN_FILE) + action_scan_file(state->result, NULL, 0, 0); + else { - content_ctx_info_t content_info = {0}; - task_push_load_content_with_current_core_from_companion_ui( - NULL, - &content_info, - CORE_TYPE_PLAIN, - NULL, NULL); + path_set(RARCH_PATH_CONTENT, state->result); + + if (!string_is_empty(core_name)) + { + content_ctx_info_t content_info = {0}; + task_push_load_content_with_current_core_from_companion_ui( + NULL, + &content_info, + CORE_TYPE_PLAIN, + NULL, NULL); + } + else + cocoa_file_load_with_detect_core(state->result); } }