mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-29 11:34:07 +02:00
Move PluginManager initialization and move Form manipulation to FormManager
This commit is contained in:
parent
bc1767fb84
commit
9e3b92bfc1
@ -2,7 +2,6 @@
|
|||||||
using CefSharp.WinForms;
|
using CefSharp.WinForms;
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using TweetDuck.Configuration;
|
using TweetDuck.Configuration;
|
||||||
using TweetDuck.Core.Bridge;
|
using TweetDuck.Core.Bridge;
|
||||||
@ -61,14 +60,16 @@ public bool IsWaiting{
|
|||||||
private SoundNotification soundNotification;
|
private SoundNotification soundNotification;
|
||||||
private VideoPlayer videoPlayer;
|
private VideoPlayer videoPlayer;
|
||||||
|
|
||||||
public FormBrowser(PluginManager pluginManager, UpdaterSettings updaterSettings){
|
public FormBrowser(UpdaterSettings updaterSettings){
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
Text = Program.BrandName;
|
Text = Program.BrandName;
|
||||||
|
|
||||||
this.plugins = pluginManager;
|
this.plugins = new PluginManager(Program.PluginPath, Program.PluginConfigFilePath);
|
||||||
this.plugins.Reloaded += plugins_Reloaded;
|
this.plugins.Reloaded += plugins_Reloaded;
|
||||||
|
this.plugins.Executed += plugins_Executed;
|
||||||
this.plugins.PluginChangedState += plugins_PluginChangedState;
|
this.plugins.PluginChangedState += plugins_PluginChangedState;
|
||||||
|
this.plugins.Reload();
|
||||||
|
|
||||||
this.contextMenu = ContextMenuBrowser.CreateMenu(this);
|
this.contextMenu = ContextMenuBrowser.CreateMenu(this);
|
||||||
this.memoryUsageTracker = new MemoryUsageTracker("TDGF_tryRunCleanup");
|
this.memoryUsageTracker = new MemoryUsageTracker("TDGF_tryRunCleanup");
|
||||||
@ -134,16 +135,6 @@ public FormBrowser(PluginManager pluginManager, UpdaterSettings updaterSettings)
|
|||||||
RestoreWindow();
|
RestoreWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryBringToFront<T>() where T : Form{
|
|
||||||
T form = Application.OpenForms.OfType<T>().FirstOrDefault();
|
|
||||||
|
|
||||||
if (form != null){
|
|
||||||
form.BringToFront();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ShowChildForm(Form form){
|
private void ShowChildForm(Form form){
|
||||||
form.VisibleChanged += (sender, args) => form.MoveToCenter(this);
|
form.VisibleChanged += (sender, args) => form.MoveToCenter(this);
|
||||||
form.Show(this);
|
form.Show(this);
|
||||||
@ -325,8 +316,18 @@ private void trayIcon_ClickClose(object sender, EventArgs e){
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void plugins_Reloaded(object sender, PluginErrorEventArgs e){
|
private void plugins_Reloaded(object sender, PluginErrorEventArgs e){
|
||||||
|
if (e.HasErrors){
|
||||||
|
FormMessage.Error("Error Loading Plugins", "The following plugins will not be available until the issues are resolved:\n\n"+string.Join("\n\n", e.Errors), FormMessage.OK);
|
||||||
|
}
|
||||||
|
|
||||||
ReloadToTweetDeck();
|
ReloadToTweetDeck();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void plugins_Executed(object sender, PluginErrorEventArgs e){
|
||||||
|
if (e.HasErrors){
|
||||||
|
FormMessage.Error("Error Executing Plugins", "Failed to execute the following plugins:\n\n"+string.Join("\n\n", e.Errors), FormMessage.OK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void plugins_PluginChangedState(object sender, PluginChangedStateEventArgs e){
|
private void plugins_PluginChangedState(object sender, PluginChangedStateEventArgs e){
|
||||||
browser.ExecuteScriptAsync("window.TDPF_setPluginState", e.Plugin, e.IsEnabled);
|
browser.ExecuteScriptAsync("window.TDPF_setPluginState", e.Plugin, e.IsEnabled);
|
||||||
@ -334,11 +335,7 @@ private void plugins_PluginChangedState(object sender, PluginChangedStateEventAr
|
|||||||
|
|
||||||
private void updates_UpdateAccepted(object sender, UpdateAcceptedEventArgs e){
|
private void updates_UpdateAccepted(object sender, UpdateAcceptedEventArgs e){
|
||||||
this.InvokeAsyncSafe(() => {
|
this.InvokeAsyncSafe(() => {
|
||||||
foreach(Form form in Application.OpenForms.Cast<Form>().Reverse()){
|
FormManager.CloseAllDialogs();
|
||||||
if (form is FormSettings || form is FormPlugins || form is FormAbout){
|
|
||||||
form.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updates.BeginUpdateDownload(this, e.UpdateInfo, update => {
|
updates.BeginUpdateDownload(this, e.UpdateInfo, update => {
|
||||||
if (update.DownloadStatus == UpdateDownloadStatus.Done){
|
if (update.DownloadStatus == UpdateDownloadStatus.Done){
|
||||||
@ -450,7 +447,7 @@ public void OpenSettings(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void OpenSettings(Type startTab){
|
public void OpenSettings(Type startTab){
|
||||||
if (!TryBringToFront<FormSettings>()){
|
if (!FormManager.TryBringToFront<FormSettings>()){
|
||||||
bool prevEnableUpdateCheck = Config.EnableUpdateCheck;
|
bool prevEnableUpdateCheck = Config.EnableUpdateCheck;
|
||||||
|
|
||||||
FormSettings form = new FormSettings(this, plugins, updates, startTab);
|
FormSettings form = new FormSettings(this, plugins, updates, startTab);
|
||||||
@ -483,13 +480,13 @@ public void OpenSettings(Type startTab){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void OpenAbout(){
|
public void OpenAbout(){
|
||||||
if (!TryBringToFront<FormAbout>()){
|
if (!FormManager.TryBringToFront<FormAbout>()){
|
||||||
ShowChildForm(new FormAbout());
|
ShowChildForm(new FormAbout());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenPlugins(){
|
public void OpenPlugins(){
|
||||||
if (!TryBringToFront<FormPlugins>()){
|
if (!FormManager.TryBringToFront<FormPlugins>()){
|
||||||
ShowChildForm(new FormPlugins(plugins));
|
ShowChildForm(new FormPlugins(plugins));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
25
Core/FormManager.cs
Normal file
25
Core/FormManager.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using TweetDuck.Core.Other;
|
||||||
|
|
||||||
|
namespace TweetDuck.Core{
|
||||||
|
static class FormManager{
|
||||||
|
public static bool TryBringToFront<T>() where T : Form{
|
||||||
|
T form = Application.OpenForms.OfType<T>().FirstOrDefault();
|
||||||
|
|
||||||
|
if (form != null){
|
||||||
|
form.BringToFront();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void CloseAllDialogs(){
|
||||||
|
foreach(Form form in Application.OpenForms.Cast<Form>().Reverse()){
|
||||||
|
if (form is FormSettings || form is FormPlugins || form is FormAbout){
|
||||||
|
form.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
Program.cs
21
Program.cs
@ -13,8 +13,6 @@
|
|||||||
using TweetDuck.Core.Other.Settings.Export;
|
using TweetDuck.Core.Other.Settings.Export;
|
||||||
using TweetDuck.Core.Utils;
|
using TweetDuck.Core.Utils;
|
||||||
using TweetDuck.Data;
|
using TweetDuck.Data;
|
||||||
using TweetDuck.Plugins;
|
|
||||||
using TweetDuck.Plugins.Events;
|
|
||||||
using TweetDuck.Updates;
|
using TweetDuck.Updates;
|
||||||
|
|
||||||
namespace TweetDuck{
|
namespace TweetDuck{
|
||||||
@ -150,18 +148,13 @@ private static void Main(){
|
|||||||
|
|
||||||
Application.ApplicationExit += (sender, args) => ExitCleanup();
|
Application.ApplicationExit += (sender, args) => ExitCleanup();
|
||||||
|
|
||||||
PluginManager plugins = new PluginManager(PluginPath, PluginConfigFilePath);
|
|
||||||
plugins.Reloaded += plugins_Reloaded;
|
|
||||||
plugins.Executed += plugins_Executed;
|
|
||||||
plugins.Reload();
|
|
||||||
|
|
||||||
UpdaterSettings updaterSettings = new UpdaterSettings{
|
UpdaterSettings updaterSettings = new UpdaterSettings{
|
||||||
AllowPreReleases = Arguments.HasFlag(Arguments.ArgDebugUpdates),
|
AllowPreReleases = Arguments.HasFlag(Arguments.ArgDebugUpdates),
|
||||||
DismissedUpdate = UserConfig.DismissedUpdate,
|
DismissedUpdate = UserConfig.DismissedUpdate,
|
||||||
InstallerDownloadFolder = InstallerPath
|
InstallerDownloadFolder = InstallerPath
|
||||||
};
|
};
|
||||||
|
|
||||||
FormBrowser mainForm = new FormBrowser(plugins, updaterSettings);
|
FormBrowser mainForm = new FormBrowser(updaterSettings);
|
||||||
Application.Run(mainForm);
|
Application.Run(mainForm);
|
||||||
|
|
||||||
if (mainForm.UpdateInstallerPath != null){
|
if (mainForm.UpdateInstallerPath != null){
|
||||||
@ -176,18 +169,6 @@ private static void Main(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void plugins_Reloaded(object sender, PluginErrorEventArgs e){
|
|
||||||
if (e.HasErrors){
|
|
||||||
FormMessage.Error("Error Loading Plugins", "The following plugins will not be available until the issues are resolved:\n\n"+string.Join("\n\n", e.Errors), FormMessage.OK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void plugins_Executed(object sender, PluginErrorEventArgs e){
|
|
||||||
if (e.HasErrors){
|
|
||||||
FormMessage.Error("Error Executing Plugins", "Failed to execute the following plugins:\n\n"+string.Join("\n\n", e.Errors), FormMessage.OK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GetDataStoragePath(){
|
private static string GetDataStoragePath(){
|
||||||
string custom = Arguments.GetValue(Arguments.ArgDataFolder, null);
|
string custom = Arguments.GetValue(Arguments.ArgDataFolder, null);
|
||||||
|
|
||||||
|
@ -88,6 +88,7 @@
|
|||||||
<Compile Include="Core\Controls\NumericUpDownEx.cs">
|
<Compile Include="Core\Controls\NumericUpDownEx.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Core\FormManager.cs" />
|
||||||
<Compile Include="Core\Handling\General\BrowserProcessHandler.cs" />
|
<Compile Include="Core\Handling\General\BrowserProcessHandler.cs" />
|
||||||
<Compile Include="Core\Handling\ContextMenuBase.cs" />
|
<Compile Include="Core\Handling\ContextMenuBase.cs" />
|
||||||
<Compile Include="Core\Handling\ContextMenuBrowser.cs" />
|
<Compile Include="Core\Handling\ContextMenuBrowser.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user