Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<Border Height="16"/>

<settings:CheckboxCard SettingName="DisableClassicMode"
<settings:CheckboxCard SettingName="UseClassicMode"
Text="{t:Translate Use classic mode}"
WarningText="{t:Translate Restart UniGetUI to apply this change}"
StateChangedCommand="{Binding ShowRestartRequiredCommand}"
Expand Down
2 changes: 2 additions & 0 deletions src/UniGetUI.Core.Settings/SettingsEngine_Names.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public enum K
WinGetComApiPolicy,
WinGetDownloadFullManifest,
DisableClassicMode,
UseClassicMode,
DisableInstallerHostChangeWarning,
BunPreferLatestVersions,
RedactUsernameInLog,
Expand Down Expand Up @@ -198,6 +199,7 @@ public static string ResolveKey(K key)
K.WinGetComApiPolicy => "WinGetComApiPolicy",
K.WinGetDownloadFullManifest => "WinGetDownloadFullManifest",
K.DisableClassicMode => "DisableClassicMode",
K.UseClassicMode => "UseClassicMode",
K.DisableInstallerHostChangeWarning => "DisableInstallerHostChangeWarning",
K.BunPreferLatestVersions => "BunPreferLatestVersions",
K.RedactUsernameInLog => "RedactUsernameInLog",
Expand Down
72 changes: 67 additions & 5 deletions src/UniGetUI.Tests/ModernAppLauncherTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Runtime.InteropServices;
using UniGetUI.Core.Data;
using UniGetUI.Core.SettingsEngine;

Expand Down Expand Up @@ -28,25 +29,35 @@ public void Dispose()
}

[Fact]
public void ClassicModeDefaultsToEnabled()
public void ClassicModeDefaultsToDisabled()
{
Assert.True(ModernAppLauncher.IsClassicModeEnabled());
Assert.False(ModernAppLauncher.IsClassicModeEnabled());

Settings.Set(Settings.K.DisableClassicMode, true);
Settings.Set(Settings.K.UseClassicMode, true);

Assert.False(ModernAppLauncher.IsClassicModeEnabled());
Assert.True(ModernAppLauncher.IsClassicModeEnabled());
}

[Fact]
public void BetaTestersDefaultToModernUI()
public void BetaTestersAlwaysUseModernUI()
{
Settings.Set(Settings.K.UseClassicMode, true);

Assert.True(ModernAppLauncher.IsClassicModeEnabled());

Settings.Set(Settings.K.EnableUniGetUIBeta, true);

Assert.False(ModernAppLauncher.IsClassicModeEnabled());
}

[Fact]
public void LegacyDisableClassicModeSettingDoesNotEnableClassicMode()
{
Settings.Set(Settings.K.DisableClassicMode, true);

Assert.False(ModernAppLauncher.IsClassicModeEnabled());
}

[Fact]
public void ResolveModernExecutablePath_PrefersRootExecutable()
{
Expand Down Expand Up @@ -107,6 +118,57 @@ public void ResolveModernExecutablePath_FindsDevelopmentBuildOutput()
Assert.Equal(expected, ModernAppLauncher.ResolveModernExecutablePath(baseDirectory));
}

[Fact]
public void ResolveModernExecutablePath_PrefersCurrentArchitectureDevelopmentBuildOutput()
{
string baseDirectory = Path.Combine(
_testRoot,
"UniGetUI",
"bin",
"x64",
"Debug",
"net10.0-windows10.0.26100.0",
"win-x64"
);
Directory.CreateDirectory(baseDirectory);

string currentRuntimeIdentifier = RuntimeInformation.ProcessArchitecture switch
{
Architecture.X64 => "win-x64",
Architecture.Arm64 => "win-arm64",
Architecture.X86 => "win-x86",
Architecture.Arm => "win-arm",
_ => "win-x64",
};
string otherRuntimeIdentifier = currentRuntimeIdentifier == "win-x64"
? "win-arm64"
: "win-x64";

string expected = CreateAvaloniaDevelopmentExecutable(currentRuntimeIdentifier);
string other = CreateAvaloniaDevelopmentExecutable(otherRuntimeIdentifier);

File.SetLastWriteTimeUtc(expected, DateTime.UtcNow.AddMinutes(-5));
File.SetLastWriteTimeUtc(other, DateTime.UtcNow);

Assert.Equal(expected, ModernAppLauncher.ResolveModernExecutablePath(baseDirectory));
}

private string CreateAvaloniaDevelopmentExecutable(string runtimeIdentifier)
{
string path = Path.Combine(
_testRoot,
"UniGetUI.Avalonia",
"bin",
"Debug",
"net10.0-windows10.0.26100.0",
runtimeIdentifier,
ModernAppLauncher.ModernAppExecutableName
);
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
File.WriteAllText(path, "");
return path;
}

[Fact]
public void CreateStartInfo_PreservesArguments()
{
Expand Down
24 changes: 22 additions & 2 deletions src/UniGetUI/ModernAppLauncher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using UniGetUI.Core.Logging;
using UniGetUI.Core.SettingsEngine;

Expand All @@ -10,7 +11,7 @@ internal static class ModernAppLauncher
internal const string ModernAppExecutableName = "UniGetUI.Avalonia.exe";

public static bool IsClassicModeEnabled() =>
!Settings.Get(Settings.K.DisableClassicMode) && !Settings.Get(Settings.K.EnableUniGetUIBeta);
Settings.Get(Settings.K.UseClassicMode) && !Settings.Get(Settings.K.EnableUniGetUIBeta);

public static void Launch(string[] args)
{
Expand Down Expand Up @@ -89,7 +90,8 @@ string candidate in Directory
ModernAppExecutableName,
SearchOption.AllDirectories
)
.OrderByDescending(File.GetLastWriteTimeUtc)
.OrderByDescending(IsCurrentRuntimeCandidate)
.ThenByDescending(File.GetLastWriteTimeUtc)
)
{
yield return candidate;
Expand All @@ -99,4 +101,22 @@ string candidate in Directory
directory = directory.Parent;
}
}

private static bool IsCurrentRuntimeCandidate(string candidate)
{
string runtimeIdentifier = RuntimeInformation.ProcessArchitecture switch
{
Architecture.X64 => "win-x64",
Architecture.Arm64 => "win-arm64",
Architecture.X86 => "win-x86",
Architecture.Arm => "win-arm",
_ => "",
};

return runtimeIdentifier.Length > 0
&& candidate.Contains(
$"{Path.DirectorySeparatorChar}{runtimeIdentifier}{Path.DirectorySeparatorChar}",
StringComparison.OrdinalIgnoreCase
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<UserControl Height="16" />
<widgets:CheckboxCard
CornerRadius="8"
SettingName="DisableClassicMode"
SettingName="UseClassicMode"
StateChanged="ShowRestartBanner"
Text="Use classic mode"
WarningText="Restart UniGetUI to apply this change"
Expand Down
Loading