Merge pull request #6766 from miniak/set-user-tasks-result

Report app.setUserTasks success/failure
This commit is contained in:
Cheng Zhao 2016-08-08 17:43:08 +09:00 committed by GitHub
commit a432fb0c34
3 changed files with 17 additions and 11 deletions

View file

@ -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.

View file

@ -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) {

View file

@ -460,6 +460,8 @@ system. Once registered, all links with `your-protocol://` will be opened with
the current executable. The whole link, including protocol, will be passed to
your application as a parameter.
Returns `true` when the call succeeded, otherwise returns `false`.
**Note:** On macOS, you can only register protocols that have been added to
your app's `info.plist`, which can not be modified at runtime. You can however
change the file with a simple text editor or script during build time.
@ -474,6 +476,8 @@ The API uses the Windows Registry and LSSetDefaultHandlerForURLScheme internally
This method checks if the current executable as the default handler for a
protocol (aka URI scheme). If so, it will remove the app as the default handler.
Returns `true` when the call succeeded, otherwise returns `false`.
### `app.isDefaultProtocolClient(protocol)` _macOS_ _Windows_
* `protocol` String - The name of your protocol, without `://`.
@ -512,6 +516,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