Merge branch 'wip/pwithnall/2119-osx-app-info' into 'master'

Debuggability improvements in gosxappinfo.m

See merge request GNOME/glib!1787
This commit is contained in:
Sebastian Dröge 2020-12-09 12:43:20 +00:00
commit 737a853f8d
2 changed files with 23 additions and 10 deletions

View File

@ -43,7 +43,7 @@ GLIB_AVAILABLE_IN_2_52
GType g_osx_app_info_get_type (void) G_GNUC_CONST; GType g_osx_app_info_get_type (void) G_GNUC_CONST;
GLIB_AVAILABLE_IN_2_52 GLIB_AVAILABLE_IN_2_52
char * g_osx_app_info_get_filename (GOsxAppInfo *info); const char *g_osx_app_info_get_filename (GOsxAppInfo *info);
GLIB_AVAILABLE_IN_2_52 GLIB_AVAILABLE_IN_2_52
GList * g_osx_app_info_get_all_for_scheme (const gchar *scheme); GList * g_osx_app_info_get_all_for_scheme (const gchar *scheme);

View File

@ -168,6 +168,7 @@ get_bundle_string_value (NSBundle *bundle,
static CFStringRef static CFStringRef
create_cfstring_from_cstr (const gchar *cstr) create_cfstring_from_cstr (const gchar *cstr)
{ {
g_return_val_if_fail (cstr != NULL, NULL);
return CFStringCreateWithCString (NULL, cstr, kCFStringEncodingUTF8); return CFStringCreateWithCString (NULL, cstr, kCFStringEncodingUTF8);
} }
@ -226,7 +227,7 @@ url_escape_hostname (const char *url)
} }
static CFURLRef static CFURLRef
create_url_from_cstr (gchar *cstr, create_url_from_cstr (const gchar *cstr,
gboolean is_file) gboolean is_file)
{ {
gchar *puny_cstr; gchar *puny_cstr;
@ -279,11 +280,17 @@ create_urlspec_for_appinfo (GOsxAppInfo *info,
GList *uris, GList *uris,
gboolean are_files) gboolean are_files)
{ {
LSLaunchURLSpec *urlspec = g_new0 (LSLaunchURLSpec, 1); LSLaunchURLSpec *urlspec = NULL;
gchar *app_cstr = g_osx_app_info_get_filename (info); const gchar *app_cstr;
g_return_val_if_fail (G_IS_OSX_APP_INFO (info), NULL);
urlspec = g_new0 (LSLaunchURLSpec, 1);
app_cstr = g_osx_app_info_get_filename (info);
g_assert (app_cstr != NULL);
/* Strip file:// from app url but ensure filesystem url */ /* Strip file:// from app url but ensure filesystem url */
urlspec->appURL = create_url_from_cstr (app_cstr + 7, TRUE); urlspec->appURL = create_url_from_cstr (app_cstr + strlen ("file://"), TRUE);
urlspec->launchFlags = kLSLaunchDefaults; urlspec->launchFlags = kLSLaunchDefaults;
urlspec->itemURLs = create_url_list_from_glist (uris, are_files); urlspec->itemURLs = create_url_list_from_glist (uris, are_files);
@ -402,7 +409,7 @@ g_osx_app_info_get_executable (GAppInfo *appinfo)
return info->executable; return info->executable;
} }
char * const char *
g_osx_app_info_get_filename (GOsxAppInfo *info) g_osx_app_info_get_filename (GOsxAppInfo *info)
{ {
g_return_val_if_fail (info != NULL, NULL); g_return_val_if_fail (info != NULL, NULL);
@ -431,7 +438,8 @@ g_osx_app_info_get_icon (GAppInfo *appinfo)
if (!info->icon) if (!info->icon)
{ {
gchar *icon_name, *app_uri, *icon_uri; const gchar *app_uri;
gchar *icon_name, *icon_uri;
GFile *file; GFile *file;
icon_name = get_bundle_string_value (info->bundle, @"CFBundleIconFile"); icon_name = get_bundle_string_value (info->bundle, @"CFBundleIconFile");
@ -439,7 +447,7 @@ g_osx_app_info_get_icon (GAppInfo *appinfo)
return NULL; return NULL;
app_uri = g_osx_app_info_get_filename (info); app_uri = g_osx_app_info_get_filename (info);
icon_uri = g_strconcat (app_uri + 7, "/Contents/Resources/", icon_name, icon_uri = g_strconcat (app_uri + strlen ("file://"), "/Contents/Resources/", icon_name,
g_str_has_suffix (icon_name, ".icns") ? NULL : ".icns", NULL); g_str_has_suffix (icon_name, ".icns") ? NULL : ".icns", NULL);
g_free (icon_name); g_free (icon_name);
@ -459,9 +467,14 @@ g_osx_app_info_launch_internal (GAppInfo *appinfo,
GError **error) GError **error)
{ {
GOsxAppInfo *info = G_OSX_APP_INFO (appinfo); GOsxAppInfo *info = G_OSX_APP_INFO (appinfo);
LSLaunchURLSpec *urlspec = create_urlspec_for_appinfo (info, uris, are_files); LSLaunchURLSpec *urlspec;
gint ret, success = TRUE; gint ret, success = TRUE;
g_return_val_if_fail (G_IS_OSX_APP_INFO (appinfo), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
urlspec = create_urlspec_for_appinfo (info, uris, are_files);
if ((ret = LSOpenFromURLSpec (urlspec, NULL))) if ((ret = LSOpenFromURLSpec (urlspec, NULL)))
{ {
/* TODO: Better error codes */ /* TODO: Better error codes */