mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-06 23:39:09 +02:00
Fix closing of plugin windows
This commit is contained in:
@@ -188,71 +188,18 @@ namespace DesktopMagic
|
|||||||
Settings.CurrentLayout.Plugins.Add(pluginId, pluginSettings);
|
Settings.CurrentLayout.Plugins.Add(pluginId, pluginSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginWindow window;
|
if (WindowNames.Contains(internalPluginData.Metadata.Id.ToString()) || !pluginSettings.Enabled)
|
||||||
|
|
||||||
if (builtInPlugins.TryGetValue(internalPluginData.Metadata, out Type? pluginType))
|
|
||||||
{
|
{
|
||||||
window = new PluginWindow((Api.Plugin)Activator.CreateInstance(pluginType)!, internalPluginData.Metadata, pluginSettings)
|
int index = WindowNames.IndexOf(internalPluginData.Metadata.Id.ToString());
|
||||||
{
|
|
||||||
Title = internalPluginData.Metadata.Name
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
window = new PluginWindow(internalPluginData.Metadata, pluginSettings, internalPluginData.DirectoryPath)
|
|
||||||
{
|
|
||||||
Title = internalPluginData.Metadata.Name
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
blockWindowsClosing = false;
|
|
||||||
|
|
||||||
if (!WindowNames.Contains(window.Title) && pluginSettings.Enabled)
|
|
||||||
{
|
|
||||||
_ = Task.Run(() =>
|
|
||||||
{
|
|
||||||
Dispatcher.Invoke(() =>
|
|
||||||
{
|
|
||||||
Action? onPluginLoaded = null;
|
|
||||||
onPluginLoaded = () =>
|
|
||||||
{
|
|
||||||
Dispatcher.Invoke(() =>
|
|
||||||
{
|
|
||||||
if (!optionsComboBox.Items.Contains(internalPluginData.Metadata))
|
|
||||||
{
|
|
||||||
_ = optionsComboBox.Items.Add(internalPluginData.Metadata);
|
|
||||||
}
|
|
||||||
optionsComboBox.SelectedIndex = -1;
|
|
||||||
optionsComboBox.SelectedIndex = optionsComboBox.Items.IndexOf(internalPluginData.Metadata);
|
|
||||||
window.PluginLoaded -= onPluginLoaded;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
window.OnExit += () =>
|
|
||||||
{
|
|
||||||
pluginSettings.Enabled = false;
|
|
||||||
};
|
|
||||||
window.PluginLoaded += onPluginLoaded;
|
|
||||||
|
|
||||||
window.ShowInTaskbar = false;
|
|
||||||
window.Show();
|
|
||||||
window.ContentRendered += DisplayWindow_ContentRendered;
|
|
||||||
window.Closing += DisplayWindow_Closing;
|
|
||||||
Windows.Add(window);
|
|
||||||
WindowNames.Add(window.Title);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int index = WindowNames.IndexOf(window.Title);
|
|
||||||
|
|
||||||
if (index >= 0)
|
if (index >= 0)
|
||||||
{
|
{
|
||||||
//Not sure how to handle this
|
//Not sure how to handle this
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
blockWindowsClosing = false;
|
||||||
Windows[index].Close();
|
Windows[index].Close();
|
||||||
|
blockWindowsClosing = true;
|
||||||
Windows.RemoveAt(index);
|
Windows.RemoveAt(index);
|
||||||
WindowNames.RemoveAt(index);
|
WindowNames.RemoveAt(index);
|
||||||
}
|
}
|
||||||
@@ -261,9 +208,52 @@ namespace DesktopMagic
|
|||||||
App.Logger.Log(ex.Message, "Main", LogSeverity.Error);
|
App.Logger.Log(ex.Message, "Main", LogSeverity.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
blockWindowsClosing = true;
|
PluginWindow window;
|
||||||
|
|
||||||
|
if (builtInPlugins.TryGetValue(internalPluginData.Metadata, out Type? pluginType))
|
||||||
|
{
|
||||||
|
window = new PluginWindow((Api.Plugin)Activator.CreateInstance(pluginType)!, internalPluginData.Metadata, pluginSettings)
|
||||||
|
{
|
||||||
|
Title = internalPluginData.Metadata.Id.ToString()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
window = new PluginWindow(internalPluginData.Metadata, pluginSettings, internalPluginData.DirectoryPath)
|
||||||
|
{
|
||||||
|
Title = internalPluginData.Metadata.Id.ToString()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Action? onPluginLoaded = null;
|
||||||
|
onPluginLoaded = () =>
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(() =>
|
||||||
|
{
|
||||||
|
if (!optionsComboBox.Items.Contains(internalPluginData.Metadata))
|
||||||
|
{
|
||||||
|
_ = optionsComboBox.Items.Add(internalPluginData.Metadata);
|
||||||
|
}
|
||||||
|
optionsComboBox.SelectedIndex = -1;
|
||||||
|
optionsComboBox.SelectedIndex = optionsComboBox.Items.IndexOf(internalPluginData.Metadata);
|
||||||
|
window.PluginLoaded -= onPluginLoaded;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
window.OnExit += () =>
|
||||||
|
{
|
||||||
|
pluginSettings.Enabled = false;
|
||||||
|
};
|
||||||
|
window.PluginLoaded += onPluginLoaded;
|
||||||
|
|
||||||
|
window.ShowInTaskbar = false;
|
||||||
|
window.Show();
|
||||||
|
window.ContentRendered += DisplayWindow_ContentRendered;
|
||||||
|
window.Closing += DisplayWindow_Closing;
|
||||||
|
Windows.Add(window);
|
||||||
|
WindowNames.Add(window.Title);
|
||||||
}
|
}
|
||||||
|
|
||||||
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