jump_list.h 3.8 KB

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