mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-23 03:15:48 +02:00
Rewrite notification handling (better URL and duration handling, remove hacky code)
This commit is contained in:
parent
81bf93e5ab
commit
064673ef23
Core
Bridge
Handling
Notification
Resources/Scripts
@ -49,18 +49,14 @@ public void SetLastHighlightedTweet(string link, string quotedLink){
|
||||
});
|
||||
}
|
||||
|
||||
public void SetNotificationQuotedTweet(string link){
|
||||
notification.InvokeAsyncSafe(() => notification.CurrentQuotedTweetUrl = link);
|
||||
}
|
||||
|
||||
public void OpenContextMenu(){
|
||||
form.InvokeAsyncSafe(form.OpenContextMenu);
|
||||
}
|
||||
|
||||
public void OnTweetPopup(string columnName, string tweetHtml, string tweetUrl, int tweetCharacters){
|
||||
public void OnTweetPopup(string columnName, string tweetHtml, int tweetCharacters, string tweetUrl, string quoteUrl){
|
||||
notification.InvokeAsyncSafe(() => {
|
||||
form.OnTweetNotification();
|
||||
notification.ShowNotification(new TweetNotification(columnName, tweetHtml, tweetUrl, tweetCharacters));
|
||||
notification.ShowNotification(new TweetNotification(columnName, tweetHtml, tweetCharacters, tweetUrl, quoteUrl));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -33,10 +33,10 @@ public override void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser br
|
||||
model.SetChecked((CefMenuCommand)MenuFreeze, form.FreezeTimer);
|
||||
model.AddSeparator();
|
||||
|
||||
if (!string.IsNullOrEmpty(form.CurrentUrl)){
|
||||
if (!string.IsNullOrEmpty(form.CurrentTweetUrl)){
|
||||
model.AddItem((CefMenuCommand)MenuCopyTweetUrl, "Copy tweet address");
|
||||
|
||||
if (!string.IsNullOrEmpty(form.CurrentQuotedTweetUrl)){
|
||||
if (!string.IsNullOrEmpty(form.CurrentQuoteUrl)){
|
||||
model.AddItem((CefMenuCommand)MenuCopyQuotedTweetUrl, "Copy quoted tweet address");
|
||||
}
|
||||
|
||||
@ -68,11 +68,11 @@ public override bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser b
|
||||
return true;
|
||||
|
||||
case MenuCopyTweetUrl:
|
||||
SetClipboardText(form.CurrentUrl);
|
||||
SetClipboardText(form.CurrentTweetUrl);
|
||||
return true;
|
||||
|
||||
case MenuCopyQuotedTweetUrl:
|
||||
SetClipboardText(form.CurrentQuotedTweetUrl);
|
||||
SetClipboardText(form.CurrentQuoteUrl);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -90,8 +90,8 @@ protected override bool ShowWithoutActivation{
|
||||
|
||||
public bool FreezeTimer { get; set; }
|
||||
public bool ContextMenuOpen { get; set; }
|
||||
public string CurrentUrl { get; private set; }
|
||||
public string CurrentQuotedTweetUrl { get; set; }
|
||||
public string CurrentTweetUrl { get; private set; }
|
||||
public string CurrentQuoteUrl { get; private set; }
|
||||
|
||||
public event EventHandler Initialized;
|
||||
|
||||
@ -179,8 +179,8 @@ protected virtual string GetTweetHTML(TweetNotification tweet){
|
||||
}
|
||||
|
||||
protected virtual void LoadTweet(TweetNotification tweet){
|
||||
CurrentUrl = tweet.Url;
|
||||
CurrentQuotedTweetUrl = string.Empty; // load from JS
|
||||
CurrentTweetUrl = tweet.TweetUrl;
|
||||
CurrentQuoteUrl = tweet.QuoteUrl;
|
||||
currentColumn = tweet.Column;
|
||||
|
||||
resourceHandler.SetHTML(GetTweetHTML(tweet));
|
||||
|
@ -44,7 +44,7 @@ public void Trigger(string html, int width, int height){
|
||||
CanMoveWindow = () => false
|
||||
};
|
||||
|
||||
screenshot.LoadNotificationForScreenshot(new TweetNotification(string.Empty, html, string.Empty, 0), width, height);
|
||||
screenshot.LoadNotificationForScreenshot(new TweetNotification(string.Empty, html, 0, string.Empty, string.Empty), width, height);
|
||||
screenshot.Show();
|
||||
timeout.Start();
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public static TweetNotification ExampleTweet{
|
||||
#endif
|
||||
}
|
||||
|
||||
return new TweetNotification("Home", ExampleTweetHTML, "", 95, true);
|
||||
return new TweetNotification("Home", ExampleTweetHTML, 95, string.Empty, string.Empty, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,24 +57,32 @@ public string Column{
|
||||
}
|
||||
}
|
||||
|
||||
public string Url{
|
||||
public string TweetUrl{
|
||||
get{
|
||||
return url;
|
||||
return tweetUrl;
|
||||
}
|
||||
}
|
||||
|
||||
public string QuoteUrl{
|
||||
get{
|
||||
return quoteUrl;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly string column;
|
||||
private readonly string html;
|
||||
private readonly string url;
|
||||
private readonly int characters;
|
||||
private readonly string tweetUrl;
|
||||
private readonly string quoteUrl;
|
||||
private readonly bool isExample;
|
||||
|
||||
public TweetNotification(string column, string html, string url, int characters) : this(column, html, url, characters, false){}
|
||||
public TweetNotification(string column, string html, int characters, string tweetUrl, string quoteUrl) : this(column, html, characters, tweetUrl, quoteUrl, false){}
|
||||
|
||||
private TweetNotification(string column, string html, string url, int characters, bool isExample){
|
||||
private TweetNotification(string column, string html, int characters, string tweetUrl, string quoteUrl, bool isExample){
|
||||
this.column = column;
|
||||
this.html = html;
|
||||
this.url = url;
|
||||
this.tweetUrl = tweetUrl;
|
||||
this.quoteUrl = quoteUrl;
|
||||
this.characters = characters;
|
||||
this.isExample = isExample;
|
||||
}
|
||||
|
@ -96,10 +96,12 @@
|
||||
html.find(".js-media").last().remove(); // and quoted tweets still show media previews, nice nice
|
||||
html.find(".js-quote-detail").removeClass("is-actionable");
|
||||
|
||||
let url = html.find("time").first().children("a").first().attr("href") || "";
|
||||
let length = tweet.text.length+(tweet.quotedTweet ? tweet.quotedTweet.text.length : 0);
|
||||
let source = tweet.getRelatedTweet();
|
||||
let duration = source ? source.text.length+(source.quotedTweet ? source.quotedTweet.text.length : 0) : tweet.text.length;
|
||||
let tweetUrl = source ? source.getChirpURL() : "";
|
||||
let quoteUrl = source && source.quotedTweet ? source.quotedTweet.getChirpURL() : "";
|
||||
|
||||
$TD.onTweetPopup(columnTypes[column.getColumnType()] || "", html.html(), url, length);
|
||||
$TD.onTweetPopup(columnTypes[column.getColumnType()] || "", html.html(), duration, tweetUrl, quoteUrl);
|
||||
}
|
||||
|
||||
if (column.model.getHasSound()){
|
||||
|
@ -101,22 +101,6 @@
|
||||
});
|
||||
})();
|
||||
|
||||
//
|
||||
// Block: Setup embedded tweet address for context menu.
|
||||
//
|
||||
(function(){
|
||||
var embedded = document.getElementsByClassName("quoted-tweet");
|
||||
if (embedded.length === 0)return;
|
||||
|
||||
var tweetId = embedded[0].getAttribute("data-tweet-id");
|
||||
if (!tweetId)return;
|
||||
|
||||
var account = embedded[0].getElementsByClassName("account-link");
|
||||
if (account.length === 0)return;
|
||||
|
||||
$TD.setNotificationQuotedTweet(account[0].getAttribute("href")+"/status/"+tweetId);
|
||||
})();
|
||||
|
||||
//
|
||||
// Block: Setup a skip button.
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user