From 97f42ead66c528030db21de1c4c052ebd1e7812c Mon Sep 17 00:00:00 2001
From: chylex <contact@chylex.com>
Date: Wed, 30 May 2018 19:50:11 +0200
Subject: [PATCH] Make it easier to debug screenshots

---
 .../Notification/Screenshot/FormNotificationScreenshotable.cs | 2 +-
 Core/Notification/Screenshot/TweetScreenshotManager.cs        | 4 ++++
 Resources/Scripts/screenshot.js                               | 2 +-
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/Core/Notification/Screenshot/FormNotificationScreenshotable.cs b/Core/Notification/Screenshot/FormNotificationScreenshotable.cs
index b0c5dc72..802ca412 100644
--- a/Core/Notification/Screenshot/FormNotificationScreenshotable.cs
+++ b/Core/Notification/Screenshot/FormNotificationScreenshotable.cs
@@ -35,7 +35,7 @@ public FormNotificationScreenshotable(Action callback, FormBrowser owner, Plugin
                 }
                 
                 using(IFrame frame = args.Browser.MainFrame){
-                    ScriptLoader.ExecuteScript(frame, script.Replace("{width}", BrowserUtils.Scale(width, DpiScale).ToString()), "screenshot");
+                    ScriptLoader.ExecuteScript(frame, script.Replace("{width}", BrowserUtils.Scale(width, DpiScale).ToString()).Replace("{frames}", TweetScreenshotManager.WaitFrames.ToString()), "gen:screenshot");
                 }
             };
             
diff --git a/Core/Notification/Screenshot/TweetScreenshotManager.cs b/Core/Notification/Screenshot/TweetScreenshotManager.cs
index 8a1d48c4..3fa2cd56 100644
--- a/Core/Notification/Screenshot/TweetScreenshotManager.cs
+++ b/Core/Notification/Screenshot/TweetScreenshotManager.cs
@@ -27,6 +27,10 @@ sealed class TweetScreenshotManager : IDisposable{
         #if GEN_SCREENSHOT_FRAMES
         private readonly Timer debugger;
         private int frameCounter;
+
+        public const int WaitFrames = 60;
+        #else
+        public const int WaitFrames = 5;
         #endif
         
         private FormNotificationScreenshotable screenshot;
diff --git a/Resources/Scripts/screenshot.js b/Resources/Scripts/screenshot.js
index e9fc0e54..2c295b60 100644
--- a/Resources/Scripts/screenshot.js
+++ b/Resources/Scripts/screenshot.js
@@ -10,7 +10,7 @@
   let avatarBottom = avatar ? avatar.getBoundingClientRect().bottom : 0;
   
   $TD.setHeight(Math.floor(Math.max(contentHeight, avatarBottom+9))).then(() => {
-    let framesLeft = 5; // basic render is done in 1 frame, large media take longer
+    let framesLeft = {frames}; // basic render is done in 1 frame, large media take longer
     
     let onNextFrame = function(){
       if (--framesLeft < 0){