Skip to content

Commit cf800c1

Browse files
committed
Add launcher shortcuts on Linux
Doesn't add desktop shortcuts due to complications with how gnome handles desktop files Resolves #136 Signed-off-by: Jade Turner <[email protected]>
1 parent 52bc77e commit cf800c1

File tree

1 file changed

+88
-27
lines changed

1 file changed

+88
-27
lines changed

WPILibInstaller-Avalonia/ViewModels/InstallPageViewModel.cs

Lines changed: 88 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,52 @@ public class InstallPageViewModel : PageViewModelBase
3131
public int ProgressTotal { get; set; }
3232
public string TextTotal { get; set; } = "";
3333

34+
private async void CreateLinuxShortcut(String name, String frcYear, CancellationToken token)
35+
{
36+
var launcherFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local/share/applications", $@"{name} {frcYear}.desktop");
37+
string contents;
38+
if (name.Contains("WPILib"))
39+
{
40+
var nameNoWPILib = name.Remove(name.Length - " (WPILib)".Length);
41+
contents = $@"#!/usr/bin/env xdg-open
42+
[Desktop Entry]
43+
Version=1.0
44+
Type=Application
45+
Categories=Robotics
46+
Name={name} {frcYear}
47+
Comment={nameNoWPILib} tool for the 2025 FIRST Robotics Competition season
48+
Exec={configurationProvider.InstallDirectory}/tools/{nameNoWPILib}.sh
49+
Icon={configurationProvider.InstallDirectory}/frccode/wpilib-256.ico
50+
Terminal=false
51+
StartupNotify=true
52+
StartupWMClass=Code
53+
";
54+
55+
}
56+
else
57+
{
58+
contents = $@"#!/usr/bin/env xdg-open
59+
[Desktop Entry]
60+
Version=1.0
61+
Type=Application
62+
Categories=Robotics
63+
Name={name} {frcYear}
64+
Comment={name} tool for the 2025 FIRST Robotics Competition season
65+
Exec={configurationProvider.InstallDirectory}/tools/{name}.sh
66+
Icon={configurationProvider.InstallDirectory}/frccode/wpilib-256.ico
67+
Terminal=false
68+
StartupNotify=true
69+
StartupWMClass=Code
70+
";
71+
}
72+
var launcherPath = Path.GetDirectoryName(launcherFile);
73+
if (launcherPath != null)
74+
{
75+
Directory.CreateDirectory(launcherPath);
76+
}
77+
await File.WriteAllTextAsync(launcherFile, contents, token);
78+
}
79+
3480
public async Task UIUpdateTask(CancellationToken token)
3581
{
3682
while (!token.IsCancellationRequested)
@@ -892,12 +938,14 @@ await MessageBox.Avalonia.MessageBoxManager.GetMessageBoxStandardWindow(new Mess
892938
break;
893939
} while (true);
894940
}
895-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && vsInstallProvider.Model.InstallingVsCode)
941+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
896942
{
897-
// Create Linux desktop shortcut
898-
var desktopFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Desktop", $@"FRC VS Code {frcYear}.desktop");
899-
var launcherFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local/share/applications", $@"FRC VS Code {frcYear}.desktop");
900-
string contents = $@"#!/usr/bin/env xdg-open
943+
if (vsInstallProvider.Model.InstallingVsCode)
944+
{
945+
// Create Linux desktop shortcut
946+
var desktopFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Desktop", $@"FRC VS Code {frcYear}.desktop");
947+
var launcherFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local/share/applications", $@"FRC VS Code {frcYear}.desktop");
948+
string contents = $@"#!/usr/bin/env xdg-open
901949
[Desktop Entry]
902950
Version=1.0
903951
Type=Application
@@ -911,29 +959,42 @@ [Desktop Entry]
911959
StartupWMClass=Code
912960
";
913961

914-
var desktopPath = Path.GetDirectoryName(desktopFile);
915-
if (desktopPath != null)
916-
{
917-
Directory.CreateDirectory(desktopPath);
918-
}
919-
var launcherPath = Path.GetDirectoryName(launcherFile);
920-
if (launcherPath != null)
921-
{
922-
Directory.CreateDirectory(launcherPath);
923-
}
924-
await File.WriteAllTextAsync(desktopFile, contents, token);
925-
await File.WriteAllTextAsync(launcherFile, contents, token);
926-
await Task.Run(() =>
927-
{
928-
var startInfo = new ProcessStartInfo("chmod", $"+x \"{desktopFile}\"")
962+
var desktopPath = Path.GetDirectoryName(desktopFile);
963+
if (desktopPath != null)
929964
{
930-
UseShellExecute = false,
931-
WindowStyle = ProcessWindowStyle.Hidden,
932-
CreateNoWindow = true
933-
};
934-
var proc = Process.Start(startInfo);
935-
proc!.WaitForExit();
936-
}, token);
965+
Directory.CreateDirectory(desktopPath);
966+
}
967+
var launcherPath = Path.GetDirectoryName(launcherFile);
968+
if (launcherPath != null)
969+
{
970+
Directory.CreateDirectory(launcherPath);
971+
}
972+
await File.WriteAllTextAsync(desktopFile, contents, token);
973+
await File.WriteAllTextAsync(launcherFile, contents, token);
974+
await Task.Run(() =>
975+
{
976+
var startInfo = new ProcessStartInfo("chmod", $"+x \"{desktopFile}\"")
977+
{
978+
UseShellExecute = false,
979+
WindowStyle = ProcessWindowStyle.Hidden,
980+
CreateNoWindow = true
981+
};
982+
var proc = Process.Start(startInfo);
983+
proc!.WaitForExit();
984+
}, token);
985+
}
986+
987+
CreateLinuxShortcut("Choreo (WPILib)", frcYear, token);
988+
CreateLinuxShortcut("AdvantageScope (WPILib)", frcYear, token);
989+
CreateLinuxShortcut("Glass", frcYear, token);
990+
CreateLinuxShortcut("OutlineViewer", frcYear, token);
991+
CreateLinuxShortcut("DataLogTool", frcYear, token);
992+
CreateLinuxShortcut("SysId", frcYear, token);
993+
CreateLinuxShortcut("SmartDashboard", frcYear, token);
994+
CreateLinuxShortcut("RobotBuilder", frcYear, token);
995+
CreateLinuxShortcut("PathWeaver", frcYear, token);
996+
CreateLinuxShortcut("roboRIOTeamNumberSetter", frcYear, token);
997+
CreateLinuxShortcut("Shuffleboard", frcYear, token);
937998
}
938999
}
9391000
}

0 commit comments

Comments
 (0)