Skip to content

Commit

Permalink
Warn when using a development build
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed May 31, 2024
1 parent 5d72dd6 commit f90a9bf
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 27 deletions.
4 changes: 4 additions & 0 deletions LightBulb/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ public static class Program

public static string VersionString { get; } = Version.ToString(3);

public static bool IsDevelopmentBuild { get; } = Version.Major is <= 0 or >= 999;

public static string ExecutableDirPath { get; } = AppContext.BaseDirectory;

public static string ExecutableFilePath { get; } =
Path.ChangeExtension(Assembly.Location, "exe");

public static string ProjectUrl { get; } = "https://github.com/Tyrrrz/LightBulb";

public static string ProjectReleasesUrl { get; } = $"{ProjectUrl}/releases";

public static AppBuilder BuildAvaloniaApp() =>
AppBuilder.Configure<App>().UsePlatformDetect().LogToTrace();

Expand Down
80 changes: 53 additions & 27 deletions LightBulb/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Avalonia;
using CommunityToolkit.Mvvm.Input;
Expand Down Expand Up @@ -59,6 +60,56 @@ Do you want to install it now?
Environment.Exit(2);
}

private async Task ShowUkraineSupportMessageAsync()
{
if (!settingsService.IsUkraineSupportMessageEnabled)
return;

var dialog = viewModelManager.CreateMessageBoxViewModel(
"Thank you for supporting Ukraine!",
"""
As Russia wages a genocidal war against my country, I'm grateful to everyone who continues to stand with Ukraine in our fight for freedom.
Click LEARN MORE to find ways that you can help.
""",
"LEARN MORE",
"CLOSE"
);

// Disable this message in the future
settingsService.IsUkraineSupportMessageEnabled = false;
settingsService.Save();

if (await dialogManager.ShowDialogAsync(dialog) != true)
return;

ProcessEx.StartShellExecute("https://tyrrrz.me/ukraine?source=lightbulb");
}

private async Task ShowDevelopmentBuildMessageAsync()
{
if (!Program.IsDevelopmentBuild)
return;

// If debugging, the user is likely a developer
if (Debugger.IsAttached)
return;

var dialog = viewModelManager.CreateMessageBoxViewModel(
"Unstable build warning",
"""
You're using a development build of the application. These builds are not thoroughly tested and may contain bugs.
Auto-updates are disabled for development builds. If you want to switch to a stable release, please download it manually.
""",
"SEE RELEASES",
"CLOSE"
);

if (await dialogManager.ShowDialogAsync(dialog) == true)
ProcessEx.StartShellExecute(Program.ProjectReleasesUrl);
}

private async Task ShowGammaRangePromptAsync()
{
if (settingsService.IsExtendedGammaRangeUnlocked)
Expand Down Expand Up @@ -114,39 +165,14 @@ Press OK to open settings.
await dialogManager.ShowDialogAsync(settingsDialog);
}

private async Task ShowUkraineSupportMessageAsync()
{
if (!settingsService.IsUkraineSupportMessageEnabled)
return;

var dialog = viewModelManager.CreateMessageBoxViewModel(
"Thank you for supporting Ukraine!",
"""
As Russia wages a genocidal war against my country, I'm grateful to everyone who continues to stand with Ukraine in our fight for freedom.
Click LEARN MORE to find ways that you can help.
""",
"LEARN MORE",
"CLOSE"
);

// Disable this message in the future
settingsService.IsUkraineSupportMessageEnabled = false;
settingsService.Save();

if (await dialogManager.ShowDialogAsync(dialog) != true)
return;

ProcessEx.StartShellExecute("https://tyrrrz.me/ukraine?source=lightbulb");
}

[RelayCommand]
private async Task InitializeAsync()
{
await FinalizePendingUpdateAsync();
await ShowUkraineSupportMessageAsync();
await ShowDevelopmentBuildMessageAsync();
await ShowGammaRangePromptAsync();
await ShowFirstTimeExperienceMessageAsync();
await ShowUkraineSupportMessageAsync();

_checkForUpdatesTimer.Start();
}
Expand Down

0 comments on commit f90a9bf

Please sign in to comment.