mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-22 00:15:48 +02:00
Completely rewrite all image pasting code
This commit is contained in:
parent
35624bcb1c
commit
61b1155a03
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Forms;
|
||||
using TweetDck.Core.Controls;
|
||||
using TweetDck.Core.Notification;
|
||||
using TweetDck.Core.Utils;
|
||||
@ -12,10 +8,9 @@ sealed class TweetDeckBridge{
|
||||
public static string LastRightClickedLink = string.Empty;
|
||||
public static string LastHighlightedTweet = string.Empty;
|
||||
public static string LastHighlightedQuotedTweet = string.Empty;
|
||||
public static string ClipboardImagePath = string.Empty;
|
||||
|
||||
public static void ResetStaticProperties(){
|
||||
LastRightClickedLink = LastHighlightedTweet = LastHighlightedQuotedTweet = ClipboardImagePath = string.Empty;
|
||||
LastRightClickedLink = LastHighlightedTweet = LastHighlightedQuotedTweet = string.Empty;
|
||||
}
|
||||
|
||||
private readonly FormBrowser form;
|
||||
@ -80,30 +75,6 @@ public void LoadNextNotification(){
|
||||
notification.InvokeAsyncSafe(notification.FinishCurrentNotification);
|
||||
}
|
||||
|
||||
public void TryPasteImage(){
|
||||
form.InvokeSafe(() => {
|
||||
if (Clipboard.ContainsImage()){
|
||||
Image img = Clipboard.GetImage();
|
||||
if (img == null)return;
|
||||
|
||||
try{
|
||||
Directory.CreateDirectory(Program.TemporaryPath);
|
||||
|
||||
ClipboardImagePath = Path.Combine(Program.TemporaryPath, "TD-Img-"+DateTime.Now.Ticks+".png");
|
||||
img.Save(ClipboardImagePath, ImageFormat.Png);
|
||||
|
||||
form.OnImagePasted();
|
||||
}catch(Exception e){
|
||||
Program.Reporter.HandleException("Clipboard Image Error", "Could not paste image from clipboard.", true, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void ClickUploadImage(int offsetX, int offsetY){
|
||||
form.InvokeAsyncSafe(() => form.TriggerImageUpload(offsetX, offsetY));
|
||||
}
|
||||
|
||||
public void ScreenshotTweet(string html, int width, int height){
|
||||
form.InvokeAsyncSafe(() => form.OnTweetScreenshotReady(html, width, height));
|
||||
}
|
||||
|
@ -66,7 +66,6 @@ public FormBrowser(PluginManager pluginManager, UpdaterSettings updaterSettings)
|
||||
|
||||
this.browser = new ChromiumWebBrowser("https://tweetdeck.twitter.com/"){
|
||||
MenuHandler = new ContextMenuBrowser(this),
|
||||
DialogHandler = new FileDialogHandler(this),
|
||||
JsDialogHandler = new JavaScriptDialogHandler(),
|
||||
LifeSpanHandler = new LifeSpanHandler()
|
||||
};
|
||||
@ -448,16 +447,6 @@ public void DisplayTooltip(string text){
|
||||
}
|
||||
}
|
||||
|
||||
public void OnImagePasted(){
|
||||
browser.ExecuteScriptAsync("TDGF_tryPasteImage()");
|
||||
}
|
||||
|
||||
public void TriggerImageUpload(int offsetX, int offsetY){
|
||||
IBrowserHost host = browser.GetBrowser().GetHost();
|
||||
host.SendMouseClickEvent(offsetX, offsetY, MouseButtonType.Left, false, 1, CefEventFlags.None);
|
||||
host.SendMouseClickEvent(offsetX, offsetY, MouseButtonType.Left, true, 1, CefEventFlags.None);
|
||||
}
|
||||
|
||||
public void TriggerTweetScreenshot(){
|
||||
browser.ExecuteScriptAsync("TDGF_triggerScreenshot()");
|
||||
}
|
||||
|
@ -1,28 +0,0 @@
|
||||
using CefSharp;
|
||||
using System.Collections.Generic;
|
||||
using TweetDck.Core.Bridge;
|
||||
using TweetDck.Core.Controls;
|
||||
|
||||
namespace TweetDck.Core.Handling{
|
||||
class FileDialogHandler : IDialogHandler{
|
||||
private readonly FormBrowser form;
|
||||
|
||||
public FileDialogHandler(FormBrowser form){
|
||||
this.form = form;
|
||||
}
|
||||
|
||||
public bool OnFileDialog(IWebBrowser browserControl, IBrowser browser, CefFileDialogMode mode, string title, string defaultFilePath, List<string> acceptFilters, int selectedAcceptFilter, IFileDialogCallback callback){
|
||||
if (!string.IsNullOrEmpty(TweetDeckBridge.ClipboardImagePath)){
|
||||
callback.Continue(selectedAcceptFilter, new List<string>{ TweetDeckBridge.ClipboardImagePath });
|
||||
|
||||
form.InvokeSafe(() => {
|
||||
TweetDeckBridge.ClipboardImagePath = string.Empty;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -28,7 +28,6 @@ static class Program{
|
||||
|
||||
public static readonly string ProgramPath = AppDomain.CurrentDomain.BaseDirectory;
|
||||
public static readonly string StoragePath = IsPortable ? Path.Combine(ProgramPath, "portable", "storage") : GetDataStoragePath();
|
||||
public static readonly string TemporaryPath = IsPortable ? Path.Combine(ProgramPath, "portable", "tmp") : Path.Combine(Path.GetTempPath(), BrandName+'_'+Path.GetRandomFileName().Substring(0, 6));
|
||||
|
||||
public static readonly string PluginDataPath = Path.Combine(StoragePath, "TD_Plugins");
|
||||
public static readonly string ConfigFilePath = Path.Combine(StoragePath, "TD_UserConfig.cfg");
|
||||
@ -260,14 +259,6 @@ private static void ExitCleanup(){
|
||||
|
||||
UserConfig.Save();
|
||||
|
||||
try{
|
||||
Directory.Delete(TemporaryPath, true);
|
||||
}catch(DirectoryNotFoundException){
|
||||
}catch(Exception e){
|
||||
// welp, too bad
|
||||
Debug.WriteLine(e.ToString());
|
||||
}
|
||||
|
||||
Cef.Shutdown();
|
||||
BrowserCache.Exit();
|
||||
|
||||
|
@ -405,72 +405,19 @@
|
||||
//
|
||||
// Block: Paste images when tweeting.
|
||||
//
|
||||
(function(){
|
||||
var lastPasteElement;
|
||||
var prevScrollTop;
|
||||
onAppReady.push(function(){
|
||||
var uploader = $._data(document, "events")["uiComposeAddImageClick"][0].handler.context;
|
||||
|
||||
var getScroller = function(){
|
||||
return $(".js-drawer").find(".js-compose-scroller").first().children().first();
|
||||
};
|
||||
|
||||
var clickUpload = function(){
|
||||
$(document).one("uiFilesAdded", function(){
|
||||
getScroller().scrollTop(prevScrollTop);
|
||||
$(".js-drawer").find(".js-compose-text").first()[0].focus();
|
||||
});
|
||||
|
||||
var button = $(".js-add-image-button").first();
|
||||
|
||||
var scroller = getScroller();
|
||||
prevScrollTop = scroller.scrollTop();
|
||||
|
||||
scroller.scrollTop(0);
|
||||
scroller.scrollTop(button.offset().top); // scrolls the button into view
|
||||
|
||||
var buttonPos = button.children().first().offset(); // finds the camera icon offset
|
||||
$TD.clickUploadImage(Math.floor(buttonPos.left), Math.floor(buttonPos.top));
|
||||
};
|
||||
|
||||
app.delegate(".js-compose-text,.js-reply-tweetbox", "paste", function(){
|
||||
lastPasteElement = $(this);
|
||||
$TD.tryPasteImage();
|
||||
});
|
||||
|
||||
window.TDGF_tryPasteImage = function(){
|
||||
if (lastPasteElement){
|
||||
var parent = lastPasteElement.parent();
|
||||
|
||||
if (parent.siblings(".js-add-image-button").length === 0){
|
||||
var pop = parent.closest(".js-inline-reply,.rpl").find(".js-inline-compose-pop,.js-reply-popout");
|
||||
|
||||
if (pop.length === 0){
|
||||
lastPasteElement = null;
|
||||
return;
|
||||
}
|
||||
|
||||
pop.click();
|
||||
|
||||
var drawer = $(".js-drawer");
|
||||
var counter = 0;
|
||||
|
||||
var interval = setInterval(function(){
|
||||
if (drawer.offset().left >= 195){
|
||||
clickUpload();
|
||||
clearInterval(interval);
|
||||
}
|
||||
else if (++counter >= 10){
|
||||
clearInterval(interval);
|
||||
}
|
||||
}, 51);
|
||||
app.delegate(".js-compose-text,.js-reply-tweetbox", "paste", function(e){
|
||||
for(let item of e.originalEvent.clipboardData.items){
|
||||
if (item.type.startsWith("image/")){
|
||||
$(this).closest(".rpl").find(".js-reply-popout").click(); // popout direct messages
|
||||
uploader.addFilesToUpload([ item.getAsFile() ]);
|
||||
break;
|
||||
}
|
||||
else{
|
||||
clickUpload();
|
||||
}
|
||||
|
||||
lastPasteElement = null;
|
||||
}
|
||||
};
|
||||
})();
|
||||
});
|
||||
});
|
||||
|
||||
//
|
||||
// Block: Support for extra mouse buttons.
|
||||
|
@ -109,7 +109,6 @@
|
||||
<DependentUpon>FormNotificationBase.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Core\Handling\ContextMenuNotification.cs" />
|
||||
<Compile Include="Core\Handling\FileDialogHandler.cs" />
|
||||
<Compile Include="Core\Handling\JavaScriptDialogHandler.cs" />
|
||||
<Compile Include="Core\Handling\LifeSpanHandler.cs" />
|
||||
<Compile Include="Core\Notification\FormNotificationTweet.cs">
|
||||
|
Loading…
Reference in New Issue
Block a user