From c97c3fb9a1f28d56ba2b6cc7090ab438204ec78e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 12 Jun 2015 13:54:42 +0800 Subject: [PATCH] Use LSGetApplicationForURL to search for app It costs less. --- atom/common/platform_util_mac.mm | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/atom/common/platform_util_mac.mm b/atom/common/platform_util_mac.mm index 4637bc33..a1f17d7c 100644 --- a/atom/common/platform_util_mac.mm +++ b/atom/common/platform_util_mac.mm @@ -122,15 +122,21 @@ bool OpenExternal(const GURL& url) { DCHECK([NSThread isMainThread]); NSString* url_string = base::SysUTF8ToNSString(url.spec()); NSURL* ns_url = [NSURL URLWithString:url_string]; - if (!ns_url){ + if (!ns_url) { return false; } - NSArray *appUrls = (NSArray*)LSCopyApplicationURLsForURL((CFURLRef)ns_url, kLSRolesAll); - if([appUrls count] > 0){ - if([[NSWorkspace sharedWorkspace] openURL:ns_url]) - return true; + + CFURLRef openingApp = NULL; + OSStatus status = LSGetApplicationForURL((CFURLRef)ns_url, + kLSRolesAll, + NULL, + &openingApp); + if (status != noErr) { + return false; } - return false; + CFRelease(openingApp); // NOT A BUG; LSGetApplicationForURL retains for us + + return [[NSWorkspace sharedWorkspace] openURL:ns_url]; } bool MoveItemToTrash(const base::FilePath& full_path) { -- 2.43.0