From d3b26ef6d8879d7aa8cacb81248c1aefe12c4253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rik=20Levente?= <33373714+Levminer@users.noreply.github.com> Date: Wed, 19 Jun 2024 11:32:37 +0200 Subject: [PATCH] Windows cleanup --- platforms/windows/lib/JSON.cs | 32 ------------------- platforms/windows/lib/Settings.cs | 32 ------------------- platforms/windows/service/RTCServer.cs | 32 ------------------- .../service/WindowsBackgroundService.cs | 1 - platforms/windows/service/service.csproj | 1 - 5 files changed, 98 deletions(-) delete mode 100644 platforms/windows/lib/JSON.cs delete mode 100644 platforms/windows/service/RTCServer.cs diff --git a/platforms/windows/lib/JSON.cs b/platforms/windows/lib/JSON.cs deleted file mode 100644 index 2e0c0b2..0000000 --- a/platforms/windows/lib/JSON.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.Json; -using System.Text.Json.Serialization; -using System.Threading.Tasks; - -namespace lib; -public class JSON { - public JsonSerializerOptions SerializerOptions = new() { - PropertyNamingPolicy = JsonNamingPolicy.CamelCase, - NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals, - WriteIndented = true, - Converters = { new InfinityToZeroConverter() } - }; -} - -internal class InfinityToZeroConverter : JsonConverter { - public override double Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - return reader.GetDouble(); - } - - public override void Write(Utf8JsonWriter writer, double value, JsonSerializerOptions options) { - // If the value is infinity, write 0 instead - if (double.IsInfinity(value)) { - writer.WriteNumberValue(0); - } else { - writer.WriteNumberValue(value); - } - } -} diff --git a/platforms/windows/lib/Settings.cs b/platforms/windows/lib/Settings.cs index bfd73a4..875a86f 100644 --- a/platforms/windows/lib/Settings.cs +++ b/platforms/windows/lib/Settings.cs @@ -66,38 +66,6 @@ public Settings() { } } - [Obsolete("Deprecated, remove when desktop is removed")] - public void GetSettings() { - var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); - - // check if Cores folder exists - if (!File.Exists(Path.Join(appData, "Cores"))) { - Directory.CreateDirectory(Path.Join(appData, "Cores")); - } - - // check if settings.json exists - if (!File.Exists(Path.Join(appData, "Cores", "settings.json"))) { - // create settings.json - File.WriteAllText(Path.Join(appData, "Cores", "settings.json"), JsonSerializer.Serialize(this)); - } - - // read settings.json - try { - var settings = JsonSerializer.Deserialize(File.ReadAllText(Path.Join(appData, "Cores", "settings.json"))); - - interval = settings.interval; - minimizeToTray = settings.minimizeToTray; - launchOnStartup = settings.launchOnStartup; - remoteConnections = settings.remoteConnections; - optionalAnalytics = settings.optionalAnalytics; - connectionCode = settings.connectionCode; - version = settings.version; - } - catch (Exception e) { - SentrySdk.CaptureException(e); - } - } - public void SetSettings() { var programData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); diff --git a/platforms/windows/service/RTCServer.cs b/platforms/windows/service/RTCServer.cs deleted file mode 100644 index 911903e..0000000 --- a/platforms/windows/service/RTCServer.cs +++ /dev/null @@ -1,32 +0,0 @@ -using ezrtc; -using lib; -using SIPSorcery.Net; -using System.Text.Json; - -namespace service; -public class RTCServer { - internal static EzRTCHost EzRTCHost = new(new Uri("wss://rtc-usw.levminer.com/one-to-many"), Program.Settings.connectionCode, new List { new RTCIceServer { urls = "stun:openrelay.metered.ca:80" }, new RTCIceServer { urls = "turn:standard.relay.metered.ca:443", credential = "8By67N7nOLDIagJk", username = "2ce7aaf275c1abdef74ec7e3", credentialType = RTCIceCredentialType.password } }); - internal static bool stop = false; - - public void Start(HardwareInfo hardwareInfo) { - Task.Run(async () => { - Task.Run(() => { - EzRTCHost.Start(); - }); - - EzRTCHost.onDataChannelOpen += (data) => { - EzRTCHost.sendMessageToAll(JsonSerializer.Serialize(new NetworkMessage() { Type = "initialData", Data = hardwareInfo.API }, Program.CompressedSerializerOptions)); - }; - - while (!stop) { - EzRTCHost.sendMessageToAll(JsonSerializer.Serialize(new NetworkMessage() { Type = "data", Data = hardwareInfo.API }, Program.CompressedSerializerOptions)); - - await Task.Delay(2000); - } - }); - } - - public void Stop() { - stop = true; - } -} diff --git a/platforms/windows/service/WindowsBackgroundService.cs b/platforms/windows/service/WindowsBackgroundService.cs index 6f6300e..9d5572d 100644 --- a/platforms/windows/service/WindowsBackgroundService.cs +++ b/platforms/windows/service/WindowsBackgroundService.cs @@ -7,7 +7,6 @@ public sealed class WindowsBackgroundService : BackgroundService { internal static HardwareInfo HardwareInfo = new(); internal static HTTPServer HTTPServer = new(); internal static WSServer WSServer = new(); - internal static RTCServer RTCServer = new(); public WindowsBackgroundService(ILogger logger) { this.logger = logger; diff --git a/platforms/windows/service/service.csproj b/platforms/windows/service/service.csproj index 8b885a9..c2a4055 100644 --- a/platforms/windows/service/service.csproj +++ b/platforms/windows/service/service.csproj @@ -15,7 +15,6 @@ -