win: Add app.addUserTasks API
This commit is contained in:
parent
48412769df
commit
47c18fef7f
3 changed files with 78 additions and 0 deletions
|
@ -33,6 +33,25 @@
|
||||||
|
|
||||||
using atom::Browser;
|
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 atom {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
@ -162,6 +181,10 @@ mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
|
||||||
base::Bind(&Browser::AddRecentDocument, browser))
|
base::Bind(&Browser::AddRecentDocument, browser))
|
||||||
.SetMethod("clearRecentDocuments",
|
.SetMethod("clearRecentDocuments",
|
||||||
base::Bind(&Browser::ClearRecentDocuments, browser))
|
base::Bind(&Browser::ClearRecentDocuments, browser))
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
.SetMethod("addUserTasks",
|
||||||
|
base::Bind(&Browser::AddUserTasks, browser))
|
||||||
|
#endif
|
||||||
.SetMethod("getDataPath", &App::GetDataPath)
|
.SetMethod("getDataPath", &App::GetDataPath)
|
||||||
.SetMethod("resolveProxy", &App::ResolveProxy)
|
.SetMethod("resolveProxy", &App::ResolveProxy)
|
||||||
.SetMethod("setDesktopName", &App::SetDesktopName);
|
.SetMethod("setDesktopName", &App::SetDesktopName);
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#define ATOM_BROWSER_BROWSER_H_
|
#define ATOM_BROWSER_BROWSER_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "base/basictypes.h"
|
#include "base/basictypes.h"
|
||||||
#include "base/compiler_specific.h"
|
#include "base/compiler_specific.h"
|
||||||
|
@ -14,6 +15,7 @@
|
||||||
#include "atom/browser/window_list_observer.h"
|
#include "atom/browser/window_list_observer.h"
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
|
#include "base/files/file_path.h"
|
||||||
#include "base/strings/string16.h"
|
#include "base/strings/string16.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -84,6 +86,16 @@ class Browser : public WindowListObserver {
|
||||||
#endif // defined(OS_MACOSX)
|
#endif // defined(OS_MACOSX)
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#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.
|
// Set the application user model ID, called when "SetName" is called.
|
||||||
void SetAppUserModelID(const std::string& name);
|
void SetAppUserModelID(const std::string& name);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "atom/browser/browser.h"
|
#include "atom/browser/browser.h"
|
||||||
|
|
||||||
#include <atlbase.h>
|
#include <atlbase.h>
|
||||||
|
#include <propkey.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <shlobj.h>
|
#include <shlobj.h>
|
||||||
#include <shobjidl.h>
|
#include <shobjidl.h>
|
||||||
|
@ -16,6 +17,7 @@
|
||||||
#include "base/path_service.h"
|
#include "base/path_service.h"
|
||||||
#include "base/strings/stringprintf.h"
|
#include "base/strings/stringprintf.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
|
#include "base/win/win_util.h"
|
||||||
#include "base/win/windows_version.h"
|
#include "base/win/windows_version.h"
|
||||||
#include "atom/common/atom_version.h"
|
#include "atom/common/atom_version.h"
|
||||||
|
|
||||||
|
@ -69,6 +71,47 @@ void Browser::ClearRecentDocuments() {
|
||||||
destinations->RemoveAllDestinations();
|
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) {
|
void Browser::SetAppUserModelID(const std::string& name) {
|
||||||
app_user_model_id_ = base::UTF8ToUTF16(
|
app_user_model_id_ = base::UTF8ToUTF16(
|
||||||
base::StringPrintf("atom-shell.app.%s", name));
|
base::StringPrintf("atom-shell.app.%s", name));
|
||||||
|
|
Loading…
Reference in a new issue