mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-04 00:46:12 +02:00
Add reload plugins button and open plugins in IDE support in plugin manager
This commit is contained in:
@@ -4,13 +4,14 @@ using DesktopMagic.Plugins;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace DesktopMagic.DataContexts;
|
||||
|
||||
internal class PluginEntryDataContext(PluginMetadata pluginMetadata, ICommand command, PluginEntryDataContext.Mode mode, string? path = null) : INotifyPropertyChanged
|
||||
internal class PluginEntryDataContext(PluginMetadata pluginMetadata, ICommand command, PluginEntryDataContext.Mode mode, string? path = null, string? csprojPath = null) : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
@@ -43,7 +44,11 @@ internal class PluginEntryDataContext(PluginMetadata pluginMetadata, ICommand co
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(pluginMetadata.ProfileUri?.ToString()))
|
||||
if (File.Exists(csprojPath))
|
||||
{
|
||||
return new("Code24", "IDE", true, new CommandHandler(OpenCsprojInIDE));
|
||||
}
|
||||
else if (string.IsNullOrWhiteSpace(pluginMetadata.ProfileUri?.ToString()))
|
||||
{
|
||||
return new("Folder24", (string)App.LanguageDictionary["folder"], path is not null, new CommandHandler(() => Process.Start("explorer.exe", path!)));
|
||||
}
|
||||
@@ -78,6 +83,34 @@ internal class PluginEntryDataContext(PluginMetadata pluginMetadata, ICommand co
|
||||
_ = Process.Start(psi);
|
||||
}
|
||||
|
||||
private void OpenCsprojInIDE()
|
||||
{
|
||||
string? associatedProgram = FileUtilities.GetAssociatedProgram(".csproj");
|
||||
string pluginProjectPath = System.IO.Path.GetDirectoryName(csprojPath)!;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(pluginProjectPath))
|
||||
{
|
||||
App.Logger.LogError("Could not determine plugin project directory.", source: "PluginManager");
|
||||
return;
|
||||
}
|
||||
|
||||
if (associatedProgram is null)
|
||||
{
|
||||
App.Logger.LogInfo($"Opening plugin project in Explorer: {pluginProjectPath}", source: "PluginManager");
|
||||
_ = Process.Start("explorer.exe", pluginProjectPath);
|
||||
return;
|
||||
}
|
||||
|
||||
App.Logger.LogInfo($"Opening plugin project in IDE: {associatedProgram}", source: "PluginManager");
|
||||
ProcessStartInfo psi = new ProcessStartInfo
|
||||
{
|
||||
FileName = associatedProgram,
|
||||
Arguments = csprojPath,
|
||||
};
|
||||
|
||||
_ = Process.Start(psi);
|
||||
}
|
||||
|
||||
private string GetInstallUninstallButtonText()
|
||||
{
|
||||
return mode switch
|
||||
|
||||
@@ -217,6 +217,14 @@ public sealed class Manager
|
||||
PluginWindows.Add(window);
|
||||
}
|
||||
|
||||
public void ReloadPlugins()
|
||||
{
|
||||
App.Logger.LogInfo("Reloading plugins", source: "PluginManager");
|
||||
|
||||
LoadPlugins();
|
||||
LoadLayout(false);
|
||||
}
|
||||
|
||||
public void SetEditMode(bool editMode)
|
||||
{
|
||||
_isEditMode = editMode;
|
||||
|
||||
@@ -98,9 +98,11 @@
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="15" />
|
||||
<ColumnDefinition Width="0.5*" />
|
||||
<ColumnDefinition Width="1.05*" />
|
||||
<ColumnDefinition Width="5.5" />
|
||||
<ColumnDefinition Width="1.05*" />
|
||||
<ColumnDefinition Width="5" />
|
||||
<ColumnDefinition Width="0.5*" />
|
||||
<ColumnDefinition Width="1.05*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Image Source="{Binding ModIoIcon}" Cursor="Hand" Height="30" MouseUp="Image_MouseUp" HorizontalAlignment="Left" />
|
||||
@@ -110,7 +112,13 @@
|
||||
<TextBlock Text="{DynamicResource createNewPlugin}" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Grid.Column="4" HorizontalAlignment="Stretch" Click="LogInButton_Click">
|
||||
<Button Grid.Column="4" HorizontalAlignment="Stretch" Click="ReloadPluginsButton_Click">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<ui:SymbolIcon Symbol="ArrowClockwise24" Margin="0 0 10 0" />
|
||||
<TextBlock Text="{DynamicResource reloadPlugins}" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Grid.Column="6" HorizontalAlignment="Stretch" Click="LogInButton_Click">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<ui:SymbolIcon Symbol="PersonKey20" Margin="0 0 10 0" />
|
||||
<TextBlock Text="{Binding LoginButtonText}" />
|
||||
|
||||
@@ -91,8 +91,7 @@ public partial class PluginManager : Page
|
||||
|
||||
if (changed)
|
||||
{
|
||||
_manager.LoadPlugins();
|
||||
_manager.LoadLayout(Application.Current.MainWindow.Visibility != System.Windows.Visibility.Visible);
|
||||
_manager.ReloadPlugins();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +100,10 @@ public partial class PluginManager : Page
|
||||
App.Logger.LogInfo("Initializing Plugin Manager", source: "PluginManager");
|
||||
HashSet<uint> pluginIds = [];
|
||||
|
||||
pluginManagerDataContext.IsLoading = true;
|
||||
pluginManagerDataContext.InstalledPlugins.Clear();
|
||||
pluginManagerDataContext.AllPlugins.Clear();
|
||||
|
||||
foreach (string pluginPath in Directory.GetDirectories(pluginsPath))
|
||||
{
|
||||
string pluginMetadataPath = Path.Combine(pluginPath, "metadata.json");
|
||||
@@ -119,8 +122,10 @@ public partial class PluginManager : Page
|
||||
continue;
|
||||
}
|
||||
|
||||
string csprojPath = GetCsprojPath(pluginMetadata.Name);
|
||||
|
||||
App.Logger.LogInfo($"Loaded plugin: {pluginMetadata.Name} (ID: {pluginMetadata.Id})", source: "PluginManager");
|
||||
pluginManagerDataContext.InstalledPlugins.Add(new PluginEntryDataContext(pluginMetadata, new CommandHandler(async () => await Remove(pluginPath, pluginMetadata.Id)), PluginEntryDataContext.Mode.Uninstall, pluginPath));
|
||||
pluginManagerDataContext.InstalledPlugins.Add(new PluginEntryDataContext(pluginMetadata, new CommandHandler(async () => await Remove(pluginPath, pluginMetadata.Id)), PluginEntryDataContext.Mode.Uninstall, pluginPath, csprojPath));
|
||||
_ = pluginIds.Add(pluginMetadata.Id);
|
||||
|
||||
if (pluginMetadata.IsLocalPlugin)
|
||||
@@ -388,6 +393,13 @@ public partial class PluginManager : Page
|
||||
pluginManagerDataContext.IsSearching = false;
|
||||
}
|
||||
|
||||
private async void ReloadPluginsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_manager.ReloadPlugins();
|
||||
await InitializePluginManager();
|
||||
changed = false;
|
||||
}
|
||||
|
||||
private async void CreatePluginButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
@@ -440,11 +452,7 @@ public partial class PluginManager : Page
|
||||
}
|
||||
|
||||
string pluginName = inputDialog.ResponseText;
|
||||
string pluginSafeName = pluginName.ToLower().Replace("_", " ");
|
||||
|
||||
TextInfo info = CultureInfo.CurrentCulture.TextInfo;
|
||||
pluginSafeName = info.ToTitleCase(pluginSafeName);
|
||||
pluginSafeName = IdentifierNameRegex().Replace(pluginSafeName, "");
|
||||
string pluginSafeName = GetPluginSafeName(pluginName);
|
||||
|
||||
App.Logger.LogInfo($"Creating plugin with name: {pluginName} (safe name: {pluginSafeName})", source: "PluginManager");
|
||||
|
||||
@@ -570,6 +578,9 @@ public class {pluginSafeName}Plugin : Plugin
|
||||
return;
|
||||
}
|
||||
|
||||
changed = true;
|
||||
await InitializePluginManager();
|
||||
|
||||
string? associatedProgram = FileUtilities.GetAssociatedProgram(".csproj");
|
||||
|
||||
if (associatedProgram is null)
|
||||
@@ -726,4 +737,21 @@ public class {pluginSafeName}Plugin : Plugin
|
||||
App.Logger.LogError($"Plugin sync failed: {ex.Message}", source: "PluginManager");
|
||||
}
|
||||
}
|
||||
|
||||
private string GetPluginSafeName(string pluginName)
|
||||
{
|
||||
string pluginSafeName = pluginName.ToLower().Replace("_", " ");
|
||||
|
||||
TextInfo info = CultureInfo.CurrentCulture.TextInfo;
|
||||
pluginSafeName = info.ToTitleCase(pluginSafeName);
|
||||
pluginSafeName = IdentifierNameRegex().Replace(pluginSafeName, "");
|
||||
|
||||
return pluginSafeName;
|
||||
}
|
||||
|
||||
private string GetCsprojPath(string pluginName)
|
||||
{
|
||||
string pluginSafeName = GetPluginSafeName(pluginName);
|
||||
return Path.Combine(pluginDevelopmentPath, pluginSafeName, $"{pluginSafeName}.csproj");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user