diff --git a/Core/Bridge/TweetDeckBridge.cs b/Core/Bridge/TweetDeckBridge.cs index d81d1a7f..e9069a37 100644 --- a/Core/Bridge/TweetDeckBridge.cs +++ b/Core/Bridge/TweetDeckBridge.cs @@ -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)); } diff --git a/Core/FormBrowser.cs b/Core/FormBrowser.cs index ee184dca..5b4dfb0c 100644 --- a/Core/FormBrowser.cs +++ b/Core/FormBrowser.cs @@ -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()"); } diff --git a/Core/Handling/FileDialogHandler.cs b/Core/Handling/FileDialogHandler.cs deleted file mode 100644 index 03ca95cd..00000000 --- a/Core/Handling/FileDialogHandler.cs +++ /dev/null @@ -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; - } - } -} diff --git a/Program.cs b/Program.cs index 6dd494c9..3ca18500 100644 --- a/Program.cs +++ b/Program.cs @@ -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(); diff --git a/Resources/Scripts/code.js b/Resources/Scripts/code.js index 22985424..90698b78 100644 --- a/Resources/Scripts/code.js +++ b/Resources/Scripts/code.js @@ -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. diff --git a/TweetDck.csproj b/TweetDck.csproj index 41fa121e..713ef5f1 100644 --- a/TweetDck.csproj +++ b/TweetDck.csproj @@ -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">