new commit

This commit is contained in:
Gilles Lazures 2026-02-09 04:49:05 +01:00
parent fe85d2dcc4
commit 07398a9eac
6 changed files with 78 additions and 4 deletions

View File

@ -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<InstallationFinish>(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 };

View File

@ -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 });

View File

@ -0,0 +1,6 @@
namespace BrikInstaller.Schemas;
public class InstallationFinish {
public bool CreateShortcut { get; set; }
public bool LaunchAfterExit { get; set; }
}

View File

@ -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")}\"");
}
}

View File

@ -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) {

View File

@ -268,7 +268,7 @@
</div>
<form>
<div>
<input type="checkbox" name="createShortcut" id="createShortcut" value="createShortcut" checked>
<input type="checkbox" name="createShortcut" id="createShortcut" value="createShortcut">
<label for="createShortcut" data-i18n="create_shortcut">createShortcut</label>
</div>
<div>
@ -277,7 +277,7 @@
</div>
</form>
<section class="buttons">
<button class="primary" data-i18n="exit" onclick="window.close()"></button>
<button class="primary" data-i18n="exit" onclick="quit()"></button>
</section>
</article>
</aside>