Implement app.setUserActivity(type, userInfo).
authorCharlie Hess <charlie@slack-corp.com>
Sat, 30 Apr 2016 00:35:07 +0000 (17:35 -0700)
committerCharlie Hess <charlie@slack-corp.com>
Sat, 30 Apr 2016 00:35:07 +0000 (17:35 -0700)
atom/browser/api/atom_api_app.cc
atom/browser/browser.h
atom/browser/browser_mac.mm

index 304e53a..8e7d8c3 100644 (file)
@@ -460,6 +460,7 @@ void App::BuildPrototype(
 #if defined(OS_MACOSX)
       .SetMethod("hide", base::Bind(&Browser::Hide, browser))
       .SetMethod("show", base::Bind(&Browser::Show, browser))
+      .SetMethod("setUserActivity", base::Bind(&Browser::SetUserActivity, browser))
 #endif
 #if defined(OS_WIN)
       .SetMethod("setUserTasks",
index 8329b14..b0dd829 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <string>
 #include <vector>
+#include <map>
 
 #include "base/macros.h"
 #include "base/compiler_specific.h"
@@ -92,6 +93,9 @@ class Browser : public WindowListObserver {
   // Show the application.
   void Show();
 
+  // Creates an activity and sets it as the one currently in use.
+  void SetUserActivity(const std::string& type, const std::map<std::string, std::string>& user_info);
+  
   // Bounce the dock icon.
   enum BounceType {
     BOUNCE_CRITICAL = 0,
index c10369a..627ed65 100644 (file)
@@ -87,6 +87,23 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol) {
 void Browser::SetAppUserModelID(const base::string16& name) {
 }
 
+void Browser::SetUserActivity(const std::string& type, const std::map<std::string, std::string>& user_info) {
+  NSString* type_ns = [NSString stringWithUTF8String:type.c_str()];
+  NSUserActivity *user_activity = [[NSUserActivity alloc] initWithActivityType:type_ns];
+
+  NSMutableArray* user_info_args = [[NSMutableArray alloc] init];
+  for (auto const &pair : user_info) {
+    NSString* key_ns = [NSString stringWithUTF8String:pair.first.c_str()];
+    NSString* value_ns = [NSString stringWithUTF8String:pair.second.c_str()];
+    
+    [user_info_args addObject:key_ns];
+    [user_info_args addObject:value_ns];
+  }
+
+  user_activity.userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:user_info_args, nil];
+  [user_activity becomeCurrent];
+}
+
 std::string Browser::GetExecutableFileVersion() const {
   return brightray::GetApplicationVersion();
 }