Skip to content

Commit

Permalink
fixed some stuff in issue #37
Browse files Browse the repository at this point in the history
  • Loading branch information
n1d3v committed Jun 22, 2024
1 parent 959ff30 commit 289d26f
Show file tree
Hide file tree
Showing 16 changed files with 288 additions and 193 deletions.
68 changes: 68 additions & 0 deletions Naticord/Classes/DarkMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Drawing;
using System.Windows.Forms;

namespace Naticord.Classes
{
internal class DarkMode
{
private readonly Color darkBackgroundColor = Color.FromArgb(30, 30, 30);
private readonly Color darkTextColor = Color.White;
private readonly Color darkButtonColor = Color.FromArgb(45, 45, 48);
private readonly Color darkButtonTextColor = Color.White;

public void ApplyDarkMode(Control control)
{
foreach (Control childControl in control.Controls)
{
ApplyControlStyles(childControl);

if (childControl.HasChildren)
{
ApplyDarkMode(childControl);
}
}
}

private void ApplyControlStyles(Control control)
{
if (control is Button)
{
ApplyButtonStyle(control as Button);
}
else if (control is Label)
{
ApplyLabelStyle(control as Label);
}
else if (control is TextBox)
{
ApplyTextBoxStyle(control as TextBox);
}
else
{
control.BackColor = darkBackgroundColor;
control.ForeColor = darkTextColor;
}
}

private void ApplyButtonStyle(Button button)
{
button.BackColor = darkButtonColor;
button.ForeColor = darkButtonTextColor;
button.FlatStyle = FlatStyle.Flat;
button.FlatAppearance.BorderColor = darkButtonColor;
}

private void ApplyLabelStyle(Label label)
{
label.ForeColor = darkTextColor;
}

private void ApplyTextBoxStyle(TextBox textBox)
{
textBox.BackColor = darkBackgroundColor;
textBox.ForeColor = darkTextColor;
textBox.BorderStyle = BorderStyle.FixedSingle;
}
}
}
17 changes: 0 additions & 17 deletions Naticord/Classes/WebSocketClientDM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ private async Task HandleWebSocketMessage(string data)
}
break;
default:
// handle other op codes when needed
break;
}
}
Expand Down Expand Up @@ -190,12 +189,10 @@ private async Task HandleMessageCreateEventAsync(JToken data)
switch ((int)eventData["type"].Value)
{
case 7:
// Join message
parentDMForm.AddMessage(author, "*Say hi!*", "slid in the server", attachmentsFormed.ToArray(), embedsFormed.ToArray(), true, true);
break;

case 19:
// Reply
bool found = false;
var messages = await parentDMForm.GetApiResponse($"channels/{parentDMForm.ChatID}/messages");
foreach (var message in messages)
Expand All @@ -221,20 +218,6 @@ private async Task HandleMessageCreateEventAsync(JToken data)
}
}

/*private void HandlePresenceUpdateEvent(JToken data)
{
dynamic eventData = data;
string userId = eventData["user"]["id"];
string status = eventData["status"];
string username = GetUsernameById(userId);
parentDMForm.Invoke((MethodInvoker)(() =>
{
// nothing for now
}));
}*/

private void HandleWebSocketError(string errorMessage)
{
parentDMForm.Invoke((MethodInvoker)(() =>
Expand Down
22 changes: 1 addition & 21 deletions Naticord/Classes/WebSocketClientGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ private void SendIdentifyPayload()

private async Task HandleWebSocketMessage(string data)
{
Console.WriteLine($"WebSocket Received: {data}");

var json = JObject.Parse(data);
int opCode = (int)json["op"];

Expand All @@ -87,12 +85,11 @@ private async Task HandleWebSocketMessage(string data)
await HandleMessageCreateEventAsync(json["d"]);
break;
case "PRESENCE_UPDATE":
//HandlePresenceUpdateEvent(json["d"]);
// soon
break;
}
break;
default:
// handle other op codes when needed
break;
}
}
Expand Down Expand Up @@ -160,12 +157,10 @@ private async Task HandleMessageCreateEventAsync(JToken data)
switch ((int)eventData["type"].Value)
{
case 7:
// Join message
parentGroupForm.AddMessage(author, "*Say hi!*", "slid in the server", attachmentsFormed.ToArray(), embedsFormed.ToArray(), true, true);
break;

case 19:
// Reply
bool found = false;
var messages = await parentGroupForm.GetApiResponse($"channels/{parentGroupForm.ChatID}/messages");
foreach (var message in messages)
Expand All @@ -183,28 +178,13 @@ private async Task HandleMessageCreateEventAsync(JToken data)
break;

default:
// Normal text or unimplemented
parentGroupForm.AddMessage(author, content, "said", attachmentsFormed.ToArray(), embedsFormed.ToArray(), true, true);
break;
}
parentGroupForm.Invoke((MethodInvoker)(() => parentGroupForm.ScrollToBottom()));
}
}

/*private void HandlePresenceUpdateEvent(JToken data)
{
dynamic eventData = data;
string userId = eventData["user"]["id"];
string status = eventData["status"];
string username = GetUsernameById(userId);
parentGroupForm.Invoke((MethodInvoker)(() =>
{
// nothing for now
}));
}*/

private void HandleWebSocketError(string errorMessage)
{
parentGroupForm.Invoke((MethodInvoker)(() =>
Expand Down
Loading

0 comments on commit 289d26f

Please sign in to comment.