diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-12-09 02:58:11 +0100 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-12-09 02:58:47 +0100 |
commit | 959e18046d6ec0bc9eefc8efd9b136cb14314af6 (patch) | |
tree | 76a30a39ccce380ee79bc79f4c96dfd35c44a6e9 /SpacebarDiscordDesktopLauncher/Program.cs | |
download | SpacebarDiscordDesktopLauncher-959e18046d6ec0bc9eefc8efd9b136cb14314af6.tar.xz |
Initial commit
Diffstat (limited to 'SpacebarDiscordDesktopLauncher/Program.cs')
-rw-r--r-- | SpacebarDiscordDesktopLauncher/Program.cs | 61 |
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 |