Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add launcher shortcuts on Linux #458

Merged
merged 9 commits into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 88 additions & 27 deletions WPILibInstaller-Avalonia/ViewModels/InstallPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,52 @@ public class InstallPageViewModel : PageViewModelBase
public int ProgressTotal { get; set; }
public string TextTotal { get; set; } = "";

private async void CreateLinuxShortcut(String name, String frcYear, String wmClass, CancellationToken token)
{
var launcherFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local/share/applications", $@"{name} {frcYear}.desktop");
string contents;
if (name.Contains("WPILib"))
{
var nameNoWPILib = name.Remove(name.Length - " (WPILib)".Length);
contents = $@"#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Categories=Robotics;Science
Name={name} {frcYear}
Comment={nameNoWPILib} tool for the 2025 FIRST Robotics Competition season
Exec={configurationProvider.InstallDirectory}/tools/{nameNoWPILib}.sh
Icon={configurationProvider.InstallDirectory}/frccode/wpilib-256.ico
Terminal=false
StartupNotify=true
StartupWMClass={wmClass}
";

}
else
{
contents = $@"#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Categories=Robotics;Science
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={wmClass}
";
}
var launcherPath = Path.GetDirectoryName(launcherFile);
if (launcherPath != null)
{
Directory.CreateDirectory(launcherPath);
}
await File.WriteAllTextAsync(launcherFile, contents, token);
}

public async Task UIUpdateTask(CancellationToken token)
{
while (!token.IsCancellationRequested)
Expand Down Expand Up @@ -940,12 +986,14 @@ await MessageBox.Avalonia.MessageBoxManager.GetMessageBoxStandardWindow(new Mess
break;
} while (true);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && vsInstallProvider.Model.InstallingVsCode)
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
// 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
Expand All @@ -959,29 +1007,42 @@ [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("AdvantageScope (WPILib)", frcYear, "AdvantageScope", token);
CreateLinuxShortcut("Elastic (WPILib)", frcYear, "Elastic", token);
CreateLinuxShortcut("Glass", frcYear, "Glass - DISCONNECTED", token);
CreateLinuxShortcut("OutlineViewer", frcYear, "OutlineViewer - DISCONNECTED", token);
CreateLinuxShortcut("DataLogTool", frcYear, "Datalog Tool", token);
CreateLinuxShortcut("SysId", frcYear, "System Identification", token);
CreateLinuxShortcut("SmartDashboard", frcYear, "edu-wpi-first-smartdashboard-SmartDashboard", token);
CreateLinuxShortcut("RobotBuilder", frcYear, "robotbuilder-RobotBuilder", token);
CreateLinuxShortcut("PathWeaver", frcYear, "edu.wpi.first.pathweaver.PathWeaver", token);
CreateLinuxShortcut("roboRIOTeamNumberSetter", frcYear, "roboRIO Team Number Setter", token);
CreateLinuxShortcut("Shuffleboard", frcYear, "edu.wpi.first.shuffleboard.app.Shuffleboard", token);
}
}
}
Expand Down
Loading