1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-08 11:34:05 +02:00

Split plugins.js into separate browser and notification scripts and refactor notification script execution code

This commit is contained in:
chylex 2016-07-01 23:53:08 +02:00
parent 19f9614c74
commit d9321a9acb
5 changed files with 50 additions and 14 deletions

View File

@ -12,6 +12,11 @@
namespace TweetDck.Core{
sealed partial class FormNotification : Form{
private const string NotificationScriptFile = "notification.js";
private static readonly string NotificationScriptIdentifier = ScriptLoader.GetRootIdentifier(NotificationScriptFile);
private static readonly string PluginScriptIdentifier = ScriptLoader.GetRootIdentifier(PluginManager.PluginNotificationScriptFile);
public Func<bool> CanMoveWindow = () => true;
private readonly Form owner;
@ -24,6 +29,7 @@ sealed partial class FormNotification : Form{
private int timeLeft, totalTime;
private readonly string notificationJS;
private readonly string pluginJS;
protected override bool ShowWithoutActivation{
get{
@ -61,7 +67,8 @@ public FormNotification(Form owner, TweetDeckBridge bridge, PluginManager plugin
owner.FormClosed += (sender, args) => Close();
notificationJS = ScriptLoader.LoadResource("notification.js");
notificationJS = ScriptLoader.LoadResource(NotificationScriptFile);
pluginJS = ScriptLoader.LoadResource(PluginManager.PluginNotificationScriptFile);
browser = new ChromiumWebBrowser("about:blank"){ MenuHandler = new ContextMenuNotification(this,autoHide) };
browser.FrameLoadEnd += Browser_FrameLoadEnd;
@ -114,9 +121,12 @@ private void Config_MuteToggled(object sender, EventArgs e){
private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){
if (e.Frame.IsMain && notificationJS != null && browser.Address != "about:blank"){
ScriptLoader.ExecuteScript(e.Frame,notificationJS,"root:notification");
ScriptLoader.ExecuteFile(e.Frame,PluginManager.PluginScriptFile);
plugins.ExecutePlugins(e.Frame,PluginEnvironment.Notification);
ScriptLoader.ExecuteScript(e.Frame,notificationJS,NotificationScriptIdentifier);
if (plugins.HasAnyPlugin(PluginEnvironment.Notification)){
ScriptLoader.ExecuteScript(e.Frame,pluginJS,PluginScriptIdentifier);
plugins.ExecutePlugins(e.Frame,PluginEnvironment.Notification);
}
}
}

View File

@ -8,7 +8,8 @@
namespace TweetDck.Plugins{
class PluginManager{
public const string PluginScriptFile = "plugins.js";
public const string PluginBrowserScriptFile = "plugins.browser.js";
public const string PluginNotificationScriptFile = "plugins.notification.js";
public string PathOfficialPlugins { get { return Path.Combine(rootPath,"official"); } }
public string PathCustomPlugins { get { return Path.Combine(rootPath,"user"); } }

View File

@ -116,13 +116,4 @@
$TD.setNotificationTweetEmbedded(account[0].getAttribute("href")+"/status/"+tweetId);
})();
//
// Block: Load plugins.
//
window.TD_APP_READY = true;
if (window.TD_PLUGINS){
window.TD_PLUGINS.onReady();
}
})($TD);

View File

@ -0,0 +1,34 @@
(function(){
//
// Class: Abstract plugin base class.
//
window.PluginBase = class{
constructor(pluginSettings){
this.$pluginSettings = pluginSettings || {};
}
run(){}
};
//
// Variable: Main object for containing and managing plugins.
//
window.TD_PLUGINS = new class{
constructor(){
this.installed = [];
this.disabled = [];
}
isDisabled(plugin){
return this.disabled.includes(plugin.id);
}
install(plugin){
this.installed.push(plugin);
if (!this.isDisabled(plugin)){
plugin.obj.run();
}
}
};
})();