mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-08 02:34:06 +02:00
Fix 'Restore Defaults' not resetting plugin status and import/reset not closing Plugins form
This commit is contained in:
parent
8141a5a5c5
commit
6468c03465
@ -471,6 +471,7 @@ public void OpenSettings(Type startTab){
|
||||
}
|
||||
|
||||
if (form.ShouldReloadBrowser){
|
||||
FormManager.TryFind<FormPlugins>()?.Close();
|
||||
plugins.Reload(); // also reloads the browser
|
||||
}
|
||||
else{
|
||||
|
@ -4,8 +4,12 @@
|
||||
|
||||
namespace TweetDuck.Core{
|
||||
static class FormManager{
|
||||
public static T TryFind<T>() where T : Form{
|
||||
return Application.OpenForms.OfType<T>().FirstOrDefault();
|
||||
}
|
||||
|
||||
public static bool TryBringToFront<T>() where T : Form{
|
||||
T form = Application.OpenForms.OfType<T>().FirstOrDefault();
|
||||
T form = TryFind<T>();
|
||||
|
||||
if (form != null){
|
||||
form.BringToFront();
|
||||
|
@ -114,6 +114,7 @@ private void btnContinue_Click(object sender, EventArgs e){
|
||||
|
||||
if (Flags.HasFlag(ExportFileFlags.PluginData)){
|
||||
try{
|
||||
File.Delete(Program.PluginConfigFilePath);
|
||||
Directory.Delete(Program.PluginDataPath, true);
|
||||
}catch(Exception ex){
|
||||
Program.Reporter.HandleException("Plugin Data Reset Error", "Could not delete plugin data.", true, ex);
|
||||
|
@ -8,22 +8,24 @@ namespace TweetDuck.Plugins{
|
||||
sealed class PluginConfig{
|
||||
public event EventHandler<PluginChangedStateEventArgs> InternalPluginChangedState; // should only be accessed from PluginManager
|
||||
|
||||
public IEnumerable<string> DisabledPlugins => Disabled;
|
||||
public bool AnyDisabled => Disabled.Count > 0;
|
||||
public IEnumerable<string> DisabledPlugins => disabled;
|
||||
public bool AnyDisabled => disabled.Count > 0;
|
||||
|
||||
private readonly HashSet<string> Disabled = new HashSet<string>{
|
||||
private static readonly string[] DefaultDisabled = {
|
||||
"official/clear-columns",
|
||||
"official/reply-account"
|
||||
};
|
||||
|
||||
private readonly HashSet<string> disabled = new HashSet<string>();
|
||||
|
||||
public void SetEnabled(Plugin plugin, bool enabled){
|
||||
if ((enabled && Disabled.Remove(plugin.Identifier)) || (!enabled && Disabled.Add(plugin.Identifier))){
|
||||
if ((enabled && disabled.Remove(plugin.Identifier)) || (!enabled && disabled.Add(plugin.Identifier))){
|
||||
InternalPluginChangedState?.Invoke(this, new PluginChangedStateEventArgs(plugin, enabled));
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEnabled(Plugin plugin){
|
||||
return !Disabled.Contains(plugin.Identifier);
|
||||
return !disabled.Contains(plugin.Identifier);
|
||||
}
|
||||
|
||||
public void Load(string file){
|
||||
@ -32,14 +34,20 @@ public void Load(string file){
|
||||
string line = reader.ReadLine();
|
||||
|
||||
if (line == "#Disabled"){
|
||||
Disabled.Clear();
|
||||
disabled.Clear();
|
||||
|
||||
while((line = reader.ReadLine()) != null){
|
||||
Disabled.Add(line);
|
||||
disabled.Add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch(FileNotFoundException){
|
||||
disabled.Clear();
|
||||
|
||||
foreach(string identifier in DefaultDisabled){
|
||||
disabled.Add(identifier);
|
||||
}
|
||||
|
||||
Save(file);
|
||||
}catch(DirectoryNotFoundException){
|
||||
}catch(Exception e){
|
||||
@ -52,8 +60,8 @@ public void Save(string file){
|
||||
using(StreamWriter writer = new StreamWriter(new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None), Encoding.UTF8)){
|
||||
writer.WriteLine("#Disabled");
|
||||
|
||||
foreach(string disabled in Disabled){
|
||||
writer.WriteLine(disabled);
|
||||
foreach(string identifier in disabled){
|
||||
writer.WriteLine(identifier);
|
||||
}
|
||||
}
|
||||
}catch(Exception e){
|
||||
|
Loading…
Reference in New Issue
Block a user