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