Report app.setUserTasks success/failure
This commit is contained in:
parent
5eeadb0ad4
commit
a0cf013112
3 changed files with 13 additions and 11 deletions
|
@ -156,7 +156,7 @@ class Browser : public WindowListObserver {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add a custom task to jump list.
|
// 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
|
// Returns the application user model ID, if there isn't one, then create
|
||||||
// one from app's name.
|
// one from app's name.
|
||||||
|
|
|
@ -79,22 +79,22 @@ void Browser::SetAppUserModelID(const base::string16& name) {
|
||||||
SetCurrentProcessExplicitAppUserModelID(app_user_model_id_.c_str());
|
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;
|
CComPtr<ICustomDestinationList> destinations;
|
||||||
if (FAILED(destinations.CoCreateInstance(CLSID_DestinationList)))
|
if (FAILED(destinations.CoCreateInstance(CLSID_DestinationList)))
|
||||||
return;
|
return false;
|
||||||
if (FAILED(destinations->SetAppID(GetAppUserModelID())))
|
if (FAILED(destinations->SetAppID(GetAppUserModelID())))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
// Start a transaction that updates the JumpList of this application.
|
// Start a transaction that updates the JumpList of this application.
|
||||||
UINT max_slots;
|
UINT max_slots;
|
||||||
CComPtr<IObjectArray> removed;
|
CComPtr<IObjectArray> removed;
|
||||||
if (FAILED(destinations->BeginList(&max_slots, IID_PPV_ARGS(&removed))))
|
if (FAILED(destinations->BeginList(&max_slots, IID_PPV_ARGS(&removed))))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
CComPtr<IObjectCollection> collection;
|
CComPtr<IObjectCollection> collection;
|
||||||
if (FAILED(collection.CoCreateInstance(CLSID_EnumerableObjectCollection)))
|
if (FAILED(collection.CoCreateInstance(CLSID_EnumerableObjectCollection)))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
for (auto& task : tasks) {
|
for (auto& task : tasks) {
|
||||||
CComPtr<IShellLink> link;
|
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->SetPath(task.program.value().c_str())) ||
|
||||||
FAILED(link->SetArguments(task.arguments.c_str())) ||
|
FAILED(link->SetArguments(task.arguments.c_str())) ||
|
||||||
FAILED(link->SetDescription(task.description.c_str())))
|
FAILED(link->SetDescription(task.description.c_str())))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
if (!task.icon_path.empty() &&
|
if (!task.icon_path.empty() &&
|
||||||
FAILED(link->SetIconLocation(task.icon_path.value().c_str(),
|
FAILED(link->SetIconLocation(task.icon_path.value().c_str(),
|
||||||
task.icon_index)))
|
task.icon_index)))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
CComQIPtr<IPropertyStore> property_store = link;
|
CComQIPtr<IPropertyStore> property_store = link;
|
||||||
if (!base::win::SetStringValueForPropertyStore(property_store, PKEY_Title,
|
if (!base::win::SetStringValueForPropertyStore(property_store, PKEY_Title,
|
||||||
task.title.c_str()))
|
task.title.c_str()))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
if (FAILED(collection->AddObject(link)))
|
if (FAILED(collection->AddObject(link)))
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When the list is empty "AddUserTasks" could fail, so we don't check return
|
// When the list is empty "AddUserTasks" could fail, so we don't check return
|
||||||
// value for it.
|
// value for it.
|
||||||
CComQIPtr<IObjectArray> task_array = collection;
|
CComQIPtr<IObjectArray> task_array = collection;
|
||||||
destinations->AddUserTasks(task_array);
|
destinations->AddUserTasks(task_array);
|
||||||
destinations->CommitList();
|
return SUCCEEDED(destinations->CommitList());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol) {
|
bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol) {
|
||||||
|
|
|
@ -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
|
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.
|
icon file consists of one icon, this value is 0.
|
||||||
|
|
||||||
|
Returns `true` when the call succeeded, otherwise returns `false`.
|
||||||
|
|
||||||
### `app.makeSingleInstance(callback)`
|
### `app.makeSingleInstance(callback)`
|
||||||
|
|
||||||
* `callback` Function
|
* `callback` Function
|
||||||
|
|
Loading…
Reference in a new issue