From 959e18046d6ec0bc9eefc8efd9b136cb14314af6 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Sat, 9 Dec 2023 02:58:11 +0100 Subject: Initial commit --- .gitignore | 5 ++ .../.idea/.gitignore | 13 +++++ .../.idea/encodings.xml | 4 ++ .../.idea/indexLayout.xml | 8 +++ .../.idea/vcs.xml | 6 ++ SpacebarDiscordDesktopLauncher.sln | 16 ++++++ SpacebarDiscordDesktopLauncher/Launcher.ico | Bin 0 -> 10781 bytes .../LinuxDiscordClientFinder.cs | 23 ++++++++ SpacebarDiscordDesktopLauncher/Program.cs | 61 +++++++++++++++++++++ .../SpacebarDiscordDesktopLauncher.csproj | 19 +++++++ .../WindowsDiscordClientFinder.cs | 38 +++++++++++++ SpacebarDiscordDesktopLauncher/build.sh | 9 +++ 12 files changed, 202 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.idea.SpacebarDiscordDesktopLauncher/.idea/.gitignore create mode 100644 .idea/.idea.SpacebarDiscordDesktopLauncher/.idea/encodings.xml create mode 100644 .idea/.idea.SpacebarDiscordDesktopLauncher/.idea/indexLayout.xml create mode 100644 .idea/.idea.SpacebarDiscordDesktopLauncher/.idea/vcs.xml create mode 100644 SpacebarDiscordDesktopLauncher.sln create mode 100644 SpacebarDiscordDesktopLauncher/Launcher.ico create mode 100644 SpacebarDiscordDesktopLauncher/LinuxDiscordClientFinder.cs create mode 100644 SpacebarDiscordDesktopLauncher/Program.cs create mode 100644 SpacebarDiscordDesktopLauncher/SpacebarDiscordDesktopLauncher.csproj create mode 100644 SpacebarDiscordDesktopLauncher/WindowsDiscordClientFinder.cs create mode 100755 SpacebarDiscordDesktopLauncher/build.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..add57be --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +bin/ +obj/ +/packages/ +riderModule.iml +/_ReSharper.Caches/ \ No newline at end of file diff --git a/.idea/.idea.SpacebarDiscordDesktopLauncher/.idea/.gitignore b/.idea/.idea.SpacebarDiscordDesktopLauncher/.idea/.gitignore new file mode 100644 index 0000000..674aba3 --- /dev/null +++ b/.idea/.idea.SpacebarDiscordDesktopLauncher/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/contentModel.xml +/modules.xml +/projectSettingsUpdater.xml +/.idea.SpacebarDiscordDesktopLauncher.iml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.SpacebarDiscordDesktopLauncher/.idea/encodings.xml b/.idea/.idea.SpacebarDiscordDesktopLauncher/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.SpacebarDiscordDesktopLauncher/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.SpacebarDiscordDesktopLauncher/.idea/indexLayout.xml b/.idea/.idea.SpacebarDiscordDesktopLauncher/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.SpacebarDiscordDesktopLauncher/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.SpacebarDiscordDesktopLauncher/.idea/vcs.xml b/.idea/.idea.SpacebarDiscordDesktopLauncher/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/.idea.SpacebarDiscordDesktopLauncher/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SpacebarDiscordDesktopLauncher.sln b/SpacebarDiscordDesktopLauncher.sln new file mode 100644 index 0000000..d39a3f6 --- /dev/null +++ b/SpacebarDiscordDesktopLauncher.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpacebarDiscordDesktopLauncher", "SpacebarDiscordDesktopLauncher\SpacebarDiscordDesktopLauncher.csproj", "{6A8C8E05-DAAF-4363-B588-B4A8E08B1A33}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6A8C8E05-DAAF-4363-B588-B4A8E08B1A33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6A8C8E05-DAAF-4363-B588-B4A8E08B1A33}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6A8C8E05-DAAF-4363-B588-B4A8E08B1A33}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6A8C8E05-DAAF-4363-B588-B4A8E08B1A33}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/SpacebarDiscordDesktopLauncher/Launcher.ico b/SpacebarDiscordDesktopLauncher/Launcher.ico new file mode 100644 index 0000000..dbdbb03 Binary files /dev/null and b/SpacebarDiscordDesktopLauncher/Launcher.ico differ diff --git a/SpacebarDiscordDesktopLauncher/LinuxDiscordClientFinder.cs b/SpacebarDiscordDesktopLauncher/LinuxDiscordClientFinder.cs new file mode 100644 index 0000000..f986c51 --- /dev/null +++ b/SpacebarDiscordDesktopLauncher/LinuxDiscordClientFinder.cs @@ -0,0 +1,23 @@ +namespace SpacebarDiscordDesktopLauncher; + +public class LinuxDiscordClientFinder +{ + public static string? FindDiscord() + { + Console.WriteLine($"Looking for installed Discord desktop instance..."); + + var pathDirectories = Environment.GetEnvironmentVariable("PATH")!.Split(':'); + foreach (var pathDirectory in pathDirectories) + { + if (!Directory.Exists(pathDirectory)) continue; + foreach (var file in Directory.GetFiles(pathDirectory)) + { + var fileInfo = new FileInfo(file); + if (fileInfo.Name.ToLower().StartsWith("discord")) + return fileInfo.FullName; + } + } + + return null; + } +} \ No newline at end of file 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(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 diff --git a/SpacebarDiscordDesktopLauncher/SpacebarDiscordDesktopLauncher.csproj b/SpacebarDiscordDesktopLauncher/SpacebarDiscordDesktopLauncher.csproj new file mode 100644 index 0000000..faa989f --- /dev/null +++ b/SpacebarDiscordDesktopLauncher/SpacebarDiscordDesktopLauncher.csproj @@ -0,0 +1,19 @@ + + + + Exe + net8.0 + enable + enable + + + + true + true + + true + true + Launcher.ico + + + diff --git a/SpacebarDiscordDesktopLauncher/WindowsDiscordClientFinder.cs b/SpacebarDiscordDesktopLauncher/WindowsDiscordClientFinder.cs new file mode 100644 index 0000000..8b6db0e --- /dev/null +++ b/SpacebarDiscordDesktopLauncher/WindowsDiscordClientFinder.cs @@ -0,0 +1,38 @@ +namespace SpacebarDiscordDesktopLauncher; + +public static class WindowsDiscordClientFinder +{ + public static string? FindDiscord() + { + Console.WriteLine($"Looking for installed Discord desktop instance..."); + + var basePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + foreach (var discordBranch in new String[] { "", "PTB", "Canary", "Development" }) + { + if (Path.Exists(Path.Combine(basePath, "Discord" + discordBranch))) + return Path.Combine(GetLatestAppVersion(Path.Combine(basePath, "Discord" + discordBranch)), + discordBranch + ".exe"); + } + + Console.WriteLine("Could not find Discord! Do you have the normal Discord client installed?"); + Console.ReadLine(); + return null; + } + + private static string GetLatestAppVersion(string basePath) + { + var dirs = Directory.GetDirectories(basePath); + var newestDir = ""; + var newestDirDate = DateTime.MinValue; + foreach (var dir in dirs) + { + var di = new DirectoryInfo(dir); + if (!di.Name.StartsWith("app", StringComparison.InvariantCultureIgnoreCase)) continue; + if (di.CreationTimeUtc <= newestDirDate) continue; + newestDirDate = di.CreationTimeUtc; + newestDir = di.FullName; + } + + return newestDir; + } +} \ No newline at end of file diff --git a/SpacebarDiscordDesktopLauncher/build.sh b/SpacebarDiscordDesktopLauncher/build.sh new file mode 100755 index 0000000..dd38d43 --- /dev/null +++ b/SpacebarDiscordDesktopLauncher/build.sh @@ -0,0 +1,9 @@ +#!/bin/sh +for arch in {x64,arm64} +do + for platform in {osx,win,linux} + do + dotnet publish -c Release -r ${platform}-${arch} --nologo --property AssemblyName=SpacebarDiscordDesktopLauncher-${platform}-${arch} -o bin/release + done +done +wait \ No newline at end of file -- cgit 1.4.1