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

Fix PluginManager crashing after error(s) during plugin execution

This commit is contained in:
chylex 2019-05-27 19:38:53 +02:00
parent dd8c5d27be
commit 108a0fefc3
4 changed files with 14 additions and 8 deletions

View File

@ -65,7 +65,7 @@ public FormBrowser(){
Text = Program.BrandName;
this.plugins = new PluginManager(Program.Config.Plugins, Program.PluginPath);
this.plugins = new PluginManager(this, Program.Config.Plugins, Program.PluginPath);
this.plugins.Reloaded += plugins_Reloaded;
this.plugins.Executed += plugins_Executed;
this.plugins.Reload();

View File

@ -73,7 +73,7 @@ protected FormNotificationMain(FormBrowser owner, PluginManager pluginManager, b
browser.LoadingStateChanged += Browser_LoadingStateChanged;
browser.FrameLoadEnd += Browser_FrameLoadEnd;
plugins.Register(browser, PluginEnvironment.Notification, this);
plugins.Register(browser, PluginEnvironment.Notification);
mouseHookDelegate = MouseHookProc;
Disposed += (sender, args) => StopMouseHook(true);

View File

@ -77,7 +77,7 @@ public TweetDeckBrowser(FormBrowser owner, PluginManager plugins, TweetDeckBridg
this.browser.SetupZoomEvents();
owner.Controls.Add(browser);
plugins.Register(browser, PluginEnvironment.Browser, owner, true);
plugins.Register(browser, PluginEnvironment.Browser, true);
Config.MuteToggled += Config_MuteToggled;
Config.SoundNotificationChanged += Config_SoundNotificationInfoChanged;

View File

@ -29,6 +29,8 @@ sealed class PluginManager{
public event EventHandler<PluginErrorEventArgs> Executed;
private readonly string rootPath;
private readonly Control sync;
private readonly PluginBridge bridge;
private readonly HashSet<Plugin> plugins = new HashSet<Plugin>();
@ -37,20 +39,22 @@ sealed class PluginManager{
private IWebBrowser mainBrowser;
public PluginManager(IPluginConfig config, string rootPath){
public PluginManager(Control sync, IPluginConfig config, string rootPath){
this.Config = config;
this.Config.PluginChangedState += Config_PluginChangedState;
this.rootPath = rootPath;
this.sync = sync;
this.bridge = new PluginBridge(this);
}
public void Register(IWebBrowser browser, PluginEnvironment environment, Control sync, bool asMainBrowser = false){
public void Register(IWebBrowser browser, PluginEnvironment environment, bool asMainBrowser = false){
browser.FrameLoadEnd += (sender, args) => {
IFrame frame = args.Frame;
if (frame.IsMain && TwitterUtils.IsTweetDeckWebsite(frame)){
ExecutePlugins(frame, environment, sync);
ExecutePlugins(frame, environment);
}
};
@ -154,7 +158,7 @@ IEnumerable<Plugin> LoadPluginsFrom(string path, PluginGroup group){
Reloaded?.Invoke(this, new PluginErrorEventArgs(loadErrors));
}
private void ExecutePlugins(IFrame frame, PluginEnvironment environment, Control sync){
private void ExecutePlugins(IFrame frame, PluginEnvironment environment){
if (!HasAnyPlugin(environment) || !ScriptLoader.ExecuteFile(frame, PluginSetupScriptNames[environment], sync)){
return;
}
@ -186,7 +190,9 @@ private void ExecutePlugins(IFrame frame, PluginEnvironment environment, Control
ScriptLoader.ExecuteScript(frame, PluginScriptGenerator.GeneratePlugin(plugin.Identifier, script, GetTokenFromPlugin(plugin), environment), "plugin:"+plugin);
}
Executed?.Invoke(this, new PluginErrorEventArgs(failedPlugins));
sync.InvokeAsyncSafe(() => {
Executed?.Invoke(this, new PluginErrorEventArgs(failedPlugins));
});
}
}
}