mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-24 05:34:06 +02:00
Allow plugins to inject HTML into notifications before they're shown
Closes #112
This commit is contained in:
parent
8e0c4f5308
commit
1a73fcdb39
@ -164,12 +164,15 @@ public virtual void ResumeNotification(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual string GetTweetHTML(TweetNotification tweet){
|
||||||
|
string bodyClasses = browser.Bounds.Contains(PointToClient(Cursor.Position)) ? "td-hover" : string.Empty;
|
||||||
|
return tweet.GenerateHtml(bodyClasses);
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void LoadTweet(TweetNotification tweet){
|
protected virtual void LoadTweet(TweetNotification tweet){
|
||||||
CurrentUrl = tweet.Url;
|
CurrentUrl = tweet.Url;
|
||||||
CurrentQuotedTweetUrl = string.Empty; // load from JS
|
CurrentQuotedTweetUrl = string.Empty; // load from JS
|
||||||
|
browser.LoadHtml(GetTweetHTML(tweet), "http://tweetdeck.twitter.com/?"+DateTime.Now.Ticks);
|
||||||
string bodyClasses = browser.Bounds.Contains(PointToClient(Cursor.Position)) ? "td-hover" : string.Empty;
|
|
||||||
browser.LoadHtml(tweet.GenerateHtml(bodyClasses), "http://tweetdeck.twitter.com/?"+DateTime.Now.Ticks);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void SetNotificationSize(int width, int height){
|
protected virtual void SetNotificationSize(int width, int height){
|
||||||
|
@ -200,6 +200,16 @@ public override void ResumeNotification(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override string GetTweetHTML(TweetNotification tweet){
|
||||||
|
string html = base.GetTweetHTML(tweet);
|
||||||
|
|
||||||
|
foreach(InjectedHTML injection in plugins.Bridge.NotificationInjections){
|
||||||
|
html = injection.Inject(html);
|
||||||
|
}
|
||||||
|
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void LoadTweet(TweetNotification tweet){
|
protected override void LoadTweet(TweetNotification tweet){
|
||||||
timerProgress.Stop();
|
timerProgress.Stop();
|
||||||
totalTime = timeLeft = tweet.GetDisplayDuration(Program.UserConfig.NotificationDurationValue);
|
totalTime = timeLeft = tweet.GetDisplayDuration(Program.UserConfig.NotificationDurationValue);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using TweetDck.Core.Utils;
|
using TweetDck.Core.Utils;
|
||||||
@ -13,6 +14,13 @@ private static string SanitizeCacheKey(string key){
|
|||||||
|
|
||||||
private readonly PluginManager manager;
|
private readonly PluginManager manager;
|
||||||
private readonly TwoKeyDictionary<int, string, string> fileCache = new TwoKeyDictionary<int, string, string>(4, 2);
|
private readonly TwoKeyDictionary<int, string, string> fileCache = new TwoKeyDictionary<int, string, string>(4, 2);
|
||||||
|
private readonly TwoKeyDictionary<int, string, InjectedHTML> notificationInjections = new TwoKeyDictionary<int,string,InjectedHTML>(4, 1);
|
||||||
|
|
||||||
|
public IEnumerable<InjectedHTML> NotificationInjections{
|
||||||
|
get{
|
||||||
|
return notificationInjections.InnerValues;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public PluginBridge(PluginManager manager){
|
public PluginBridge(PluginManager manager){
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
@ -20,16 +28,23 @@ public PluginBridge(PluginManager manager){
|
|||||||
this.manager.PluginChangedState += manager_PluginChangedState;
|
this.manager.PluginChangedState += manager_PluginChangedState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Event handlers
|
||||||
|
|
||||||
private void manager_Reloaded(object sender, PluginErrorEventArgs e){
|
private void manager_Reloaded(object sender, PluginErrorEventArgs e){
|
||||||
fileCache.Clear();
|
fileCache.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void manager_PluginChangedState(object sender, PluginChangedStateEventArgs e){
|
private void manager_PluginChangedState(object sender, PluginChangedStateEventArgs e){
|
||||||
if (!e.IsEnabled){
|
if (!e.IsEnabled){
|
||||||
fileCache.Remove(manager.GetTokenFromPlugin(e.Plugin));
|
int token = manager.GetTokenFromPlugin(e.Plugin);
|
||||||
|
|
||||||
|
fileCache.Remove(token);
|
||||||
|
notificationInjections.Remove(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Utility methods
|
||||||
|
|
||||||
private string GetFullPathOrThrow(int token, PluginFolder folder, string path){
|
private string GetFullPathOrThrow(int token, PluginFolder folder, string path){
|
||||||
Plugin plugin = manager.GetPluginFromToken(token);
|
Plugin plugin = manager.GetPluginFromToken(token);
|
||||||
string fullPath = plugin == null ? string.Empty : plugin.GetFullPathIfSafe(folder, path);
|
string fullPath = plugin == null ? string.Empty : plugin.GetFullPathIfSafe(folder, path);
|
||||||
@ -98,5 +113,13 @@ public string ReadFileRoot(int token, string path){
|
|||||||
public bool CheckFileExistsRoot(int token, string path){
|
public bool CheckFileExistsRoot(int token, string path){
|
||||||
return File.Exists(GetFullPathOrThrow(token, PluginFolder.Root, path));
|
return File.Exists(GetFullPathOrThrow(token, PluginFolder.Root, path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void InjectIntoNotificationsBefore(int token, string key, string search, string html){
|
||||||
|
notificationInjections[token, key] = new InjectedHTML(InjectedHTML.Position.Before, search, html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InjectIntoNotificationsAfter(int token, string key, string search, string html){
|
||||||
|
notificationInjections[token, key] = new InjectedHTML(InjectedHTML.Position.After, search, html);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user