From cc9ba35c51a527ceba69b5e492182ed0c66dabc4 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Fri, 25 Feb 2022 14:17:18 +0100 Subject: [PATCH] fix: tray garbage collection (#33074) Co-authored-by: Shelley Vohr --- shell/browser/api/electron_api_tray.cc | 7 +++++-- shell/browser/api/electron_api_tray.h | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/shell/browser/api/electron_api_tray.cc b/shell/browser/api/electron_api_tray.cc index 72cd816638bde..51ea4c67aa603 100644 --- a/shell/browser/api/electron_api_tray.cc +++ b/shell/browser/api/electron_api_tray.cc @@ -89,8 +89,10 @@ gin::Handle Tray::New(gin_helper::ErrorThrower thrower, } #endif - return gin::CreateHandle(thrower.isolate(), - new Tray(args->isolate(), image, guid)); + auto handle = gin::CreateHandle(args->isolate(), + new Tray(args->isolate(), image, guid)); + handle->Pin(args->isolate()); + return handle; } void Tray::OnClicked(const gfx::Rect& bounds, @@ -180,6 +182,7 @@ void Tray::OnDragEnded() { } void Tray::Destroy() { + Unpin(); menu_.Reset(); tray_icon_.reset(); } diff --git a/shell/browser/api/electron_api_tray.h b/shell/browser/api/electron_api_tray.h index 19a28eef23713..8c4870b11ad89 100644 --- a/shell/browser/api/electron_api_tray.h +++ b/shell/browser/api/electron_api_tray.h @@ -19,6 +19,7 @@ #include "shell/common/gin_helper/cleaned_up_at_exit.h" #include "shell/common/gin_helper/constructible.h" #include "shell/common/gin_helper/error_thrower.h" +#include "shell/common/gin_helper/pinnable.h" namespace gfx { class Image; @@ -38,6 +39,7 @@ class Tray : public gin::Wrappable, public gin_helper::EventEmitterMixin, public gin_helper::Constructible, public gin_helper::CleanedUpAtExit, + public gin_helper::Pinnable, public TrayIconObserver { public: // gin_helper::Constructible