Skip to content

Commit

Permalink
feat: allow setting working directory in app.setUserTasks() / app.set…
Browse files Browse the repository at this point in the history
…JumpList() (electron#18148)
  • Loading branch information
miniak authored and kiku-jw committed May 16, 2019
1 parent a205a29 commit d81c816
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions atom/browser/api/atom_api_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions atom/browser/browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions atom/browser/browser_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions atom/browser/ui/win/jump_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand All @@ -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))) {
Expand Down
1 change: 1 addition & 0 deletions atom/browser/ui/win/jump_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions docs/api/structures/jump-list-item.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions docs/api/structures/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
9 changes: 6 additions & 3 deletions spec/ts-smoke/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([])
Expand All @@ -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',
Expand All @@ -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)
}]
},
{
Expand Down

0 comments on commit d81c816

Please sign in to comment.