summary refs log tree commit diff
path: root/SpacebarDiscordDesktopLauncher
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-12-09 02:58:11 +0100
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-12-09 02:58:47 +0100
commit959e18046d6ec0bc9eefc8efd9b136cb14314af6 (patch)
tree76a30a39ccce380ee79bc79f4c96dfd35c44a6e9 /SpacebarDiscordDesktopLauncher
downloadSpacebarDiscordDesktopLauncher-959e18046d6ec0bc9eefc8efd9b136cb14314af6.tar.xz
Initial commit
Diffstat (limited to 'SpacebarDiscordDesktopLauncher')
-rw-r--r--SpacebarDiscordDesktopLauncher/Launcher.icobin0 -> 10781 bytes
-rw-r--r--SpacebarDiscordDesktopLauncher/LinuxDiscordClientFinder.cs23
-rw-r--r--SpacebarDiscordDesktopLauncher/Program.cs61
-rw-r--r--SpacebarDiscordDesktopLauncher/SpacebarDiscordDesktopLauncher.csproj19
-rw-r--r--SpacebarDiscordDesktopLauncher/WindowsDiscordClientFinder.cs38
-rwxr-xr-xSpacebarDiscordDesktopLauncher/build.sh9
6 files changed, 150 insertions, 0 deletions
diff --git a/SpacebarDiscordDesktopLauncher/Launcher.ico b/SpacebarDiscordDesktopLauncher/Launcher.ico
new file mode 100644

index 0000000..dbdbb03 --- /dev/null +++ b/SpacebarDiscordDesktopLauncher/Launcher.ico
Binary files differdiff --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<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 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 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net8.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + + <PropertyGroup Condition="'$(Configuration)' == 'Release'"> + <Optimize>true</Optimize> + <RunAOTCompilation>true</RunAOTCompilation> +<!-- <PublishAot>true</PublishAot>--> + <PublishTrimmed>true</PublishTrimmed> + <PublishSingleFile>true</PublishSingleFile> + <ApplicationIcon>Launcher.ico</ApplicationIcon> + </PropertyGroup> + +</Project> 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