fix: fallback to GtkStatusIcon when app indicator is not supported (#36815)

* chore: get ready for multi backend tray

* fix: fallback to GtkStatusIcon when app indicator is not supported

* chore: use smart pointers
This commit is contained in:
Cheng Zhao 2023-01-26 19:15:55 +09:00 committed by GitHub
parent 7d46d3ec9d
commit c303135b02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 377 additions and 111 deletions

View file

@ -0,0 +1,52 @@
// Copyright (c) 2023 Microsoft, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_BROWSER_UI_STATUS_ICON_GTK_H_
#define ELECTRON_SHELL_BROWSER_UI_STATUS_ICON_GTK_H_
#include <memory>
#include "ui/base/glib/glib_integers.h"
#include "ui/base/glib/glib_signal.h"
#include "ui/base/glib/scoped_gobject.h"
#include "ui/linux/status_icon_linux.h"
typedef struct _GtkStatusIcon GtkStatusIcon;
namespace electron {
namespace gtkui {
class MenuGtk;
}
class StatusIconGtk : public ui::StatusIconLinux {
public:
StatusIconGtk();
StatusIconGtk(const StatusIconGtk&) = delete;
StatusIconGtk& operator=(const StatusIconGtk&) = delete;
~StatusIconGtk() override;
// ui::StatusIconLinux:
void SetIcon(const gfx::ImageSkia& image) override;
void SetToolTip(const std::u16string& tool_tip) override;
void UpdatePlatformContextMenu(ui::MenuModel* model) override;
void RefreshPlatformContextMenu() override;
void OnSetDelegate() override;
private:
CHROMEG_CALLBACK_0(StatusIconGtk, void, OnClick, GtkStatusIcon*);
CHROMEG_CALLBACK_2(StatusIconGtk,
void,
OnContextMenuRequested,
GtkStatusIcon*,
guint,
guint);
std::unique_ptr<gtkui::MenuGtk> menu_;
ScopedGObject<GtkStatusIcon> icon_;
};
} // namespace electron
#endif // ELECTRON_SHELL_BROWSER_UI_STATUS_ICON_GTK_H_