Browse Source

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

Milan Burda 6 years ago
parent
commit
3a5e6f2551

+ 3 - 0
atom/browser/api/atom_api_app.cc

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

+ 1 - 0
atom/browser/browser.h

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

+ 1 - 0
atom/browser/browser_win.cc

@@ -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);
   }
 

+ 6 - 0
atom/browser/ui/win/jump_list.cc

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

+ 1 - 0
atom/browser/ui/win/jump_list.h

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

+ 1 - 0
docs/api/structures/jump-list-item.md

@@ -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 - 0
docs/api/structures/task.md

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

+ 6 - 3
spec/ts-smoke/electron/main.ts

@@ -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)
       }]
   },
   {