Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dark Mode Styling #1325

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
10 changes: 10 additions & 0 deletions XrmToolBox/New/PluginForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using XrmToolBox.Controls;
Expand Down Expand Up @@ -59,6 +60,15 @@ public PluginForm(UserControl control, string name, string pluginName)
CustomTheme.Instance.ApplyTheme(this);
DisplayHighlight(pluginControlBase.ConnectionDetail);

Task.Factory.StartNew(() =>
{
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));

this.Invoke((MethodInvoker)delegate
{
CustomTheme.Instance.ApplyTheme(this);
});
});
Copy link
Author

@johnyenter-briars johnyenter-briars Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MscrmTools are you ok with this pattern? When attempting to support rendering plugins in darkmode, I was running to an issue in which we would call CustomTheme.Instance.ApplyTheme(this) before the Plugin had a chance to render. This meant that the main window of plugins wouldn't get themed.

Adding this statement - where we call ApplyTheme after a set amount of time - giving the plugin time to render it's WinForm - allowed the plugin to render in dark mode.

For example, I tested with Sql4CDS and got this result:

image

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if waiting a specific amount of time is the best way to handle this (even if I have no other idea for now)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I agree it's hacky. The problem is - I don't see any method in the IPlugin interface that is like "PluginFinishedLoading". I think that would be an optimal solution. Each plug-in could load, and only once it's ready let xrm toolbox know. The only problem is adding a new method and then getting all plug-ins to implement the new method would be a nightmare.

}

public event EventHandler<StatusBarMessageEventArgs> SendMessageToStatusBar;
Expand Down
2 changes: 2 additions & 0 deletions XrmToolBox/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ private static void CurrentDomain_UnhandledException(object sender, UnhandledExc
/// </summary>
private static void InitializePluginsFolder()
{
//TODO: don't early return. Somehow optionally run this in debug mode? (If XRM Toolbox is open elsewhere)
return;
if (!Directory.Exists(Paths.PluginsPath))
{
Directory.CreateDirectory(Paths.PluginsPath);
Expand Down