summary refs log tree commit diff
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
downloadSpacebarDiscordDesktopLauncher-master.tar.xz
Initial commit HEAD master
-rw-r--r--.gitignore5
-rw-r--r--.idea/.idea.SpacebarDiscordDesktopLauncher/.idea/.gitignore13
-rw-r--r--.idea/.idea.SpacebarDiscordDesktopLauncher/.idea/encodings.xml4
-rw-r--r--.idea/.idea.SpacebarDiscordDesktopLauncher/.idea/indexLayout.xml8
-rw-r--r--.idea/.idea.SpacebarDiscordDesktopLauncher/.idea/vcs.xml6
-rw-r--r--SpacebarDiscordDesktopLauncher.sln16
-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
12 files changed, 202 insertions, 0 deletions
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
+</project>
\ 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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="UserContentModel">
+    <attachedFolders />
+    <explicitIncludes />
+    <explicitExcludes />
+  </component>
+</project>
\ 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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>
\ 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
--- /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