mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-19 18:15:47 +02:00
Move screenshot height calculation to the screenshot window
This commit is contained in:
parent
ebe3868720
commit
3f0b161cd0
@ -1,19 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using TweetDuck.Core.Controls;
|
|
||||||
|
|
||||||
namespace TweetDuck.Core.Bridge{
|
|
||||||
sealed class CallbackBridge{
|
|
||||||
private readonly Control owner;
|
|
||||||
private readonly Action safeCallback;
|
|
||||||
|
|
||||||
public CallbackBridge(Control owner, Action safeCallback){
|
|
||||||
this.owner = owner;
|
|
||||||
this.safeCallback = safeCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Trigger(){
|
|
||||||
owner.InvokeSafe(safeCallback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -117,8 +117,8 @@ public void OnTweetSound(){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ScreenshotTweet(string html, int width, int height){
|
public void ScreenshotTweet(string html, int width){
|
||||||
form.InvokeAsyncSafe(() => form.OnTweetScreenshotReady(html, width, height));
|
form.InvokeAsyncSafe(() => form.OnTweetScreenshotReady(html, width));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayVideo(string url, string username){
|
public void PlayVideo(string url, string username){
|
||||||
|
@ -455,12 +455,12 @@ public void ShowTweetDetail(string columnId, string chirpId, string fallbackUrl)
|
|||||||
AnalyticsFile.TweetDetails.Trigger();
|
AnalyticsFile.TweetDetails.Trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnTweetScreenshotReady(string html, int width, int height){
|
public void OnTweetScreenshotReady(string html, int width){
|
||||||
if (notificationScreenshotManager == null){
|
if (notificationScreenshotManager == null){
|
||||||
notificationScreenshotManager = new TweetScreenshotManager(this, plugins);
|
notificationScreenshotManager = new TweetScreenshotManager(this, plugins);
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationScreenshotManager.Trigger(html, width, height);
|
notificationScreenshotManager.Trigger(html, width);
|
||||||
AnalyticsFile.TweetScreenshots.Trigger();
|
AnalyticsFile.TweetScreenshots.Trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using CefSharp;
|
using CefSharp;
|
||||||
using TweetDuck.Core.Bridge;
|
using TweetDuck.Core.Controls;
|
||||||
using TweetDuck.Core.Other;
|
using TweetDuck.Core.Other;
|
||||||
using TweetDuck.Core.Utils;
|
using TweetDuck.Core.Utils;
|
||||||
using TweetDuck.Data;
|
using TweetDuck.Data;
|
||||||
@ -15,19 +15,26 @@ sealed class FormNotificationScreenshotable : FormNotificationBase{
|
|||||||
protected override bool CanDragWindow => false;
|
protected override bool CanDragWindow => false;
|
||||||
|
|
||||||
private readonly PluginManager plugins;
|
private readonly PluginManager plugins;
|
||||||
|
private readonly int width;
|
||||||
|
|
||||||
public FormNotificationScreenshotable(Action callback, FormBrowser owner, PluginManager pluginManager) : base(owner, false){
|
public FormNotificationScreenshotable(Action callback, FormBrowser owner, PluginManager pluginManager, string html, int width) : base(owner, false){
|
||||||
this.plugins = pluginManager;
|
this.plugins = pluginManager;
|
||||||
|
this.width = width;
|
||||||
|
|
||||||
browser.RegisterAsyncJsObject("$TD_NotificationScreenshot", new CallbackBridge(this, 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){
|
using(IFrame frame = args.Browser.MainFrame){
|
||||||
ScriptLoader.ExecuteScript(frame, "window.setTimeout($TD_NotificationScreenshot.trigger, document.getElementsByTagName('iframe').length ? 267 : 67)", "gen:screenshot");
|
if (!ScriptLoader.ExecuteFile(frame, "screenshot.js")){
|
||||||
|
this.InvokeAsyncSafe(callback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
LoadTweet(new TweetNotification(string.Empty, string.Empty, string.Empty, html, 0, string.Empty, string.Empty));
|
||||||
|
SetScreenshotHeight(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetTweetHTML(TweetNotification tweet){
|
protected override string GetTweetHTML(TweetNotification tweet){
|
||||||
@ -40,12 +47,16 @@ protected override string GetTweetHTML(TweetNotification tweet){
|
|||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadNotificationForScreenshot(TweetNotification tweet, int width, int height){
|
private void SetScreenshotHeight(int height){
|
||||||
LoadTweet(tweet);
|
SetNotificationSize(width, height); // TODO test how it works on high DPI, probably not great?
|
||||||
SetNotificationSize(width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TakeScreenshot(){
|
public void TakeScreenshot(){
|
||||||
|
if (ClientSize.Height == 0){
|
||||||
|
FormMessage.Error("Screenshot Failed", "Could not detect screenshot size.", FormMessage.OK);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
IntPtr context = NativeMethods.GetDC(this.Handle);
|
IntPtr context = NativeMethods.GetDC(this.Handle);
|
||||||
|
|
||||||
if (context == IntPtr.Zero){
|
if (context == IntPtr.Zero){
|
||||||
|
26
Core/Notification/Screenshot/ScreenshotBridge.cs
Normal file
26
Core/Notification/Screenshot/ScreenshotBridge.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using TweetDuck.Core.Controls;
|
||||||
|
|
||||||
|
namespace TweetDuck.Core.Notification.Screenshot{
|
||||||
|
sealed class ScreenshotBridge{
|
||||||
|
private readonly Control owner;
|
||||||
|
|
||||||
|
private readonly Action<int> safeSetHeight;
|
||||||
|
private readonly Action safeTriggerScreenshot;
|
||||||
|
|
||||||
|
public ScreenshotBridge(Control owner, Action<int> safeSetHeight, Action safeTriggerScreenshot){
|
||||||
|
this.owner = owner;
|
||||||
|
this.safeSetHeight = safeSetHeight;
|
||||||
|
this.safeTriggerScreenshot = safeTriggerScreenshot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetHeight(int tweetHeight){
|
||||||
|
owner.InvokeSafe(() => safeSetHeight(tweetHeight));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TriggerScreenshot(){
|
||||||
|
owner.InvokeSafe(safeTriggerScreenshot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -37,13 +37,12 @@ private void disposer_Tick(object sender, EventArgs e){
|
|||||||
screenshot = null;
|
screenshot = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Trigger(string html, int width, int height){
|
public void Trigger(string html, int width){
|
||||||
if (screenshot != null){
|
if (screenshot != null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
screenshot = new FormNotificationScreenshotable(Callback, owner, plugins);
|
screenshot = new FormNotificationScreenshotable(Callback, owner, plugins, html, width);
|
||||||
screenshot.LoadNotificationForScreenshot(new TweetNotification(string.Empty, string.Empty, string.Empty, html, 0, string.Empty, string.Empty), width, height);
|
|
||||||
screenshot.Show();
|
screenshot.Show();
|
||||||
timeout.Start();
|
timeout.Start();
|
||||||
|
|
||||||
|
@ -705,20 +705,7 @@
|
|||||||
html.addClass("td-notification-padded");
|
html.addClass("td-notification-padded");
|
||||||
}
|
}
|
||||||
|
|
||||||
let testTweet = html.clone().css({
|
$TD.screenshotTweet(html[0].outerHTML, columnWidth);
|
||||||
position: "absolute",
|
|
||||||
left: "-999px",
|
|
||||||
width: columnWidth+"px"
|
|
||||||
}).appendTo(document.body);
|
|
||||||
|
|
||||||
let testTweetAvatar = testTweet.find(".tweet-avatar").first();
|
|
||||||
let avatarBottom = testTweetAvatar.length === 1 ? testTweetAvatar.offset().top+testTweetAvatar.height() : 0;
|
|
||||||
|
|
||||||
let realHeight = Math.floor(Math.max(testTweet.height(), avatarBottom+9));
|
|
||||||
testTweet.remove();
|
|
||||||
|
|
||||||
html.find(".js-stream-item-content").first().css("height", "100vh");
|
|
||||||
$TD.screenshotTweet(html[0].outerHTML, columnWidth, realHeight);
|
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
16
Resources/Scripts/screenshot.js
Normal file
16
Resources/Scripts/screenshot.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
(function($TD){
|
||||||
|
document.getElementsByClassName("column")[0].style.height = "100%";
|
||||||
|
|
||||||
|
let ele = document.getElementsByTagName("article")[0];
|
||||||
|
ele.style.width = window.outerWidth+"px";
|
||||||
|
|
||||||
|
ele.style.position = "absolute";
|
||||||
|
let contentHeight = ele.offsetHeight;
|
||||||
|
ele.style.position = "static";
|
||||||
|
|
||||||
|
let avatar = ele.querySelector(".tweet-avatar");
|
||||||
|
let avatarBottom = avatar ? avatar.getBoundingClientRect().bottom : 0;
|
||||||
|
|
||||||
|
$TD.setHeight(Math.floor(Math.max(contentHeight, avatarBottom+9)));
|
||||||
|
setTimeout($TD.triggerScreenshot, document.getElementsByTagName("iframe").length ? 267 : 67);
|
||||||
|
})($TD_NotificationScreenshot);
|
@ -245,7 +245,7 @@
|
|||||||
<Compile Include="Core\Other\Settings\TabSettingsNotifications.Designer.cs">
|
<Compile Include="Core\Other\Settings\TabSettingsNotifications.Designer.cs">
|
||||||
<DependentUpon>TabSettingsNotifications.cs</DependentUpon>
|
<DependentUpon>TabSettingsNotifications.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Core\Bridge\CallbackBridge.cs" />
|
<Compile Include="Core\Notification\Screenshot\ScreenshotBridge.cs" />
|
||||||
<Compile Include="Data\CommandLineArgs.cs" />
|
<Compile Include="Data\CommandLineArgs.cs" />
|
||||||
<Compile Include="Core\Notification\Screenshot\FormNotificationScreenshotable.cs">
|
<Compile Include="Core\Notification\Screenshot\FormNotificationScreenshotable.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
|
Loading…
Reference in New Issue
Block a user