mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-19 08:34:08 +02:00
Fix PluginManager crashing after error(s) during plugin execution
This commit is contained in:
parent
dd8c5d27be
commit
108a0fefc3
@ -65,7 +65,7 @@ public FormBrowser(){
|
|||||||
|
|
||||||
Text = Program.BrandName;
|
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.Reloaded += plugins_Reloaded;
|
||||||
this.plugins.Executed += plugins_Executed;
|
this.plugins.Executed += plugins_Executed;
|
||||||
this.plugins.Reload();
|
this.plugins.Reload();
|
||||||
|
@ -73,7 +73,7 @@ protected FormNotificationMain(FormBrowser owner, PluginManager pluginManager, b
|
|||||||
browser.LoadingStateChanged += Browser_LoadingStateChanged;
|
browser.LoadingStateChanged += Browser_LoadingStateChanged;
|
||||||
browser.FrameLoadEnd += Browser_FrameLoadEnd;
|
browser.FrameLoadEnd += Browser_FrameLoadEnd;
|
||||||
|
|
||||||
plugins.Register(browser, PluginEnvironment.Notification, this);
|
plugins.Register(browser, PluginEnvironment.Notification);
|
||||||
|
|
||||||
mouseHookDelegate = MouseHookProc;
|
mouseHookDelegate = MouseHookProc;
|
||||||
Disposed += (sender, args) => StopMouseHook(true);
|
Disposed += (sender, args) => StopMouseHook(true);
|
||||||
|
@ -77,7 +77,7 @@ public TweetDeckBrowser(FormBrowser owner, PluginManager plugins, TweetDeckBridg
|
|||||||
this.browser.SetupZoomEvents();
|
this.browser.SetupZoomEvents();
|
||||||
|
|
||||||
owner.Controls.Add(browser);
|
owner.Controls.Add(browser);
|
||||||
plugins.Register(browser, PluginEnvironment.Browser, owner, true);
|
plugins.Register(browser, PluginEnvironment.Browser, true);
|
||||||
|
|
||||||
Config.MuteToggled += Config_MuteToggled;
|
Config.MuteToggled += Config_MuteToggled;
|
||||||
Config.SoundNotificationChanged += Config_SoundNotificationInfoChanged;
|
Config.SoundNotificationChanged += Config_SoundNotificationInfoChanged;
|
||||||
|
@ -29,6 +29,8 @@ sealed class PluginManager{
|
|||||||
public event EventHandler<PluginErrorEventArgs> Executed;
|
public event EventHandler<PluginErrorEventArgs> Executed;
|
||||||
|
|
||||||
private readonly string rootPath;
|
private readonly string rootPath;
|
||||||
|
|
||||||
|
private readonly Control sync;
|
||||||
private readonly PluginBridge bridge;
|
private readonly PluginBridge bridge;
|
||||||
|
|
||||||
private readonly HashSet<Plugin> plugins = new HashSet<Plugin>();
|
private readonly HashSet<Plugin> plugins = new HashSet<Plugin>();
|
||||||
@ -37,20 +39,22 @@ sealed class PluginManager{
|
|||||||
|
|
||||||
private IWebBrowser mainBrowser;
|
private IWebBrowser mainBrowser;
|
||||||
|
|
||||||
public PluginManager(IPluginConfig config, string rootPath){
|
public PluginManager(Control sync, IPluginConfig config, string rootPath){
|
||||||
this.Config = config;
|
this.Config = config;
|
||||||
this.Config.PluginChangedState += Config_PluginChangedState;
|
this.Config.PluginChangedState += Config_PluginChangedState;
|
||||||
|
|
||||||
this.rootPath = rootPath;
|
this.rootPath = rootPath;
|
||||||
|
|
||||||
|
this.sync = sync;
|
||||||
this.bridge = new PluginBridge(this);
|
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) => {
|
browser.FrameLoadEnd += (sender, args) => {
|
||||||
IFrame frame = args.Frame;
|
IFrame frame = args.Frame;
|
||||||
|
|
||||||
if (frame.IsMain && TwitterUtils.IsTweetDeckWebsite(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));
|
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)){
|
if (!HasAnyPlugin(environment) || !ScriptLoader.ExecuteFile(frame, PluginSetupScriptNames[environment], sync)){
|
||||||
return;
|
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);
|
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));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user