feat: allow setting working directory in app.setUserTasks() / app.setJumpList() (#18148)

This commit is contained in:
Milan Burda 2019-05-13 18:17:12 +02:00 committed by Alexey Kuzmin
parent 326215e1f1
commit 3a5e6f2551
8 changed files with 20 additions and 3 deletions

View file

@ -85,6 +85,7 @@ struct Converter<Browser::UserTask> {
return false;
dict.Get("arguments", &(out->arguments));
dict.Get("description", &(out->description));
dict.Get("workingDirectory", &(out->working_dir));
return true;
}
};
@ -158,6 +159,7 @@ struct Converter<JumpListItem> {
dict.Get("args", &(out->arguments));
dict.Get("description", &(out->description));
dict.Get("workingDirectory", &(out->working_dir));
return true;
case JumpListItem::Type::SEPARATOR:
@ -184,6 +186,7 @@ struct Converter<JumpListItem> {
dict.Set("iconPath", val.icon_path);
dict.Set("iconIndex", val.icon_index);
dict.Set("description", val.description);
dict.Set("workingDirectory", val.working_dir);
break;
case JumpListItem::Type::SEPARATOR:

View file

@ -197,6 +197,7 @@ class Browser : public WindowListObserver {
base::string16 arguments;
base::string16 title;
base::string16 description;
base::FilePath working_dir;
base::FilePath icon_path;
int icon_index;

View file

@ -141,6 +141,7 @@ bool Browser::SetUserTasks(const std::vector<UserTask>& tasks) {
item.icon_path = task.icon_path;
item.icon_index = task.icon_index;
item.description = task.description;
item.working_dir = task.working_dir;
category.items.push_back(item);
}

View file

@ -23,6 +23,7 @@ bool AppendTask(const JumpListItem& item, IObjectCollection* collection) {
if (FAILED(link.CoCreateInstance(CLSID_ShellLink)) ||
FAILED(link->SetPath(item.path.value().c_str())) ||
FAILED(link->SetArguments(item.arguments.c_str())) ||
FAILED(link->SetWorkingDirectory(item.working_dir.value().c_str())) ||
FAILED(link->SetDescription(item.description.c_str())))
return false;
@ -86,6 +87,8 @@ bool ConvertShellLinkToJumpListItem(IShellLink* shell_link,
if (FAILED(shell_link->GetPath(path, base::size(path), nullptr, 0)))
return false;
item->path = base::FilePath(path);
CComQIPtr<IPropertyStore> property_store = shell_link;
base::win::ScopedPropVariant prop;
if (SUCCEEDED(
@ -99,6 +102,9 @@ bool ConvertShellLinkToJumpListItem(IShellLink* shell_link,
item->title = prop.get().pwszVal;
}
if (SUCCEEDED(shell_link->GetWorkingDirectory(path, base::size(path))))
item->working_dir = base::FilePath(path);
int icon_index;
if (SUCCEEDED(
shell_link->GetIconLocation(path, base::size(path), &icon_index))) {

View file

@ -49,6 +49,7 @@ struct JumpListItem {
base::string16 arguments;
base::string16 title;
base::string16 description;
base::FilePath working_dir;
base::FilePath icon_path;
int icon_index = 0;

View file

@ -26,3 +26,4 @@
resource file contains multiple icons this value can be used to specify the
zero-based index of the icon that should be displayed for this task. If a
resource file contains only one icon, this property should be set to zero.
* `workingDirectory` String (optional) - The working directory. Default is empty.

View file

@ -12,3 +12,4 @@
* `iconIndex` Number - The icon index in the icon file. If an icon file
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.
* `workingDirectory` String (optional) - The working directory. Default is empty.

View file

@ -241,7 +241,8 @@ app.setUserTasks([
iconPath: process.execPath,
iconIndex: 0,
title: 'New Window',
description: 'Create a new window'
description: 'Create a new window',
workingDirectory: path.dirname(process.execPath)
}
])
app.setUserTasks([])
@ -265,7 +266,8 @@ app.setJumpList([
args: '--run-tool-a',
iconPath: process.execPath,
iconIndex: 0,
description: 'Runs Tool A'
description: 'Runs Tool A',
workingDirectory: path.dirname(process.execPath)
},
{
type: 'task',
@ -274,7 +276,8 @@ app.setJumpList([
args: '--run-tool-b',
iconPath: process.execPath,
iconIndex: 0,
description: 'Runs Tool B'
description: 'Runs Tool B',
workingDirectory: path.dirname(process.execPath)
}]
},
{