1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-08-18 13:31:41 +02:00

Add a way to register callbacks when $TDX property object gets updated

This commit is contained in:
2020-02-16 14:38:46 +01:00
parent 9480ba26e0
commit c1aefc7163
3 changed files with 18 additions and 2 deletions
Core/Bridge
Resources/Scripts

@@ -12,7 +12,7 @@ namespace TweetDuck.Core.Bridge{
static string Str(string value) => $"\"{value}\";"; static string Str(string value) => $"\"{value}\";";
UserConfig config = Program.Config.User; UserConfig config = Program.Config.User;
StringBuilder build = new StringBuilder(128).Append("(function(x){"); StringBuilder build = new StringBuilder(384).Append("(function(x){");
build.Append("x.expandLinksOnHover=").Append(Bool(config.ExpandLinksOnHover)); build.Append("x.expandLinksOnHover=").Append(Bool(config.ExpandLinksOnHover));
@@ -29,7 +29,7 @@ namespace TweetDuck.Core.Bridge{
build.Append("x.skipOnLinkClick=").Append(Bool(config.NotificationSkipOnLinkClick)); build.Append("x.skipOnLinkClick=").Append(Bool(config.NotificationSkipOnLinkClick));
} }
return build.Append("})(window.$TDX=window.$TDX||{})").ToString(); return build.Append("})(window.$TDX=window.$TDX||{});if(window.TDGF_onPropertiesUpdated)window.TDGF_onPropertiesUpdated()").ToString();
} }
} }
} }

@@ -1716,6 +1716,21 @@
window.TDGF_reload = function(){}; // redefine to prevent reloading multiple times window.TDGF_reload = function(){}; // redefine to prevent reloading multiple times
}; };
//
// Block: Setup global functions to respond to updating $TDX properties.
//
(function(){
var callbacks = [];
window.TDGF_registerPropertyUpdateCallback = function(callback){
callbacks.push(callback);
};
window.TDGF_onPropertiesUpdated = function(){
callbacks.forEach(func => func($TDX));
};
})();
// //
// Block: Disable default TweetDeck update notification. // Block: Disable default TweetDeck update notification.
// //

@@ -123,6 +123,7 @@
window.TDPF_reloadColumns = window.TDGF_reloadColumns; window.TDPF_reloadColumns = window.TDGF_reloadColumns;
window.TDPF_prioritizeNewestEvent = window.TDGF_prioritizeNewestEvent; window.TDPF_prioritizeNewestEvent = window.TDGF_prioritizeNewestEvent;
window.TDPF_injectMustache = window.TDGF_injectMustache; window.TDPF_injectMustache = window.TDGF_injectMustache;
window.TDPF_registerPropertyUpdateCallback = window.TDGF_registerPropertyUpdateCallback;
window.TDPF_playVideo = function(urlOrObject, username){ window.TDPF_playVideo = function(urlOrObject, username){
if (typeof urlOrObject === "string"){ if (typeof urlOrObject === "string"){