tray_icon_gtk.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (c) 2014 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/browser/ui/tray_icon_gtk.h"
  5. #include "base/strings/stringprintf.h"
  6. #include "base/strings/utf_string_conversions.h"
  7. #include "shell/browser/browser.h"
  8. #include "shell/browser/ui/gtk/status_icon.h"
  9. #include "shell/common/application_info.h"
  10. #include "ui/gfx/image/image.h"
  11. #include "ui/gfx/image/image_skia_operations.h"
  12. namespace electron {
  13. TrayIconGtk::TrayIconGtk() = default;
  14. TrayIconGtk::~TrayIconGtk() = default;
  15. void TrayIconGtk::SetImage(const gfx::Image& image) {
  16. image_ = image.AsImageSkia();
  17. if (icon_) {
  18. icon_->SetIcon(image_);
  19. return;
  20. }
  21. tool_tip_ = base::UTF8ToUTF16(GetApplicationName());
  22. icon_ = gtkui::CreateLinuxStatusIcon(image_, tool_tip_,
  23. Browser::Get()->GetName().c_str());
  24. icon_->SetDelegate(this);
  25. }
  26. void TrayIconGtk::SetToolTip(const std::string& tool_tip) {
  27. tool_tip_ = base::UTF8ToUTF16(tool_tip);
  28. icon_->SetToolTip(tool_tip_);
  29. }
  30. void TrayIconGtk::SetContextMenu(ElectronMenuModel* menu_model) {
  31. menu_model_ = menu_model;
  32. icon_->UpdatePlatformContextMenu(menu_model_);
  33. }
  34. const gfx::ImageSkia& TrayIconGtk::GetImage() const {
  35. return image_;
  36. }
  37. const std::u16string& TrayIconGtk::GetToolTip() const {
  38. return tool_tip_;
  39. }
  40. ui::MenuModel* TrayIconGtk::GetMenuModel() const {
  41. return menu_model_;
  42. }
  43. void TrayIconGtk::OnImplInitializationFailed() {}
  44. void TrayIconGtk::OnClick() {
  45. NotifyClicked();
  46. }
  47. bool TrayIconGtk::HasClickAction() {
  48. return false;
  49. }
  50. // static
  51. TrayIcon* TrayIcon::Create(absl::optional<UUID> guid) {
  52. return new TrayIconGtk;
  53. }
  54. } // namespace electron