From 17a084879990a9bf4537f3d8eb24e82d05999624 Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Fri, 18 Oct 2024 21:24:48 +0800 Subject: [PATCH] Add shortcuts on Linux Resolves https://github.com/wpilibsuite/WPILibInstaller-Avalonia/issues/136 Signed-off-by: Jade Turner --- .../ViewModels/InstallPageViewModel.cs | 112 ++++++++++++++---- 1 file changed, 86 insertions(+), 26 deletions(-) diff --git a/WPILibInstaller-Avalonia/ViewModels/InstallPageViewModel.cs b/WPILibInstaller-Avalonia/ViewModels/InstallPageViewModel.cs index 844c04d..404443c 100644 --- a/WPILibInstaller-Avalonia/ViewModels/InstallPageViewModel.cs +++ b/WPILibInstaller-Avalonia/ViewModels/InstallPageViewModel.cs @@ -31,6 +31,50 @@ public class InstallPageViewModel : PageViewModelBase public int ProgressTotal { get; set; } public string TextTotal { get; set; } = ""; + private async void CreateLinuxShortcut(String name, String frcYear, CancellationToken token) + { + // Create Linux desktop shortcut + var desktopFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Desktop", $@"{name} {frcYear}.desktop"); + var launcherFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local/share/applications", $@"{name} {frcYear}.desktop"); + string contents = $@"#!/usr/bin/env xdg-open +[Desktop Entry] +Version=1.0 +Type=Application +Categories=Development +Name={name} {frcYear} +Comment={name} tool for the 2025 FIRST Robotics Competition season +Exec={configurationProvider.InstallDirectory}/tools/{name}.sh +Icon={configurationProvider.InstallDirectory}/frccode/wpilib-256.ico +Terminal=false +StartupNotify=true +StartupWMClass=Code +"; + + var desktopPath = Path.GetDirectoryName(desktopFile); + if (desktopPath != null) + { + Directory.CreateDirectory(desktopPath); + } + var launcherPath = Path.GetDirectoryName(launcherFile); + if (launcherPath != null) + { + Directory.CreateDirectory(launcherPath); + } + await File.WriteAllTextAsync(desktopFile, contents, token); + await File.WriteAllTextAsync(launcherFile, contents, token); + await Task.Run(() => + { + var startInfo = new ProcessStartInfo("chmod", $"+x \"{desktopFile}\"") + { + UseShellExecute = false, + WindowStyle = ProcessWindowStyle.Hidden, + CreateNoWindow = true + }; + var proc = Process.Start(startInfo); + proc!.WaitForExit(); + }, token); + } + public async Task UIUpdateTask(CancellationToken token) { while (!token.IsCancellationRequested) @@ -894,10 +938,12 @@ await MessageBox.Avalonia.MessageBoxManager.GetMessageBoxStandardWindow(new Mess } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && vsInstallProvider.Model.InstallingVsCode) { - // Create Linux desktop shortcut - var desktopFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Desktop", $@"FRC VS Code {frcYear}.desktop"); - var launcherFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local/share/applications", $@"FRC VS Code {frcYear}.desktop"); - string contents = $@"#!/usr/bin/env xdg-open + if (vsInstallProvider.Model.InstallingVsCode) + { + // Create Linux desktop shortcut + var desktopFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Desktop", $@"FRC VS Code {frcYear}.desktop"); + var launcherFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local/share/applications", $@"FRC VS Code {frcYear}.desktop"); + string contents = $@"#!/usr/bin/env xdg-open [Desktop Entry] Version=1.0 Type=Application @@ -911,29 +957,43 @@ [Desktop Entry] StartupWMClass=Code "; - var desktopPath = Path.GetDirectoryName(desktopFile); - if (desktopPath != null) - { - Directory.CreateDirectory(desktopPath); - } - var launcherPath = Path.GetDirectoryName(launcherFile); - if (launcherPath != null) - { - Directory.CreateDirectory(launcherPath); - } - await File.WriteAllTextAsync(desktopFile, contents, token); - await File.WriteAllTextAsync(launcherFile, contents, token); - await Task.Run(() => - { - var startInfo = new ProcessStartInfo("chmod", $"+x \"{desktopFile}\"") + var desktopPath = Path.GetDirectoryName(desktopFile); + if (desktopPath != null) { - UseShellExecute = false, - WindowStyle = ProcessWindowStyle.Hidden, - CreateNoWindow = true - }; - var proc = Process.Start(startInfo); - proc!.WaitForExit(); - }, token); + Directory.CreateDirectory(desktopPath); + } + var launcherPath = Path.GetDirectoryName(launcherFile); + if (launcherPath != null) + { + Directory.CreateDirectory(launcherPath); + } + await File.WriteAllTextAsync(desktopFile, contents, token); + await File.WriteAllTextAsync(launcherFile, contents, token); + await Task.Run(() => + { + var startInfo = new ProcessStartInfo("chmod", $"+x \"{desktopFile}\"") + { + UseShellExecute = false, + WindowStyle = ProcessWindowStyle.Hidden, + CreateNoWindow = true + }; + var proc = Process.Start(startInfo); + proc!.WaitForExit(); + }, token); + } + + CreateLinuxShortcut("Choreo", frcYear, token); + CreateLinuxShortcut("AdvantageScope", frcYear, token); + CreateLinuxShortcut("Glass", frcYear, token); + CreateLinuxShortcut("OutlineViewer", frcYear, token); + CreateLinuxShortcut("DataLogTool", frcYear, token); + CreateLinuxShortcut("SysId", frcYear, token); + CreateLinuxShortcut("ToolsUpdater", frcYear, token); + CreateLinuxShortcut("SmartDashboard", frcYear, token); + CreateLinuxShortcut("RobotBuilder", frcYear, token); + CreateLinuxShortcut("PathWeaver", frcYear, token); + CreateLinuxShortcut("roboRIOTeamNumberSetter", frcYear, token); + CreateLinuxShortcut("Shuffleboard", frcYear, token); } } }