Code Quality

This commit is contained in:
EnderIce2 2021-04-23 21:34:39 +03:00
parent 54c8969d2b
commit 59fda87954
3 changed files with 41 additions and 8 deletions

View File

@ -53,7 +53,10 @@ namespace EnderIce2.SDRSharpPlugin
public void Initialize(ISharpControl control) public void Initialize(ISharpControl control)
{ {
if (Utils.GetBooleanSetting("ShowWelcomePage", true)) if (Utils.GetBooleanSetting("ShowWelcomePage", true))
{
new WelcomeForm().ShowDialog(); new WelcomeForm().ShowDialog();
}
_controlPanel = new SettingsPanel(); _controlPanel = new SettingsPanel();
windowMessages = new TopWindowMessages(); // TODO: do something when "EnableRPCInvite" is set to false windowMessages = new TopWindowMessages(); // TODO: do something when "EnableRPCInvite" is set to false
_control = control; _control = control;
@ -89,15 +92,20 @@ namespace EnderIce2.SDRSharpPlugin
return; return;
} }
if (Utils.GetStringSetting("ClientID").Replace(" ", "").Length != 18) if (Utils.GetStringSetting("ClientID").Replace(" ", "").Length != 18)
{
client = new DiscordRpcClient("765213507321856078", pipe: discordPipe) client = new DiscordRpcClient("765213507321856078", pipe: discordPipe)
{ {
Logger = new ConsoleLogger(logLevel, true) Logger = new ConsoleLogger(logLevel, true)
}; };
}
else else
{
client = new DiscordRpcClient(Utils.GetStringSetting("ClientID"), pipe: discordPipe) client = new DiscordRpcClient(Utils.GetStringSetting("ClientID"), pipe: discordPipe)
{ {
Logger = new ConsoleLogger(logLevel, true) Logger = new ConsoleLogger(logLevel, true)
}; };
}
client.RegisterUriScheme(); client.RegisterUriScheme();
client.OnRpcMessage += Client_OnRpcMessage; client.OnRpcMessage += Client_OnRpcMessage;
client.OnPresenceUpdate += Client_OnPresenceUpdate; client.OnPresenceUpdate += Client_OnPresenceUpdate;
@ -110,7 +118,6 @@ namespace EnderIce2.SDRSharpPlugin
client.OnUnsubscribe += OnUnsubscribe; client.OnUnsubscribe += OnUnsubscribe;
client.OnJoin += OnJoin; client.OnJoin += OnJoin;
client.OnJoinRequested += OnJoinRequested; client.OnJoinRequested += OnJoinRequested;
//client.OnSpectate += OnSpectate;
presence.Timestamps = new Timestamps() presence.Timestamps = new Timestamps()
{ {
Start = DateTime.UtcNow Start = DateTime.UtcNow
@ -126,7 +133,7 @@ namespace EnderIce2.SDRSharpPlugin
} }
catch (Exception ex) catch (Exception ex)
{ {
LogWriter.WriteToFile("----> " + ex.ToString()); LogWriter.WriteToFile("----> " + ex);
MessageBox.Show($"Cannot get Spy Server Network address\n\nError:\n{ex}", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); MessageBox.Show($"Cannot get Spy Server Network address\n\nError:\n{ex}", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
} }
_ = MainLoop(); _ = MainLoop();
@ -236,7 +243,10 @@ namespace EnderIce2.SDRSharpPlugin
playedBefore = true; playedBefore = true;
} }
else if (!_control.IsPlaying && playedBefore) else if (!_control.IsPlaying && playedBefore)
{
presence.Assets.SmallImageKey = "pause"; presence.Assets.SmallImageKey = "pause";
}
if (!playedBefore) if (!playedBefore)
{ {
presence.Details = "Frequency: Not playing"; presence.Details = "Frequency: Not playing";
@ -255,16 +265,20 @@ namespace EnderIce2.SDRSharpPlugin
LogWriter.WriteToFile("Setting presence..."); LogWriter.WriteToFile("Setting presence...");
presence.Details = $"Frequency: {string.Format("{0:#,0,,0 Hz}", _control.Frequency)}"; presence.Details = $"Frequency: {string.Format("{0:#,0,,0 Hz}", _control.Frequency)}";
if (string.IsNullOrWhiteSpace(_control.RdsRadioText + _control.RdsProgramService)) if (string.IsNullOrWhiteSpace(_control.RdsRadioText + _control.RdsProgramService))
{
presence.State = $"RDS: unknown{space_for_listen_list}"; presence.State = $"RDS: unknown{space_for_listen_list}";
}
else else
{
presence.State = $"RDS: {_control.RdsProgramService} - {_control.RdsRadioText}{space_for_listen_list}"; presence.State = $"RDS: {_control.RdsProgramService} - {_control.RdsRadioText}{space_for_listen_list}";
}
} }
catch (Exception ex) catch (Exception ex)
{ {
LogWriter.WriteToFile(ex.ToString()); LogWriter.WriteToFile(ex.ToString());
} }
/*presence.Secrets.JoinSecret = */ /* presence.Secrets.JoinSecret = */
//_control.RegisterFrontControl(Gui, PluginPosition.Top); // TODO: _control.RegisterFrontControl(Gui, PluginPosition.Top);
} }
try try
{ {
@ -280,7 +294,7 @@ namespace EnderIce2.SDRSharpPlugin
else else
{ {
LogWriter.WriteToFile("Frequency or Radio Text are null!"); LogWriter.WriteToFile("Frequency or Radio Text are null!");
await Task.Delay(1000); await Task.Delay(1000).ConfigureAwait(false);
} }
} }
if (client == null) if (client == null)

View File

@ -26,17 +26,31 @@ namespace EnderIce2.SDRSharpPlugin
InitializeComponent(); InitializeComponent();
textBox1.Text = Utils.GetStringSetting("ClientID"); textBox1.Text = Utils.GetStringSetting("ClientID");
if (Utils.GetBooleanSetting("EnableRPC", true)) if (Utils.GetBooleanSetting("EnableRPC", true))
{
checkBox1.Checked = true; checkBox1.Checked = true;
}
else else
{
checkBox1.Checked = false; checkBox1.Checked = false;
}
if (Utils.GetBooleanSetting("LogRPC", false)) if (Utils.GetBooleanSetting("LogRPC", false))
{
checkBox2.Checked = true; checkBox2.Checked = true;
}
else else
{
checkBox2.Checked = false; checkBox2.Checked = false;
}
if (Utils.GetBooleanSetting("EnableRPCInvite", false)) if (Utils.GetBooleanSetting("EnableRPCInvite", false))
{
checkBox3.Checked = true; checkBox3.Checked = true;
}
else else
{
checkBox3.Checked = false; checkBox3.Checked = false;
}
LogWriter.WriteToFile("SettingsPanel loaded"); LogWriter.WriteToFile("SettingsPanel loaded");
} }

View File

@ -25,8 +25,8 @@ namespace EnderIce2.SDRSharpPlugin
LogWriter.WriteToFile(value); LogWriter.WriteToFile(value);
} }
} }
private bool AnswerA = false; private bool AnswerA;
private bool AnswerD = false; private bool AnswerD;
public async Task<bool> RequestAnswer(DiscordRpcClient client, JoinRequestMessage args) public async Task<bool> RequestAnswer(DiscordRpcClient client, JoinRequestMessage args)
{ {
LogWriter.WriteToFile("Incoming RPC request from " + args.User.Username); LogWriter.WriteToFile("Incoming RPC request from " + args.User.Username);
@ -54,10 +54,15 @@ namespace EnderIce2.SDRSharpPlugin
private async Task SetDefaultTextInLabel(bool accepted) private async Task SetDefaultTextInLabel(bool accepted)
{ {
if (accepted) if (accepted)
{
ChangeLabel = $"SDR# RPC | Request accepted"; ChangeLabel = $"SDR# RPC | Request accepted";
}
else else
{
ChangeLabel = $"SDR# RPC | Request declined"; ChangeLabel = $"SDR# RPC | Request declined";
await Task.Delay(5000); }
await Task.Delay(5000).ConfigureAwait(false);
ChangeLabel = $"SDR# RPC | Ready"; ChangeLabel = $"SDR# RPC | Ready";
} }
} }