channel_indicator_utils.cc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/system/channel_indicator/channel_indicator_utils.h"
  5. #include <string>
  6. #include "ash/public/cpp/style/dark_light_mode_controller.h"
  7. #include "ash/resources/vector_icons/vector_icons.h"
  8. #include "ash/shell.h"
  9. #include "ash/shell_delegate.h"
  10. #include "ash/strings/grit/ash_strings.h"
  11. #include "base/notreached.h"
  12. #include "base/strings/strcat.h"
  13. #include "base/strings/utf_string_conversions.h"
  14. #include "ui/base/l10n/l10n_util.h"
  15. #include "ui/gfx/color_palette.h"
  16. namespace ash::channel_indicator_utils {
  17. bool IsDisplayableChannel(version_info::Channel channel) {
  18. switch (channel) {
  19. case version_info::Channel::BETA:
  20. case version_info::Channel::DEV:
  21. case version_info::Channel::CANARY:
  22. return true;
  23. case version_info::Channel::STABLE:
  24. case version_info::Channel::UNKNOWN:
  25. return false;
  26. }
  27. }
  28. int GetChannelNameStringResourceID(version_info::Channel channel,
  29. bool append_channel) {
  30. switch (channel) {
  31. case version_info::Channel::BETA:
  32. return append_channel ? IDS_ASH_STATUS_TRAY_CHANNEL_BETA_CHANNEL
  33. : IDS_ASH_STATUS_TRAY_CHANNEL_BETA;
  34. case version_info::Channel::DEV:
  35. return append_channel ? IDS_ASH_STATUS_TRAY_CHANNEL_DEV_CHANNEL
  36. : IDS_ASH_STATUS_TRAY_CHANNEL_DEV;
  37. case version_info::Channel::CANARY:
  38. return append_channel ? IDS_ASH_STATUS_TRAY_CHANNEL_CANARY_CHANNEL
  39. : IDS_ASH_STATUS_TRAY_CHANNEL_CANARY;
  40. // Handle STABLE/UNKNOWN here to satisfy the compiler without using
  41. // "default," but the DCHECK() above will bark if that value is ever
  42. // actually passed in.
  43. case version_info::Channel::STABLE:
  44. case version_info::Channel::UNKNOWN:
  45. return -1;
  46. }
  47. }
  48. SkColor GetFgColor(version_info::Channel channel) {
  49. bool is_dark_mode_enabled =
  50. DarkLightModeController::Get()->IsDarkModeEnabled();
  51. switch (channel) {
  52. case version_info::Channel::BETA:
  53. return is_dark_mode_enabled ? gfx::kGoogleBlue200 : gfx::kGoogleBlue900;
  54. case version_info::Channel::DEV:
  55. return is_dark_mode_enabled ? gfx::kGoogleGreen200 : gfx::kGoogleGreen900;
  56. case version_info::Channel::CANARY:
  57. return is_dark_mode_enabled ? gfx::kGoogleYellow200 : gfx::kGoogleGrey900;
  58. case version_info::Channel::STABLE:
  59. case version_info::Channel::UNKNOWN:
  60. return SkColorSetRGB(0x00, 0x00, 0x00);
  61. }
  62. }
  63. SkColor GetBgColor(version_info::Channel channel) {
  64. bool is_dark_mode_enabled =
  65. DarkLightModeController::Get()->IsDarkModeEnabled();
  66. switch (channel) {
  67. case version_info::Channel::BETA:
  68. return is_dark_mode_enabled ? SkColorSetA(gfx::kGoogleBlue300, 0x55)
  69. : gfx::kGoogleBlue200;
  70. case version_info::Channel::DEV:
  71. return is_dark_mode_enabled ? SkColorSetA(gfx::kGoogleGreen300, 0x55)
  72. : gfx::kGoogleGreen200;
  73. case version_info::Channel::CANARY:
  74. return is_dark_mode_enabled ? SkColorSetA(gfx::kGoogleYellow300, 0x55)
  75. : gfx::kGoogleYellow200;
  76. case version_info::Channel::STABLE:
  77. case version_info::Channel::UNKNOWN:
  78. return SkColorSetRGB(0x00, 0x00, 0x00);
  79. }
  80. }
  81. std::u16string GetFullReleaseTrackString(version_info::Channel channel) {
  82. if (!IsDisplayableChannel(channel))
  83. return std::u16string();
  84. return base::StrCat(
  85. {l10n_util::GetStringUTF16(
  86. channel_indicator_utils::GetChannelNameStringResourceID(channel,
  87. false)),
  88. u" ",
  89. base::UTF8ToUTF16(Shell::Get()->shell_delegate()->GetVersionString())});
  90. }
  91. const gfx::VectorIcon& GetVectorIcon(version_info::Channel channel) {
  92. DCHECK(IsDisplayableChannel(channel));
  93. switch (channel) {
  94. case version_info::Channel::BETA:
  95. return kChannelBetaIcon;
  96. case version_info::Channel::DEV:
  97. return kChannelDevIcon;
  98. case version_info::Channel::CANARY:
  99. return kChannelCanaryIcon;
  100. case version_info::Channel::UNKNOWN:
  101. case version_info::Channel::STABLE:
  102. NOTREACHED();
  103. return kChannelCanaryIcon;
  104. }
  105. }
  106. } // namespace ash::channel_indicator_utils