using atom::Browser;
+namespace mate {
+
+template<>
+struct Converter<Browser::UserTask> {
+ static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
+ Browser::UserTask* out) {
+ mate::Dictionary dict;
+ if (!ConvertFromV8(isolate, val, &dict))
+ return false;
+ return dict.Get("program", &(out->program)) &&
+ dict.Get("arguments", &(out->arguments)) &&
+ dict.Get("title", &(out->title)) &&
+ dict.Get("description", &(out->description));
+ }
+};
+
+} // namespace mate
+
+
namespace atom {
namespace api {
base::Bind(&Browser::AddRecentDocument, browser))
.SetMethod("clearRecentDocuments",
base::Bind(&Browser::ClearRecentDocuments, browser))
+#if defined(OS_WIN)
+ .SetMethod("addUserTasks",
+ base::Bind(&Browser::AddUserTasks, browser))
+#endif
.SetMethod("getDataPath", &App::GetDataPath)
.SetMethod("resolveProxy", &App::ResolveProxy)
.SetMethod("setDesktopName", &App::SetDesktopName);
#define ATOM_BROWSER_BROWSER_H_
#include <string>
+#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "atom/browser/window_list_observer.h"
#if defined(OS_WIN)
+#include "base/files/file_path.h"
#include "base/strings/string16.h"
#endif
#endif // defined(OS_MACOSX)
#if defined(OS_WIN)
+ struct UserTask {
+ base::FilePath program;
+ base::string16 arguments;
+ base::string16 title;
+ base::string16 description;
+ };
+
+ // Add a custom task to jump list.
+ void AddUserTasks(const std::vector<UserTask>& tasks);
+
// Set the application user model ID, called when "SetName" is called.
void SetAppUserModelID(const std::string& name);
#endif
#include "atom/browser/browser.h"
#include <atlbase.h>
+#include <propkey.h>
#include <windows.h>
#include <shlobj.h>
#include <shobjidl.h>
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/win/win_util.h"
#include "base/win/windows_version.h"
#include "atom/common/atom_version.h"
destinations->RemoveAllDestinations();
}
+void Browser::AddUserTasks(const std::vector<UserTask>& tasks) {
+ CComPtr<ICustomDestinationList> destinations;
+ if (FAILED(destinations.CoCreateInstance(CLSID_DestinationList)))
+ return;
+ if (FAILED(destinations->SetAppID(app_user_model_id_.c_str())))
+ return;
+
+ // 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;
+
+ CComPtr<IObjectCollection> collection;
+ if (FAILED(collection.CoCreateInstance(CLSID_EnumerableObjectCollection)))
+ return;
+
+ for (auto& task : tasks) {
+ CComPtr<IShellLink> link;
+ if (FAILED(link.CoCreateInstance(CLSID_ShellLink)) ||
+ FAILED(link->SetPath(task.program.value().c_str())) ||
+ FAILED(link->SetArguments(task.arguments.c_str())) ||
+ FAILED(link->SetDescription(task.description.c_str())))
+ return;
+
+ CComQIPtr<IPropertyStore> property_store = link;
+ if (!base::win::SetStringValueForPropertyStore(property_store, PKEY_Title,
+ task.title.c_str()))
+ return;
+
+ if (FAILED(collection->AddObject(link)))
+ return;
+ }
+
+ // 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();
+}
+
void Browser::SetAppUserModelID(const std::string& name) {
app_user_model_id_ = base::UTF8ToUTF16(
base::StringPrintf("atom-shell.app.%s", name));