Free, open-source Windows optimization tool for performance, privacy, and simplicity.
C# csharpdebloatdotnetgamingopen-sourceoptimizationoptimizeroptimizerduckperformanceprivacytweakertweakswindowswinui
feat: add update checker and notification UI
itsfatduck7f3ec02b2429
diff --git a/optimizerDuck/App.xaml.cs b/optimizerDuck/App.xaml.csindex 45d7181..03aac86 100644--- a/optimizerDuck/App.xaml.cs+++ b/optimizerDuck/App.xaml.cs@@ -171,6 +171,7 @@ public partial class App : Applicationservices.AddSingleton<OptimizationService>();services.AddSingleton<SystemInfoService>();services.AddSingleton<StreamService>();+ services.AddSingleton<UpdaterService>();}).Build();diff --git a/optimizerDuck/Core/Models/UI/OptimizationTags.cs b/optimizerDuck/Core/Models/UI/OptimizationTags.csindex 8210755..cddc31f 100644--- a/optimizerDuck/Core/Models/UI/OptimizationTags.cs+++ b/optimizerDuck/Core/Models/UI/OptimizationTags.cs@@ -105,7 +105,7 @@ public static class OptimizationTagsToDisplayTranslations.Optimizer_UI_Tags_Security),OptimizationTags.NetworkRequired => new OptimizationTagDisplay(- SymbolRegular.NetworkAdapter16,+ SymbolRegular.Wifi120,Translations.Optimizer_UI_Tags_NetworkRequired),OptimizationTags.Nvidia => new OptimizationTagDisplay(diff --git a/optimizerDuck/Services/UpdaterService.cs b/optimizerDuck/Services/UpdaterService.csnew file mode 100644index 0000000..0c9e397--- /dev/null+++ b/optimizerDuck/Services/UpdaterService.cs@@ -0,0 +1,108 @@+using System.Diagnostics;+using System.IO;+using System.Net.Http;+using System.Net.Http.Headers;+using System.Reflection;+using Microsoft.Extensions.Logging;+using Newtonsoft.Json;+using optimizerDuck.Common.Extensions;++namespace optimizerDuck.Services;++public class UpdaterService+{+ private const string Owner = "itsfatduck";+ private const string Repo = "optimizerDuck";+ private readonly HttpClient _httpClient;+ private readonly ILogger _logger;++ public UpdaterService(ILogger<UpdaterService> logger)+ {+ _httpClient = new HttpClient();+ _httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("optimizerDuck", "1.0"));+ _logger = logger;+ }++ public async Task<bool> CheckForUpdatesAsync()+ {+ _logger.LogInformation("Checking for updates...");++ try+ {+ var response =+ await _httpClient.GetStringAsync($"https://api.github.com/repos/{Owner}/{Repo}/releases/latest");+ var latestRelease = JsonConvert.DeserializeObject<GitHubRelease>(response);++ if (latestRelease == null || string.IsNullOrEmpty(latestRelease.TagName))+ {+ _logger.LogWarning("Could not retrieve latest release information");+ return false;+ }++ // "v1.1.0" -> "1.1.0"+ var latestVersionStr = latestRelease.TagName.TrimStart('v');++ // "1.1.0-fix" -> "1.1.0"+ var preReleaseSeparatorIndex = latestVersionStr.IndexOf('-');+ if (preReleaseSeparatorIndex != -1)+ latestVersionStr = latestVersionStr[..preReleaseSeparatorIndex];++ _logger.LogDebug("Latest release version: {LatestReleaseTagName}", latestRelease.TagName);++ // Parse version+ if (!Version.TryParse(latestVersionStr, out var latestVersion))+ {+ _logger.LogWarning("Could not parse latest release version: {LatestReleaseTagName}", latestRelease.TagName);+ return false;+ }++ var currentVersion = Assembly.GetExecutingAssembly().GetName().Version+ ?? new Version(0, 0, 0);++ if (latestVersion > currentVersion)+ {+ var updateExecutableAsset = latestRelease.Assets+ .FirstOrDefault(a =>+ a.Name.StartsWith("optimizerDuck", StringComparison.OrdinalIgnoreCase)+ && a.Name.EndsWith(".exe", StringComparison.OrdinalIgnoreCase));++ if (updateExecutableAsset == null)+ {+ _logger.LogWarning("No update executable (.exe) found in the latest release");+ return false;+ }++ _logger.LogInformation("A new version ({LatestVersion}) is available!", latestVersionStr);++ return true;+ }+ else+ {+ _logger.LogInformation("You are running the latest version");+ return false;+ }+ }+ catch (Exception ex)+ {+ _logger.LogError(ex, $"Error checking for updates");+ return false;+ }+ }+}++// Helper classes for deserializing GitHub API response+public class GitHubRelease+{+ [JsonProperty("tag_name")] public required string TagName { get; set; }++ [JsonProperty("assets")] public required List<GitHubAsset> Assets { get; set; }++ [JsonProperty("body")] public required string Body { get; set; }+}++public class GitHubAsset+{+ [JsonProperty("name")] public required string Name { get; set; }++ [JsonProperty("browser_download_url")] public required string BrowserDownloadUrl { get; set; }+}\ No newline at end of filediff --git a/optimizerDuck/UI/ViewModels/Pages/DashboardViewModel.cs b/optimizerDuck/UI/ViewModels/Pages/DashboardViewModel.csindex b49c7c7..5c70e73 100644--- a/optimizerDuck/UI/ViewModels/Pages/DashboardViewModel.cs+++ b/optimizerDuck/UI/ViewModels/Pages/DashboardViewModel.cs@@ -18,26 +18,34 @@ public partial class DashboardViewModel : ViewModelprivate readonly ILogger<DashboardViewModel> _logger;private readonly SystemInfoService _systemInfoService;private readonly ISnackbarService _snackbarService;+ private readonly UpdaterService _updaterService;+ private readonly IContentDialogService _contentDialogService;+private readonly DispatcherTimer _updateTimer;[ObservableProperty] private ApplicationTheme _currentApplicationTheme = ApplicationTheme.Unknown;private bool _isInitialized;[ObservableProperty] private bool _isLoading;+ [ObservableProperty] private bool _hasUpdate;[ObservableProperty] private RamInfo _runtimeRam = RamInfo.Unknown;[ObservableProperty] private SystemSnapshot _systemInfo = SystemSnapshot.Unknown;- public DashboardViewModel(SystemInfoService systemInfoService,ISnackbarService snackbarService, ILogger<DashboardViewModel> logger)+ public DashboardViewModel(SystemInfoService systemInfoService, ISnackbarService snackbarService,+ ILogger<DashboardViewModel> logger, UpdaterService updaterService, IContentDialogService contentDialogService){_systemInfoService = systemInfoService;- _snackbarService = snackbarService;+ _snackbarService = snackbarService;_logger = logger;-+ _updaterService = updaterService;+ _contentDialogService = contentDialogService;+_updateTimer = new DispatcherTimer{Interval = TimeSpan.FromSeconds(2)};_updateTimer.Tick += async (s, e) => await UpdateRuntimeInfoAsync();+CurrentApplicationTheme = ApplicationThemeManager.GetAppTheme();ApplicationThemeManager.Changed += OnThemeChanged;}@@ -52,6 +60,7 @@ public partial class DashboardViewModel : ViewModelif (!_isInitialized){_systemInfoService.LogSummary();+ HasUpdate = await _updaterService.CheckForUpdatesAsync();_isInitialized = true;}@@ -211,4 +220,4 @@ public partial class DashboardViewModel : ViewModel}#endregion-}+}\ No newline at end of filediff --git a/optimizerDuck/UI/ViewModels/Pages/SettingsViewModel.cs b/optimizerDuck/UI/ViewModels/Pages/SettingsViewModel.csindex da8afea..cc3dc17 100644--- a/optimizerDuck/UI/ViewModels/Pages/SettingsViewModel.cs+++ b/optimizerDuck/UI/ViewModels/Pages/SettingsViewModel.cs@@ -35,7 +35,6 @@ public partial class SettingsViewModel(//Learn more linkspublic string DiscordInvite { get; } = Shared.DiscordInviteURL;-public string GitHubRepo { get; } = Shared.GitHubRepoURL;public string Documentation { get; } = Shared.GitHubRepoURL + "/wiki";public string SupportMe { get; } = Shared.SupportMeURL;diff --git a/optimizerDuck/UI/Views/Pages/DashboardPage.xaml b/optimizerDuck/UI/Views/Pages/DashboardPage.xamlindex 482179f..d980c7a 100644--- a/optimizerDuck/UI/Views/Pages/DashboardPage.xaml+++ b/optimizerDuck/UI/Views/Pages/DashboardPage.xaml@@ -47,36 +47,45 @@</Grid><!-- Header -->- <Grid ColumnDefinitions="*,Auto" Margin="0,0,0,20">- <ui:TextBlock- FontTypography="Title"- Text="{ext:Loc Dashboard.Header.Title}"- TextWrapping="Wrap" />+ <StackPanel Margin="0,0,0,20">+ <ui:InfoBar+ IsOpen="True"+ Margin="0,0,0,10"+ Message="A new version of optimizerDuck is available."+ Severity="Warning"+ Title="Update Available"+ Visibility="{Binding ViewModel.HasUpdate, Converter={StaticResource BoolToVisibilityConverter}}" />+ <Grid ColumnDefinitions="*,Auto">+ <ui:TextBlock+ FontTypography="Title"+ Text="{ext:Loc Dashboard.Header.Title}"+ TextWrapping="Wrap" />- <Menu Grid.Column="1">- <ui:MenuItem Header="{ext:Loc Dashboard.Header.Menu.Header.Options}">- <ui:MenuItem Header="{ext:Loc Dashboard.Header.Menu.Header.Run}" Icon="{ui:SymbolIcon Apps24}">- <ui:MenuItem- Command="{Binding ViewModel.RunCommand}"- CommandParameter="Settings"- Header="{ext:Loc Dashboard.Header.Menu.RunSettings}" />+ <Menu Grid.Column="1">+ <ui:MenuItem Header="{ext:Loc Dashboard.Header.Menu.Header.Options}">+ <ui:MenuItem Header="{ext:Loc Dashboard.Header.Menu.Header.Run}" Icon="{ui:SymbolIcon Apps24}">+ <ui:MenuItem+ Command="{Binding ViewModel.RunCommand}"+ CommandParameter="Settings"+ Header="{ext:Loc Dashboard.Header.Menu.RunSettings}" />+ <ui:MenuItem+ Command="{Binding ViewModel.RunCommand}"+ CommandParameter="TaskManager"+ Header="{ext:Loc Dashboard.Header.Menu.RunTaskManager}" />+ <ui:MenuItem+ Command="{Binding ViewModel.RunCommand}"+ CommandParameter="ControlPanel"+ Header="{ext:Loc Dashboard.Header.Menu.RunControlPanel}" />+ </ui:MenuItem>+ <Separator /><ui:MenuItem- Command="{Binding ViewModel.RunCommand}"- CommandParameter="TaskManager"- Header="{ext:Loc Dashboard.Header.Menu.RunTaskManager}" />- <ui:MenuItem- Command="{Binding ViewModel.RunCommand}"- CommandParameter="ControlPanel"- Header="{ext:Loc Dashboard.Header.Menu.RunControlPanel}" />+ Command="{Binding ViewModel.RefreshCommand}"+ Header="{ext:Loc Dashboard.Header.Menu.Refresh}"+ Icon="{ui:SymbolIcon ArrowClockwise24}" /></ui:MenuItem>- <Separator />- <ui:MenuItem- Command="{Binding ViewModel.RefreshCommand}"- Header="{ext:Loc Dashboard.Header.Menu.Refresh}"- Icon="{ui:SymbolIcon ArrowClockwise24}" />- </ui:MenuItem>- </Menu>- </Grid>+ </Menu>+ </Grid>+ </StackPanel><!-- Action Cards --><UniformGrid