diff --git a/src/main/Program.cs b/src/main/Program.cs index 8a27a43..0e0309e 100644 --- a/src/main/Program.cs +++ b/src/main/Program.cs @@ -129,6 +129,24 @@ class Program{ } } break; + case "installer::quit": + if (jsonPayload.TryGetProperty("createShortcut", out var createShortcut) && jsonPayload.TryGetProperty("launchAfterExit", out var launchAfterExit)) { + try { + InstallationFinish installationFinish = jsonPayload.Deserialize(Constants._jsonOptions)!; + if (installationFinish.CreateShortcut) { + //TO-DO : Fetch executable path from remote + // Create a shortcut with it + } + if (installationFinish.LaunchAfterExit) { + //TO-DO : Fetch executable path from remote + // Launch it + } + responsePayload = new { success = true }; + } catch (Exception) { + responsePayload = new { success = false }; + } + } + break; } var finalResponse = new { requestId, payload = responsePayload }; diff --git a/src/main/helpers/Bash.cs b/src/main/helpers/Bash.cs index b81bd7d..68aa980 100644 --- a/src/main/helpers/Bash.cs +++ b/src/main/helpers/Bash.cs @@ -53,8 +53,7 @@ public static class BashUtils { public static void OpenUrl(string url) { try { Process.Start(url); - } - catch { + } catch { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { url = url.Replace("&", "^&"); Process.Start(new ProcessStartInfo(url) { UseShellExecute = true }); diff --git a/src/main/schemas/Installation.cs b/src/main/schemas/Installation.cs new file mode 100644 index 0000000..1fe01c8 --- /dev/null +++ b/src/main/schemas/Installation.cs @@ -0,0 +1,6 @@ +namespace BrikInstaller.Schemas; + +public class InstallationFinish { + public bool CreateShortcut { get; set; } + public bool LaunchAfterExit { get; set; } +} \ No newline at end of file diff --git a/src/main/services/Installation.cs b/src/main/services/Installation.cs index 92c3065..f3fdd61 100644 --- a/src/main/services/Installation.cs +++ b/src/main/services/Installation.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using System.Runtime.InteropServices; +using BrikInstaller.Utils; namespace BrikInstaller.Services; @@ -73,4 +74,45 @@ public static class InstallationService { } return final; } + +} + +public static class ShortcutService { + public static void CreateShortcut(string appName, string targetExePath, bool createDesktop, bool autoStart) { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { + CreateWindowsShortcut(appName, targetExePath); + } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { + CreateMacShortcut(appName, targetExePath); + } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { + CreateLinuxShortcut(appName, targetExePath); + } + } + + private static void CreateMacShortcut(string appName, string targetExePath) { + string desktopPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Desktop"); + string shortcutPath = Path.Combine(desktopPath, appName); + + BashUtils.GetCommandOutput($"ln -sf \"{targetExePath}\" \"{shortcutPath}\""); + } + + private static void CreateWindowsShortcut(string appName, string targetExePath) { + string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + string shortcutLocation = Path.Combine(desktopPath, $"{appName}.lnk"); + + string script = $"$s=(New-Object -ComObject WScript.Shell).CreateShortcut('{shortcutLocation}');$s.TargetPath='{targetExePath}';$s.Save()"; + Process.Start(new ProcessStartInfo("powershell", $"-Command \"{script}\"") { CreateNoWindow = true }); + } + + private static void CreateLinuxShortcut(string appName, string targetExePath) { + string desktopEntry = $@" +[Desktop Entry] +Type=Application +Name={appName} +Exec=""{targetExePath}"" +Terminal=false +"; + string desktopPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Desktop"); + File.WriteAllText(Path.Combine(desktopPath, $"{appName}.desktop"), desktopEntry); + Process.Start("chmod", $"+x \"{Path.Combine(desktopPath, $"{appName}.desktop")}\""); + } } \ No newline at end of file diff --git a/src/resources/renderer/assets/js/index.js b/src/resources/renderer/assets/js/index.js index 22aecb8..6d907b3 100644 --- a/src/resources/renderer/assets/js/index.js +++ b/src/resources/renderer/assets/js/index.js @@ -189,6 +189,15 @@ async function checkInstallationPath(path) { } } +async function quit() { + const finishState = { + createShortcut: createShortcut["checked"], + launchAfterExit: launchAfterExit["checked"] + } + console.log(finishState) + await system.call("installer::quit", finishState) +} + onFrameShowed("onboarding", () => { const languageDropdown = document.querySelector("details.language") if (languageDropdown.getAttribute("value") == null) { diff --git a/src/resources/renderer/index.html b/src/resources/renderer/index.html index 2b4e3cc..57ba554 100644 --- a/src/resources/renderer/index.html +++ b/src/resources/renderer/index.html @@ -268,7 +268,7 @@
- +
@@ -277,7 +277,7 @@
- +