1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-03 14:34:08 +02:00

Improve screenshot reliability

This commit is contained in:
chylex 2018-04-15 16:24:26 +02:00
parent 762717da1e
commit c064ef7a30
2 changed files with 19 additions and 11 deletions
Core/Notification/Screenshot
Resources/Scripts

View File

@ -24,19 +24,26 @@ public FormNotificationScreenshotable(Action callback, FormBrowser owner, Plugin
browser.RegisterAsyncJsObject("$TD_NotificationScreenshot", new ScreenshotBridge(this, SetScreenshotHeight, callback)); browser.RegisterAsyncJsObject("$TD_NotificationScreenshot", new ScreenshotBridge(this, SetScreenshotHeight, callback));
browser.LoadingStateChanged += (sender, args) => { browser.LoadingStateChanged += (sender, args) => {
if (!args.IsLoading){ if (args.IsLoading){
using(IFrame frame = args.Browser.MainFrame){ return;
if (!ScriptLoader.ExecuteFile(frame, "screenshot.js")){ }
this.InvokeAsyncSafe(callback);
} string script = ScriptLoader.LoadResource("screenshot.js", true);
}
if (script == null){
this.InvokeAsyncSafe(callback);
return;
}
using(IFrame frame = args.Browser.MainFrame){
ScriptLoader.ExecuteScript(frame, script.Replace("{width}", ClientSize.Width.ToString()), "screenshot");
} }
}; };
LoadTweet(new TweetNotification(string.Empty, string.Empty, string.Empty, html, 0, string.Empty, string.Empty));
SetScreenshotHeight(1); SetScreenshotHeight(1);
LoadTweet(new TweetNotification(string.Empty, string.Empty, string.Empty, html, 0, string.Empty, string.Empty));
} }
protected override string GetTweetHTML(TweetNotification tweet){ protected override string GetTweetHTML(TweetNotification tweet){
string html = tweet.GenerateHtml("td-screenshot"); string html = tweet.GenerateHtml("td-screenshot");

View File

@ -1,6 +1,6 @@
(function($TD){ (function($TD){
let ele = document.getElementsByTagName("article")[0]; let ele = document.getElementsByTagName("article")[0];
ele.style.width = window.innerWidth+"px"; ele.style.width = "{width}px";
ele.style.position = "absolute"; ele.style.position = "absolute";
let contentHeight = ele.offsetHeight; let contentHeight = ele.offsetHeight;
@ -9,6 +9,7 @@
let avatar = ele.querySelector(".tweet-avatar"); let avatar = ele.querySelector(".tweet-avatar");
let avatarBottom = avatar ? avatar.getBoundingClientRect().bottom : 0; let avatarBottom = avatar ? avatar.getBoundingClientRect().bottom : 0;
$TD.setHeight(Math.floor(Math.max(contentHeight, avatarBottom+9))); $TD.setHeight(Math.floor(Math.max(contentHeight, avatarBottom+9))).then(() => {
setTimeout($TD.triggerScreenshot, document.getElementsByTagName("iframe").length ? 267 : 67); setTimeout($TD.triggerScreenshot, document.getElementsByTagName("iframe").length ? 267 : 67);
});
})($TD_NotificationScreenshot); })($TD_NotificationScreenshot);