summary refs log tree commit diff
path: root/SpacebarDiscordDesktopLauncher/Program.cs
diff options
context:
space:
mode:
Diffstat (limited to 'SpacebarDiscordDesktopLauncher/Program.cs')
-rw-r--r--SpacebarDiscordDesktopLauncher/Program.cs61
1 files changed, 61 insertions, 0 deletions
diff --git a/SpacebarDiscordDesktopLauncher/Program.cs b/SpacebarDiscordDesktopLauncher/Program.cs
new file mode 100644
index 0000000..e72a641
--- /dev/null
+++ b/SpacebarDiscordDesktopLauncher/Program.cs
@@ -0,0 +1,61 @@
+// See https://aka.ms/new-console-template for more information
+
+using System.Diagnostics;
+using System.Text.Json;
+using System.Text.Json.Nodes;
+using SpacebarDiscordDesktopLauncher;
+
+internal class Program
+{
+    public static void Main(string[] args)
+    {
+        string? discordClientPath = Environment.OSVersion.Platform switch
+        {
+            PlatformID.Win32NT => WindowsDiscordClientFinder.FindDiscord(),
+            PlatformID.Unix => LinuxDiscordClientFinder.FindDiscord(),
+            _ => throw new Exception($"Unknown platform: {Environment.OSVersion.Platform}")
+        };
+
+        string? userDataPath = Environment.OSVersion.Platform switch
+        {
+            PlatformID.Win32NT => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
+                ".local",
+                "share", "Discord-SpacebarLauncher"),
+            PlatformID.Unix => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local",
+                "share",
+                "Discord-SpacebarLauncher"),
+            _ => throw new Exception($"Unknown platform: {Environment.OSVersion.Platform}")
+        };
+
+        if (discordClientPath is null)
+        {
+            Console.WriteLine("Could not find Discord! Do you have the normal Discord client installed?");
+            Console.ReadLine();
+            return;
+        }
+
+        if (Environment.OSVersion.Platform == PlatformID.Unix)
+        {
+            var settingsJsonPath = Path.Combine(userDataPath, "discord", "settings.json");
+            JsonObject discordSettings = new();
+            if (File.Exists(settingsJsonPath))
+                discordSettings = JsonSerializer.Deserialize<JsonObject>(File.ReadAllText(settingsJsonPath));
+
+            discordSettings!["SKIP_HOST_UPDATE"] = true;
+            File.WriteAllText(settingsJsonPath, JsonSerializer.Serialize(discordSettings));
+            Console.WriteLine($"Wrote settings.json... Contents: {discordSettings}");
+            Console.WriteLine($"Full path: {settingsJsonPath}");
+        }
+
+        var psi = new ProcessStartInfo(discordClientPath)
+        {
+            Environment =
+            {
+                { "DISCORD_WEBAPP_ENDPOINT", "https://app.spacebar.chat" },
+                { "DISCORD_USER_DATA_DIR", userDataPath },
+            }
+        };
+
+        Process.Start(psi);
+    }
+}
\ No newline at end of file