Cleaning Code

This commit is contained in:
EnderIce2 2021-05-13 22:45:50 +03:00
parent 0cc81d35e2
commit a441168176
2 changed files with 23 additions and 4 deletions

View File

@ -30,4 +30,4 @@ namespace EnderIce2.SDRSharpPlugin
} }
} }
} }
} }

View File

@ -16,12 +16,16 @@ namespace EnderIce2.SDRSharpPlugin
private SettingsPanel _controlPanel; private SettingsPanel _controlPanel;
private const LogLevel logLevel = LogLevel.Trace; private const LogLevel logLevel = LogLevel.Trace;
private const int discordPipe = -1; private const int discordPipe = -1;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "<Pending>")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "<Pending>")]
bool RPCalreadyLoaded; private bool RPCalreadyLoaded;
private ISharpControl _control; private ISharpControl _control;
bool playedBefore; private bool playedBefore;
//private SDRSharp.FrontEnds.SpyServer.ControllerPanel controllerPanel; //private SDRSharp.FrontEnds.SpyServer.ControllerPanel controllerPanel;
private TopWindowMessages windowMessages; private TopWindowMessages windowMessages;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "<Pending>")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "<Pending>")]
private RichPresence presence = new RichPresence() private RichPresence presence = new RichPresence()
{ {
@ -35,11 +39,13 @@ namespace EnderIce2.SDRSharpPlugin
SmallImageText = $"SDR-RPC plugin v{Assembly.LoadFrom("SDR-RPC.dll").GetName().Version} by EnderIce2" // should show the correct version SmallImageText = $"SDR-RPC plugin v{Assembly.LoadFrom("SDR-RPC.dll").GetName().Version} by EnderIce2" // should show the correct version
} }
}; };
private DiscordRpcClient client; private DiscordRpcClient client;
private bool isRunning = true; private bool isRunning = true;
public string DisplayName => _displayName; public string DisplayName => _displayName;
public bool HasGui => true; public bool HasGui => true;
public UserControl Gui => _controlPanel; public UserControl Gui => _controlPanel;
public void Initialize(ISharpControl control) public void Initialize(ISharpControl control)
{ {
IConfigurationPanelProvider configurationPanelProvider; IConfigurationPanelProvider configurationPanelProvider;
@ -146,46 +152,56 @@ namespace EnderIce2.SDRSharpPlugin
} }
LogWriter.WriteToFile("EOM Initialize"); LogWriter.WriteToFile("EOM Initialize");
} }
private void Client_OnPresenceUpdate(object sender, PresenceMessage args) private void Client_OnPresenceUpdate(object sender, PresenceMessage args)
{ {
LogWriter.WriteToFile($"[RpcMessage] | Presence state: {args.Presence.State}"); LogWriter.WriteToFile($"[RpcMessage] | Presence state: {args.Presence.State}");
} }
private void Client_OnRpcMessage(object sender, IMessage msg) private void Client_OnRpcMessage(object sender, IMessage msg)
{ {
LogWriter.WriteToFile($"[RpcMessage] | {msg.Type} | {msg}"); LogWriter.WriteToFile($"[RpcMessage] | {msg.Type} | {msg}");
} }
private void OnConnectionFailed(object sender, ConnectionFailedMessage args) private void OnConnectionFailed(object sender, ConnectionFailedMessage args)
{ {
_controlPanel.ChangeStatus = $"RPC Connection Failed!\n{args.Type} | {args.FailedPipe}"; _controlPanel.ChangeStatus = $"RPC Connection Failed!\n{args.Type} | {args.FailedPipe}";
} }
private void OnConnectionEstablished(object sender, ConnectionEstablishedMessage args) private void OnConnectionEstablished(object sender, ConnectionEstablishedMessage args)
{ {
_controlPanel.ChangeStatus = "RPC Connection Established!"; _controlPanel.ChangeStatus = "RPC Connection Established!";
} }
private void OnError(object sender, ErrorMessage args) private void OnError(object sender, ErrorMessage args)
{ {
_controlPanel.ChangeStatus = $"RPC Error:\n{args.Message}"; _controlPanel.ChangeStatus = $"RPC Error:\n{args.Message}";
windowMessages.ChangeLabel = "SDR# RPC | Internal error"; windowMessages.ChangeLabel = "SDR# RPC | Internal error";
} }
private void OnClose(object sender, CloseMessage args) private void OnClose(object sender, CloseMessage args)
{ {
_controlPanel.ChangeStatus = "RPC Closed"; _controlPanel.ChangeStatus = "RPC Closed";
windowMessages.ChangeLabel = "SDR# RPC | Closed"; windowMessages.ChangeLabel = "SDR# RPC | Closed";
Close(); Close();
} }
private void OnReady(object sender, ReadyMessage args) private void OnReady(object sender, ReadyMessage args)
{ {
_controlPanel.ChangeStatus = "RPC Ready"; _controlPanel.ChangeStatus = "RPC Ready";
windowMessages.ChangeLabel = "SDR# RPC | Ready"; windowMessages.ChangeLabel = "SDR# RPC | Ready";
} }
private void OnSubscribe(object sender, SubscribeMessage args) private void OnSubscribe(object sender, SubscribeMessage args)
{ {
_controlPanel.ChangeStatus = $"Subscribed: {args.Event}"; _controlPanel.ChangeStatus = $"Subscribed: {args.Event}";
} }
private void OnUnsubscribe(object sender, UnsubscribeMessage args) private void OnUnsubscribe(object sender, UnsubscribeMessage args)
{ {
_controlPanel.ChangeStatus = $"Unsubscribed: {args.Event}"; _controlPanel.ChangeStatus = $"Unsubscribed: {args.Event}";
} }
private void OnJoin(object sender, JoinMessage args) private void OnJoin(object sender, JoinMessage args)
{ {
presence.Party.Size++; presence.Party.Size++;
@ -196,6 +212,7 @@ namespace EnderIce2.SDRSharpPlugin
Utils.SaveSetting("spyserver.uri", args.Secret); Utils.SaveSetting("spyserver.uri", args.Secret);
_control.StartRadio(); _control.StartRadio();
} }
private async void OnJoinRequested(object sender, JoinRequestMessage args) private async void OnJoinRequested(object sender, JoinRequestMessage args)
{ {
try try
@ -214,7 +231,8 @@ namespace EnderIce2.SDRSharpPlugin
MessageBox.Show(ex.ToString()); MessageBox.Show(ex.ToString());
} }
} }
async Task MainLoop()
private async Task MainLoop()
{ {
try try
{ {
@ -324,6 +342,7 @@ namespace EnderIce2.SDRSharpPlugin
LogWriter.WriteToFile(ex.ToString()); LogWriter.WriteToFile(ex.ToString());
} }
} }
public void Close() public void Close()
{ {
LogWriter.WriteToFile("Close called"); LogWriter.WriteToFile("Close called");