-
Notifications
You must be signed in to change notification settings - Fork 937
Relaunch UniGetUI through /bin/sh instead of powershell.exe off Windows #5418
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
Merged
Gabriel Dufresne (GabrielDuf)
merged 2 commits into
Devolutions:main
from
awss1i:fix/relaunch-off-windows
Sep 28, 2026
+314
−12
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| namespace UniGetUI.Core.Tools.Tests; | ||
|
|
||
| // xUnit 2 has no runtime skip; setting Skip in the attribute makes a test for another platform | ||
| // report as skipped instead of passing without running. | ||
|
|
||
| public sealed class WindowsFactAttribute : FactAttribute | ||
| { | ||
| public WindowsFactAttribute() | ||
| { | ||
| if (!OperatingSystem.IsWindows()) | ||
| { | ||
| Skip = "Runs on Windows only"; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public sealed class UnixFactAttribute : FactAttribute | ||
| { | ||
| public UnixFactAttribute() | ||
| { | ||
| if (OperatingSystem.IsWindows()) | ||
| { | ||
| Skip = "Runs on Linux and macOS only"; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public sealed class MacOSFactAttribute : FactAttribute | ||
| { | ||
| public MacOSFactAttribute() | ||
| { | ||
| if (!OperatingSystem.IsMacOS()) | ||
| { | ||
| Skip = "Runs on macOS only"; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| using System.Diagnostics; | ||
| using System.Runtime.Versioning; | ||
| using UniGetUI.Core.Tools; | ||
|
|
||
| namespace UniGetUI.Core.Tools.Tests; | ||
|
|
||
| public class RelaunchTests | ||
| { | ||
| [WindowsFact] | ||
| public void CreateRelaunchStartInfo_OnWindows_WaitsAndStartsThroughPowerShell() | ||
| { | ||
| ProcessStartInfo startInfo = CoreTools.CreateRelaunchStartInfo( | ||
| 4242, | ||
| @"C:\Users\O'Brien\UniGetUI\UniGetUI.exe" | ||
| ); | ||
|
|
||
| Assert.Equal("powershell.exe", startInfo.FileName); | ||
| Assert.Equal( | ||
| "-NoProfile -WindowStyle Hidden -Command \"Wait-Process -Id 4242; " | ||
| + @"Start-Process -FilePath 'C:\Users\O''Brien\UniGetUI\UniGetUI.exe'""", | ||
| startInfo.Arguments | ||
| ); | ||
| Assert.Empty(startInfo.ArgumentList); | ||
| Assert.False(startInfo.UseShellExecute); | ||
| Assert.True(startInfo.CreateNoWindow); | ||
| } | ||
|
|
||
| [UnixFact] | ||
| public void CreateRelaunchStartInfo_OffWindows_WaitsForThePidInAShellHelper() | ||
| { | ||
| ProcessStartInfo startInfo = CoreTools.CreateRelaunchStartInfo(4242, "/opt/unigetui/UniGetUI"); | ||
|
|
||
| Assert.Equal("/bin/sh", startInfo.FileName); | ||
| Assert.Equal("", startInfo.Arguments); | ||
| Assert.Equal(6, startInfo.ArgumentList.Count); | ||
| Assert.Equal("-c", startInfo.ArgumentList[0]); | ||
| Assert.Contains("kill -0 \"$pid\"", startInfo.ArgumentList[1]); | ||
| Assert.Contains("\"$exe\" >/dev/null 2>&1 &", startInfo.ArgumentList[1]); | ||
| Assert.Contains("/usr/bin/open -na \"$bundle\" || \"$exe\" >/dev/null 2>&1 &", startInfo.ArgumentList[1]); | ||
| Assert.Equal("sh", startInfo.ArgumentList[2]); | ||
| Assert.Equal("4242", startInfo.ArgumentList[3]); | ||
| Assert.Equal("/opt/unigetui/UniGetUI", startInfo.ArgumentList[4]); | ||
| Assert.Equal("", startInfo.ArgumentList[5]); | ||
| Assert.False(startInfo.UseShellExecute); | ||
| } | ||
|
|
||
| [MacOSFact] | ||
| public void CreateRelaunchStartInfo_OnMacOs_PassesTheBundleToTheHelper() | ||
| { | ||
| ProcessStartInfo startInfo = CoreTools.CreateRelaunchStartInfo( | ||
| 4242, | ||
| "/Applications/UniGetUI.app/Contents/MacOS/UniGetUI" | ||
| ); | ||
|
|
||
| Assert.Equal("/Applications/UniGetUI.app", startInfo.ArgumentList[5]); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("/Applications/UniGetUI.app/Contents/MacOS/UniGetUI", "UniGetUI.app")] | ||
| [InlineData("/Users/me/My Apps/UniGetUI.app/Contents/MacOS/UniGetUI", "UniGetUI.app")] | ||
| public void FindAppBundle_ReturnsTheBundleThatContainsTheExecutable(string executable, string bundleName) | ||
| { | ||
| string? bundle = CoreTools.FindAppBundle(executable); | ||
|
|
||
| Assert.NotNull(bundle); | ||
| Assert.Equal(bundleName, Path.GetFileName(bundle)); | ||
| Assert.EndsWith(bundleName, bundle); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("/opt/unigetui/UniGetUI")] | ||
| [InlineData("/home/me/UniGetUI.app.bak/bin/UniGetUI")] | ||
| [InlineData("UniGetUI")] | ||
| public void FindAppBundle_ReturnsNullOutsideABundle(string executable) | ||
| { | ||
| Assert.Null(CoreTools.FindAppBundle(executable)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TryStartRelaunchHelper_ReturnsFalseWhenTheHelperCannotStart() | ||
| { | ||
| var startInfo = new ProcessStartInfo( | ||
| Path.Combine(Path.GetTempPath(), "unigetui-missing-" + Path.GetRandomFileName()) | ||
| ) | ||
| { | ||
| UseShellExecute = false, | ||
| }; | ||
|
|
||
| Assert.False(CoreTools.TryStartRelaunchHelper(startInfo)); | ||
| } | ||
|
|
||
| // The real helper: a sleeping child stands in for the exiting UniGetUI, and the "executable" is | ||
| // a script that leaves a marker. The marker must not appear while the child is alive. | ||
| [UnixFact] | ||
| [UnsupportedOSPlatform("windows")] | ||
| public Task RelaunchHelper_StartsTheExecutableOnlyAfterTheProcessExits() => | ||
| AssertHelperRelaunchesAfterExitAsync(bundle: null); | ||
|
|
||
| // A bundle open refuses (here one that does not exist; on Linux there is no /usr/bin/open at | ||
| // all) must fall back to starting the executable instead of leaving nothing running. | ||
| [UnixFact] | ||
| [UnsupportedOSPlatform("windows")] | ||
| public Task RelaunchHelper_StartsTheExecutableWhenOpenRejectsTheBundle() => | ||
| AssertHelperRelaunchesAfterExitAsync( | ||
| bundle: Path.Combine(Path.GetTempPath(), "unigetui-missing-" + Path.GetRandomFileName(), "UniGetUI.app") | ||
| ); | ||
|
|
||
| [UnsupportedOSPlatform("windows")] | ||
| private static async Task AssertHelperRelaunchesAfterExitAsync(string? bundle) | ||
| { | ||
| string directory = Path.Combine(Path.GetTempPath(), "unigetui-relaunch-" + Path.GetRandomFileName()); | ||
| Directory.CreateDirectory(directory); | ||
| string marker = Path.Combine(directory, "relaunched"); | ||
| string target = Path.Combine(directory, "target.sh"); | ||
| File.WriteAllText(target, $"#!/bin/sh\ntouch \"{marker}\"\n"); | ||
| File.SetUnixFileMode(target, UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute); | ||
|
|
||
| using var standIn = Process.Start(new ProcessStartInfo("sleep", "1.5") { UseShellExecute = false })!; | ||
| try | ||
| { | ||
| ProcessStartInfo startInfo = CoreTools.CreateRelaunchStartInfo(standIn.Id, target); | ||
| if (bundle is not null) | ||
| { | ||
| startInfo.ArgumentList[5] = bundle; | ||
| } | ||
|
|
||
| using var helper = Process.Start(startInfo); | ||
| Assert.NotNull(helper); | ||
|
|
||
| await Task.Delay(500); | ||
| Assert.False(standIn.HasExited); | ||
| Assert.False(File.Exists(marker), "the helper must not start the executable while the process is alive"); | ||
|
|
||
| await standIn.WaitForExitAsync(); | ||
| var deadline = DateTime.UtcNow.AddSeconds(5); | ||
| while (!File.Exists(marker) && DateTime.UtcNow < deadline) | ||
| { | ||
| await Task.Delay(100); | ||
| } | ||
|
|
||
| Assert.True(File.Exists(marker), "the helper did not start the executable after the process exited"); | ||
| await helper.WaitForExitAsync(); | ||
| Assert.Equal(0, helper.ExitCode); | ||
| } | ||
| finally | ||
| { | ||
| if (!standIn.HasExited) | ||
| { | ||
| standIn.Kill(); | ||
| } | ||
|
|
||
| Directory.Delete(directory, recursive: true); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| using System.Runtime.CompilerServices; | ||
|
|
||
| [assembly: InternalsVisibleTo("UniGetUI.Core.Tools.Tests")] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.