From 429801183ccc640db75366cdd9747a5cba469c62 Mon Sep 17 00:00:00 2001 From: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com> Date: Sat, 1 Jun 2024 00:58:24 +0300 Subject: [PATCH] Warn when using development build (#1248) --- DiscordChatExporter.Gui/Program.cs | 6 ++++- .../Components/DashboardViewModel.cs | 2 +- .../ViewModels/MainViewModel.cs | 26 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/DiscordChatExporter.Gui/Program.cs b/DiscordChatExporter.Gui/Program.cs index 544c0064..1ff84103 100644 --- a/DiscordChatExporter.Gui/Program.cs +++ b/DiscordChatExporter.Gui/Program.cs @@ -15,9 +15,13 @@ 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 ProjectUrl { get; } = "https://github.com/Tyrrrz/DiscordChatExporter"; - public static string DocumentationUrl { get; } = ProjectUrl + "/tree/master/.docs"; + public static string ProjectReleasesUrl { get; } = $"{ProjectUrl}/releases"; + + public static string ProjectDocumentationUrl { get; } = ProjectUrl + "/tree/master/.docs"; public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure().UsePlatformDetect().LogToTrace(); diff --git a/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs b/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs index 5ee722f6..91728805 100644 --- a/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs +++ b/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs @@ -102,7 +102,7 @@ public partial class DashboardViewModel : ViewModelBase await _dialogManager.ShowDialogAsync(_viewModelManager.CreateSettingsViewModel()); [RelayCommand] - private void ShowHelp() => ProcessEx.StartShellExecute(Program.DocumentationUrl); + private void ShowHelp() => ProcessEx.StartShellExecute(Program.ProjectDocumentationUrl); private bool CanPullGuilds() => !IsBusy && !string.IsNullOrWhiteSpace(Token); diff --git a/DiscordChatExporter.Gui/ViewModels/MainViewModel.cs b/DiscordChatExporter.Gui/ViewModels/MainViewModel.cs index deced764..c96cb458 100644 --- a/DiscordChatExporter.Gui/ViewModels/MainViewModel.cs +++ b/DiscordChatExporter.Gui/ViewModels/MainViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Threading.Tasks; using Avalonia; using CommunityToolkit.Mvvm.Input; @@ -46,6 +47,30 @@ public partial class MainViewModel( ProcessEx.StartShellExecute("https://tyrrrz.me/ukraine?source=discordchatexporter"); } + 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 CheckForUpdatesAsync() { try @@ -80,6 +105,7 @@ public partial class MainViewModel( private async Task InitializeAsync() { await ShowUkraineSupportMessageAsync(); + await ShowDevelopmentBuildMessageAsync(); await CheckForUpdatesAsync(); }