jump_list.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // Copyright (c) 2016 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_BROWSER_UI_WIN_JUMP_LIST_H_
  5. #define ATOM_BROWSER_UI_WIN_JUMP_LIST_H_
  6. #include <atlbase.h>
  7. #include <shobjidl.h>
  8. #include <vector>
  9. #include "base/files/file_path.h"
  10. #include "base/macros.h"
  11. namespace atom {
  12. enum class JumpListResult : int {
  13. SUCCESS = 0,
  14. // In JS code this error will manifest as an exception.
  15. ARGUMENT_ERROR = 1,
  16. // Generic error, the runtime logs may provide some clues.
  17. GENERIC_ERROR = 2,
  18. // Custom categories can't contain separators.
  19. CUSTOM_CATEGORY_SEPARATOR_ERROR = 3,
  20. // The app isn't registered to handle a file type found in a custom category.
  21. MISSING_FILE_TYPE_REGISTRATION_ERROR = 4,
  22. // Custom categories can't be created due to user privacy settings.
  23. CUSTOM_CATEGORY_ACCESS_DENIED_ERROR = 5,
  24. };
  25. struct JumpListItem {
  26. enum class Type {
  27. // A task will launch an app (usually the one that created the Jump List)
  28. // with specific arguments.
  29. TASK,
  30. // Separators can only be inserted between items in the standard Tasks
  31. // category, they can't appear in custom categories.
  32. SEPARATOR,
  33. // A file link will open a file using the app that created the Jump List,
  34. // for this to work the app must be registered as a handler for the file
  35. // type (though the app doesn't have to be the default handler).
  36. FILE
  37. };
  38. Type type = Type::TASK;
  39. // For tasks this is the path to the program executable, for file links this
  40. // is the full filename.
  41. base::FilePath path;
  42. base::string16 arguments;
  43. base::string16 title;
  44. base::string16 description;
  45. base::FilePath working_dir;
  46. base::FilePath icon_path;
  47. int icon_index = 0;
  48. JumpListItem();
  49. JumpListItem(const JumpListItem&);
  50. ~JumpListItem();
  51. };
  52. struct JumpListCategory {
  53. enum class Type {
  54. // A custom category can contain tasks and files, but not separators.
  55. CUSTOM,
  56. // Frequent/Recent categories are managed by the OS, their name and items
  57. // can't be set by the app (though items can be set indirectly).
  58. FREQUENT,
  59. RECENT,
  60. // The standard Tasks category can't be renamed by the app, but the app
  61. // can set the items that should appear in this category, and those items
  62. // can include tasks, files, and separators.
  63. TASKS
  64. };
  65. Type type = Type::TASKS;
  66. base::string16 name;
  67. std::vector<JumpListItem> items;
  68. JumpListCategory();
  69. JumpListCategory(const JumpListCategory&);
  70. ~JumpListCategory();
  71. };
  72. // Creates or removes a custom Jump List for an app.
  73. // See https://msdn.microsoft.com/en-us/library/windows/desktop/gg281362.aspx
  74. class JumpList {
  75. public:
  76. // |app_id| must be the Application User Model ID of the app for which the
  77. // custom Jump List should be created/removed, it's usually obtained by
  78. // calling GetCurrentProcessExplicitAppUserModelID().
  79. explicit JumpList(const base::string16& app_id);
  80. ~JumpList();
  81. // Starts a new transaction, must be called before appending any categories,
  82. // aborting or committing. After the method returns |min_items| will indicate
  83. // the minimum number of items that will be displayed in the Jump List, and
  84. // |removed_items| (if not null) will contain all the items the user has
  85. // unpinned from the Jump List. Both parameters are optional.
  86. bool Begin(int* min_items = nullptr,
  87. std::vector<JumpListItem>* removed_items = nullptr);
  88. // Abandons any changes queued up since Begin() was called.
  89. bool Abort();
  90. // Commits any changes queued up since Begin() was called.
  91. bool Commit();
  92. // Deletes the custom Jump List and restores the default Jump List.
  93. bool Delete();
  94. // Appends a category to the custom Jump List.
  95. JumpListResult AppendCategory(const JumpListCategory& category);
  96. // Appends categories to the custom Jump List.
  97. JumpListResult AppendCategories(
  98. const std::vector<JumpListCategory>& categories);
  99. private:
  100. base::string16 app_id_;
  101. CComPtr<ICustomDestinationList> destinations_;
  102. DISALLOW_COPY_AND_ASSIGN(JumpList);
  103. };
  104. } // namespace atom
  105. #endif // ATOM_BROWSER_UI_WIN_JUMP_LIST_H_