Browse Source

Report app.setUserTasks success/failure

Milan Burda 8 years ago
parent
commit
a0cf013112
3 changed files with 13 additions and 11 deletions
  1. 1 1
      atom/browser/browser.h
  2. 10 10
      atom/browser/browser_win.cc
  3. 2 0
      docs/api/app.md

+ 1 - 1
atom/browser/browser.h

@@ -156,7 +156,7 @@ class Browser : public WindowListObserver {
   };
 
   // Add a custom task to jump list.
-  void SetUserTasks(const std::vector<UserTask>& tasks);
+  bool SetUserTasks(const std::vector<UserTask>& tasks);
 
   // Returns the application user model ID, if there isn't one, then create
   // one from app's name.

+ 10 - 10
atom/browser/browser_win.cc

@@ -79,22 +79,22 @@ void Browser::SetAppUserModelID(const base::string16& name) {
   SetCurrentProcessExplicitAppUserModelID(app_user_model_id_.c_str());
 }
 
-void Browser::SetUserTasks(const std::vector<UserTask>& tasks) {
+bool Browser::SetUserTasks(const std::vector<UserTask>& tasks) {
   CComPtr<ICustomDestinationList> destinations;
   if (FAILED(destinations.CoCreateInstance(CLSID_DestinationList)))
-    return;
+    return false;
   if (FAILED(destinations->SetAppID(GetAppUserModelID())))
-    return;
+    return false;
 
   // Start a transaction that updates the JumpList of this application.
   UINT max_slots;
   CComPtr<IObjectArray> removed;
   if (FAILED(destinations->BeginList(&max_slots, IID_PPV_ARGS(&removed))))
-    return;
+    return false;
 
   CComPtr<IObjectCollection> collection;
   if (FAILED(collection.CoCreateInstance(CLSID_EnumerableObjectCollection)))
-    return;
+    return false;
 
   for (auto& task : tasks) {
     CComPtr<IShellLink> link;
@@ -102,27 +102,27 @@ void Browser::SetUserTasks(const std::vector<UserTask>& tasks) {
         FAILED(link->SetPath(task.program.value().c_str())) ||
         FAILED(link->SetArguments(task.arguments.c_str())) ||
         FAILED(link->SetDescription(task.description.c_str())))
-      return;
+      return false;
 
     if (!task.icon_path.empty() &&
         FAILED(link->SetIconLocation(task.icon_path.value().c_str(),
                                      task.icon_index)))
-      return;
+      return false;
 
     CComQIPtr<IPropertyStore> property_store = link;
     if (!base::win::SetStringValueForPropertyStore(property_store, PKEY_Title,
                                                    task.title.c_str()))
-      return;
+      return false;
 
     if (FAILED(collection->AddObject(link)))
-      return;
+      return false;
   }
 
   // When the list is empty "AddUserTasks" could fail, so we don't check return
   // value for it.
   CComQIPtr<IObjectArray> task_array = collection;
   destinations->AddUserTasks(task_array);
-  destinations->CommitList();
+  return SUCCEEDED(destinations->CommitList());
 }
 
 bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol) {

+ 2 - 0
docs/api/app.md

@@ -512,6 +512,8 @@ Adds `tasks` to the [Tasks][tasks] category of the JumpList on Windows.
   consists of two or more icons, set this value to identify the icon. If an
   icon file consists of one icon, this value is 0.
 
+Returns `true` when the call succeeded, otherwise returns `false`.
+
 ### `app.makeSingleInstance(callback)`
 
 * `callback` Function