Added themes

This commit is contained in:
2024-05-27 20:10:52 +03:00
parent d3dd29f4bf
commit 83115d72a4
8 changed files with 261 additions and 22 deletions

View File

@@ -4,6 +4,7 @@ using DiscordBotCore.Interfaces;
using DiscordBotCore.Others;
using DiscordBotCore.Others.Actions;
using DiscordBotUI_Windows;
using DiscordBotUI_Windows.WindowsForms;
namespace DiscordBotUI
@@ -16,11 +17,23 @@ namespace DiscordBotUI
public bool RequireOtherThread => true;
public string Description => "Discord UI desc";
public void Start(DiscordSocketClient client)
public async void Start(DiscordSocketClient client)
{
await Config.ApplicationSettings.LoadFromFile();
await Config.ThemeManager.LoadThemesFromThemesFolder();
if (Config.ApplicationSettings.ContainsKey("AppTheme"))
{
Config.ThemeManager.SetTheme(Config.ApplicationSettings["AppTheme"]);
} else Config.ApplicationSettings.Add("AppTheme", "Default");
Thread thread = new Thread(() =>
{
Application.Run(new MainWindow());
MainWindow mainWindow = new MainWindow();
Config.ThemeManager.SetFormTheme(Config.ThemeManager.CurrentTheme, mainWindow);
Application.Run(mainWindow);
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
@@ -41,25 +54,79 @@ namespace DiscordBotUI
public InternalActionRunType RunType => InternalActionRunType.ON_CALL;
public Task Execute(string[]? args)
public async Task Execute(string[]? args)
{
if(args == null || args.Length == 0)
{
Console.WriteLine("Please provide an option");
return Task.CompletedTask;
return;
}
if (args[0] == "theme")
{
if (args.Length == 1)
{
Console.WriteLine("Please provide a theme name");
return;
}
if(args[1] == "save")
{
if (args.Length == 2)
{
Console.WriteLine("Please provide a theme name");
return;
}
await Config.ThemeManager.SaveThemeToFile(args[2]);
Console.WriteLine("Theme saved");
}
if(args[1] == "set")
{
if (args.Length == 2)
{
Console.WriteLine("Please provide a theme name");
return;
}
Config.ThemeManager.SetTheme(args[2]);
}
if (args[1] == "list")
{
foreach (var theme in Config.ThemeManager._InstalledThemes)
{
Console.WriteLine(theme.Name);
}
}
return;
}
if(args[0] == "start")
{
await Config.ApplicationSettings.LoadFromFile();
await Config.ThemeManager.LoadThemesFromThemesFolder();
if (Config.ApplicationSettings.ContainsKey("AppTheme"))
{
Config.ThemeManager.SetTheme(Config.ApplicationSettings["AppTheme"]);
}
Thread thread = new Thread(() =>
{
Application.Run(new MainWindow());
MainWindow mainWindow = new MainWindow();
Config.ThemeManager.SetFormTheme(Config.ThemeManager.CurrentTheme, mainWindow);
Application.Run(mainWindow);
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
return Task.CompletedTask;
}
}
}