jump_list.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 icon_path;
  46. int icon_index = 0;
  47. JumpListItem();
  48. JumpListItem(const JumpListItem&);
  49. ~JumpListItem();
  50. };
  51. struct JumpListCategory {
  52. enum class Type {
  53. // A custom category can contain tasks and files, but not separators.
  54. CUSTOM,
  55. // Frequent/Recent categories are managed by the OS, their name and items
  56. // can't be set by the app (though items can be set indirectly).
  57. FREQUENT,
  58. RECENT,
  59. // The standard Tasks category can't be renamed by the app, but the app
  60. // can set the items that should appear in this category, and those items
  61. // can include tasks, files, and separators.
  62. TASKS
  63. };
  64. Type type = Type::TASKS;
  65. base::string16 name;
  66. std::vector<JumpListItem> items;
  67. JumpListCategory();
  68. JumpListCategory(const JumpListCategory&);
  69. ~JumpListCategory();
  70. };
  71. // Creates or removes a custom Jump List for an app.
  72. // See https://msdn.microsoft.com/en-us/library/windows/desktop/gg281362.aspx
  73. class JumpList {
  74. public:
  75. // |app_id| must be the Application User Model ID of the app for which the
  76. // custom Jump List should be created/removed, it's usually obtained by
  77. // calling GetCurrentProcessExplicitAppUserModelID().
  78. explicit JumpList(const base::string16& app_id);
  79. ~JumpList();
  80. // Starts a new transaction, must be called before appending any categories,
  81. // aborting or committing. After the method returns |min_items| will indicate
  82. // the minimum number of items that will be displayed in the Jump List, and
  83. // |removed_items| (if not null) will contain all the items the user has
  84. // unpinned from the Jump List. Both parameters are optional.
  85. bool Begin(int* min_items = nullptr,
  86. std::vector<JumpListItem>* removed_items = nullptr);
  87. // Abandons any changes queued up since Begin() was called.
  88. bool Abort();
  89. // Commits any changes queued up since Begin() was called.
  90. bool Commit();
  91. // Deletes the custom Jump List and restores the default Jump List.
  92. bool Delete();
  93. // Appends a category to the custom Jump List.
  94. JumpListResult AppendCategory(const JumpListCategory& category);
  95. // Appends categories to the custom Jump List.
  96. JumpListResult AppendCategories(
  97. const std::vector<JumpListCategory>& categories);
  98. private:
  99. base::string16 app_id_;
  100. CComPtr<ICustomDestinationList> destinations_;
  101. DISALLOW_COPY_AND_ASSIGN(JumpList);
  102. };
  103. } // namespace atom
  104. #endif // ATOM_BROWSER_UI_WIN_JUMP_LIST_H_