From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <marshallofsound@electronjs.org>
Date: Tue, 13 Feb 2024 17:40:15 -0800
Subject: fix: add support for skipping first 2 no-op refreshes in thumb cap

Fixes a bug in the SCK thumbnail capturer, will be reported upstream for a hopefully
less hacky fix.

The first refresh is "no windows yet, no thumbnails".
The second refresh is "we have windows, we queued the thumbnail requests"
The third refresh (the one we want) is "we have windows, and have thumbnail requests"

This really isn't ideal at all, we need to refactor desktopCapturer (read completely re-implement it)
to use StartUpdating and handle the events instead of using the "get the list once" method.

diff --git a/chrome/browser/media/webrtc/desktop_media_list.h b/chrome/browser/media/webrtc/desktop_media_list.h
index 05e2c0a8c61d55899fbd92c40e495b1581102d2e..f262e311e7bc1ceb6f51242d6b9f40d5b8ffeabd 100644
--- a/chrome/browser/media/webrtc/desktop_media_list.h
+++ b/chrome/browser/media/webrtc/desktop_media_list.h
@@ -148,6 +148,8 @@ class DesktopMediaList {
   // source lists that need to be displayed independently from when the
   // DesktopMediaList gains focus.
   virtual void ShowDelegatedList() = 0;
+
+  int skip_next_refresh_ = 0;
 };
 
 #endif  // CHROME_BROWSER_MEDIA_WEBRTC_DESKTOP_MEDIA_LIST_H_
diff --git a/chrome/browser/media/webrtc/desktop_media_list_base.cc b/chrome/browser/media/webrtc/desktop_media_list_base.cc
index c76fd79c7998b963f8edfed525acac65fcef35f7..09ca689cde5c1cc3257df277f516d924fd171953 100644
--- a/chrome/browser/media/webrtc/desktop_media_list_base.cc
+++ b/chrome/browser/media/webrtc/desktop_media_list_base.cc
@@ -236,7 +236,11 @@ uint32_t DesktopMediaListBase::GetImageHash(const gfx::Image& image) {
 void DesktopMediaListBase::OnRefreshComplete() {
   DCHECK_CURRENTLY_ON(BrowserThread::UI);
   DCHECK(refresh_callback_);
-  std::move(refresh_callback_).Run();
+  if (skip_next_refresh_ > 0) {
+    skip_next_refresh_--;
+  } else {
+    std::move(refresh_callback_).Run();
+  }
 }
 
 void DesktopMediaListBase::ScheduleNextRefresh() {
