]> khamidou — GitHub mirrors - electron.git/commitdiff
Use LSGetApplicationForURL to search for app
authorCheng Zhao <zcbenz@gmail.com>
Fri, 12 Jun 2015 05:54:42 +0000 (13:54 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 12 Jun 2015 05:54:42 +0000 (13:54 +0800)
It costs less.

atom/common/platform_util_mac.mm

index 4637bc330e315002837a8c145260bd881ee52983..a1f17d7c9d5c98737d390345fe406a883b2004bd 100644 (file)
@@ -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) {