mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-07 15:56:13 +02:00
Fix closing of plugin windows
This commit is contained in:
@@ -188,31 +188,46 @@ namespace DesktopMagic
|
|||||||
Settings.CurrentLayout.Plugins.Add(pluginId, pluginSettings);
|
Settings.CurrentLayout.Plugins.Add(pluginId, pluginSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (WindowNames.Contains(internalPluginData.Metadata.Id.ToString()) || !pluginSettings.Enabled)
|
||||||
|
{
|
||||||
|
int index = WindowNames.IndexOf(internalPluginData.Metadata.Id.ToString());
|
||||||
|
|
||||||
|
if (index >= 0)
|
||||||
|
{
|
||||||
|
//Not sure how to handle this
|
||||||
|
try
|
||||||
|
{
|
||||||
|
blockWindowsClosing = false;
|
||||||
|
Windows[index].Close();
|
||||||
|
blockWindowsClosing = true;
|
||||||
|
Windows.RemoveAt(index);
|
||||||
|
WindowNames.RemoveAt(index);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
App.Logger.Log(ex.Message, "Main", LogSeverity.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
PluginWindow window;
|
PluginWindow window;
|
||||||
|
|
||||||
if (builtInPlugins.TryGetValue(internalPluginData.Metadata, out Type? pluginType))
|
if (builtInPlugins.TryGetValue(internalPluginData.Metadata, out Type? pluginType))
|
||||||
{
|
{
|
||||||
window = new PluginWindow((Api.Plugin)Activator.CreateInstance(pluginType)!, internalPluginData.Metadata, pluginSettings)
|
window = new PluginWindow((Api.Plugin)Activator.CreateInstance(pluginType)!, internalPluginData.Metadata, pluginSettings)
|
||||||
{
|
{
|
||||||
Title = internalPluginData.Metadata.Name
|
Title = internalPluginData.Metadata.Id.ToString()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
window = new PluginWindow(internalPluginData.Metadata, pluginSettings, internalPluginData.DirectoryPath)
|
window = new PluginWindow(internalPluginData.Metadata, pluginSettings, internalPluginData.DirectoryPath)
|
||||||
{
|
{
|
||||||
Title = internalPluginData.Metadata.Name
|
Title = internalPluginData.Metadata.Id.ToString()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
blockWindowsClosing = false;
|
|
||||||
|
|
||||||
if (!WindowNames.Contains(window.Title) && pluginSettings.Enabled)
|
|
||||||
{
|
|
||||||
_ = Task.Run(() =>
|
|
||||||
{
|
|
||||||
Dispatcher.Invoke(() =>
|
|
||||||
{
|
|
||||||
Action? onPluginLoaded = null;
|
Action? onPluginLoaded = null;
|
||||||
onPluginLoaded = () =>
|
onPluginLoaded = () =>
|
||||||
{
|
{
|
||||||
@@ -239,31 +254,6 @@ namespace DesktopMagic
|
|||||||
window.Closing += DisplayWindow_Closing;
|
window.Closing += DisplayWindow_Closing;
|
||||||
Windows.Add(window);
|
Windows.Add(window);
|
||||||
WindowNames.Add(window.Title);
|
WindowNames.Add(window.Title);
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int index = WindowNames.IndexOf(window.Title);
|
|
||||||
|
|
||||||
if (index >= 0)
|
|
||||||
{
|
|
||||||
//Not sure how to handle this
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Windows[index].Close();
|
|
||||||
|
|
||||||
Windows.RemoveAt(index);
|
|
||||||
WindowNames.RemoveAt(index);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
App.Logger.Log(ex.Message, "Main", LogSeverity.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
blockWindowsClosing = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DisplayWindow_ContentRendered(object? sender, EventArgs e)
|
private void DisplayWindow_ContentRendered(object? sender, EventArgs e)
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ public partial class PluginWindow : Window
|
|||||||
public event Action? OnExit;
|
public event Action? OnExit;
|
||||||
|
|
||||||
private readonly PluginSettings settings;
|
private readonly PluginSettings settings;
|
||||||
|
private readonly System.Timers.Timer? updateTimer;
|
||||||
private Thread? pluginThread;
|
private Thread? pluginThread;
|
||||||
private System.Timers.Timer? valueTimer;
|
private System.Timers.Timer? valueTimer;
|
||||||
|
|
||||||
private Plugin? pluginClassInstance;
|
private Plugin? pluginClassInstance;
|
||||||
|
|
||||||
public bool IsRunning { get; private set; } = true;
|
public bool IsRunning { get; private set; } = true;
|
||||||
@@ -55,12 +55,12 @@ public partial class PluginWindow : Window
|
|||||||
Owner = w;
|
Owner = w;
|
||||||
w.Hide();
|
w.Hide();
|
||||||
|
|
||||||
System.Timers.Timer t = new System.Timers.Timer
|
updateTimer = new System.Timers.Timer
|
||||||
{
|
{
|
||||||
Interval = 100
|
Interval = 100
|
||||||
};
|
};
|
||||||
t.Elapsed += UpdateTimer_Elapsed;
|
updateTimer.Elapsed += UpdateTimer_Elapsed;
|
||||||
t.Start();
|
updateTimer.Start();
|
||||||
|
|
||||||
PluginMetadata = pluginMetadata;
|
PluginMetadata = pluginMetadata;
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
@@ -163,6 +163,11 @@ public partial class PluginWindow : Window
|
|||||||
border.CornerRadius = new CornerRadius(settings.Theme.CornerRadius);
|
border.CornerRadius = new CornerRadius(settings.Theme.CornerRadius);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!IsRunning)
|
||||||
|
{
|
||||||
|
updateTimer?.Stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadPlugin()
|
private void LoadPlugin()
|
||||||
@@ -378,8 +383,8 @@ public partial class PluginWindow : Window
|
|||||||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||||
{
|
{
|
||||||
App.Logger.Log($"\"{PluginMetadata}\" - Stopping plugin", "Plugin");
|
App.Logger.Log($"\"{PluginMetadata}\" - Stopping plugin", "Plugin");
|
||||||
pluginClassInstance?.Stop();
|
|
||||||
IsRunning = false;
|
IsRunning = false;
|
||||||
|
pluginClassInstance?.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Window Events
|
#region Window Events
|
||||||
|
|||||||
Reference in New Issue
Block a user