From ede29aa9f96b7a606a15a79b9cbf08b814e22eba Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 3 Mar 2023 13:35:42 +0100 Subject: [PATCH] Added channel startup argument --- .../Properties/launchSettings.json | 2 +- .../Settings/Tabs/ReleasesTabView.axaml | 78 ++++++++++++------- .../Settings/Tabs/ReleasesTabViewModel.cs | 9 ++- .../Services/Updating/IUpdateService.cs | 1 + .../Services/Updating/UpdateService.cs | 30 +++---- 5 files changed, 75 insertions(+), 45 deletions(-) diff --git a/src/Artemis.UI.Windows/Properties/launchSettings.json b/src/Artemis.UI.Windows/Properties/launchSettings.json index a1588c6f9..31322f128 100644 --- a/src/Artemis.UI.Windows/Properties/launchSettings.json +++ b/src/Artemis.UI.Windows/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Artemis.UI.Windows": { "commandName": "Project", - "commandLineArgs": "--force-elevation --disable-forced-shutdown --pcmr" + "commandLineArgs": "--force-elevation --disable-forced-shutdown --pcmr --channel=feature/lawn-mowing" } } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Settings/Tabs/ReleasesTabView.axaml b/src/Artemis.UI/Screens/Settings/Tabs/ReleasesTabView.axaml index d70248659..44d257cd2 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/ReleasesTabView.axaml +++ b/src/Artemis.UI/Screens/Settings/Tabs/ReleasesTabView.axaml @@ -5,37 +5,57 @@ xmlns:settings="clr-namespace:Artemis.UI.Screens.Settings" xmlns:updating="clr-namespace:Artemis.UI.Screens.Settings.Updating" xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia" + xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia" mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="1400" x:Class="Artemis.UI.Screens.Settings.ReleasesTabView" x:DataType="settings:ReleasesTabViewModel"> - - - - - - - - - - - - - - - - - - - - + + + Loading releases... + + + + + + + Learn more about channels on the wiki + + - - + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Settings/Tabs/ReleasesTabViewModel.cs b/src/Artemis.UI/Screens/Settings/Tabs/ReleasesTabViewModel.cs index d7e3a6517..c504c4510 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/ReleasesTabViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Tabs/ReleasesTabViewModel.cs @@ -24,6 +24,7 @@ namespace Artemis.UI.Screens.Settings; public class ReleasesTabViewModel : ActivatableViewModelBase { private readonly ILogger _logger; + private readonly IUpdateService _updateService; private readonly IUpdatingClient _updatingClient; private readonly INotificationService _notificationService; private readonly SourceList _releases; @@ -34,6 +35,7 @@ public class ReleasesTabViewModel : ActivatableViewModelBase public ReleasesTabViewModel(ILogger logger, IUpdateService updateService, IUpdatingClient updatingClient, IReleaseVmFactory releaseVmFactory, INotificationService notificationService) { _logger = logger; + _updateService = updateService; _updatingClient = updatingClient; _notificationService = notificationService; @@ -47,15 +49,18 @@ public class ReleasesTabViewModel : ActivatableViewModelBase DisplayName = "Releases"; ReleaseViewModels = releaseViewModels; + Channel = _updateService.Channel; this.WhenActivated(async d => { - await updateService.CacheLatestRelease(); + await _updateService.CacheLatestRelease(); await GetMoreReleases(d.AsCancellationToken()); SelectedReleaseViewModel = ReleaseViewModels.FirstOrDefault(r => r.ReleaseId == PreselectId) ?? ReleaseViewModels.FirstOrDefault(); }); } + public ReadOnlyObservableCollection ReleaseViewModels { get; } + public string Channel { get; } public string? PreselectId { get; set; } public ReleaseViewModel? SelectedReleaseViewModel @@ -79,7 +84,7 @@ public class ReleasesTabViewModel : ActivatableViewModelBase { Loading = true; - IOperationResult result = await _updatingClient.GetReleases.ExecuteAsync("feature/gh-actions", Platform.Windows, 20, _lastPageInfo?.EndCursor, cancellationToken); + IOperationResult result = await _updatingClient.GetReleases.ExecuteAsync(_updateService.Channel, Platform.Windows, 20, _lastPageInfo?.EndCursor, cancellationToken); if (result.Data?.PublishedReleases?.Nodes == null) return; diff --git a/src/Artemis.UI/Services/Updating/IUpdateService.cs b/src/Artemis.UI/Services/Updating/IUpdateService.cs index 9c4ad84c8..519222c24 100644 --- a/src/Artemis.UI/Services/Updating/IUpdateService.cs +++ b/src/Artemis.UI/Services/Updating/IUpdateService.cs @@ -6,6 +6,7 @@ namespace Artemis.UI.Services.Updating; public interface IUpdateService : IArtemisUIService { + string Channel { get; } IGetNextRelease_NextPublishedRelease? CachedLatestRelease { get; } Task CacheLatestRelease(); diff --git a/src/Artemis.UI/Services/Updating/UpdateService.cs b/src/Artemis.UI/Services/Updating/UpdateService.cs index 2d95b9230..d858c5d79 100644 --- a/src/Artemis.UI/Services/Updating/UpdateService.cs +++ b/src/Artemis.UI/Services/Updating/UpdateService.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Threading; using System.Threading.Tasks; using Artemis.Core; @@ -18,15 +19,14 @@ public class UpdateService : IUpdateService private const double UPDATE_CHECK_INTERVAL = 3_600_000; // once per hour private readonly PluginSetting _autoCheck; private readonly PluginSetting _autoInstall; - private readonly PluginSetting _channel; - private readonly Func _getReleaseInstaller; + private readonly Platform _updatePlatform; private readonly ILogger _logger; private readonly IMainWindowService _mainWindowService; private readonly IQueuedActionRepository _queuedActionRepository; private readonly Lazy _updateNotificationProvider; - private readonly Platform _updatePlatform; private readonly IUpdatingClient _updatingClient; + private readonly Func _getReleaseInstaller; private bool _suspendAutoCheck; @@ -45,6 +45,12 @@ public class UpdateService : IUpdateService _updateNotificationProvider = updateNotificationProvider; _getReleaseInstaller = getReleaseInstaller; + string? channelArgument = Constants.StartupArguments.FirstOrDefault(a => a.StartsWith("--channel=")); + if (channelArgument != null) + Channel = channelArgument.Split("=")[1]; + if (string.IsNullOrWhiteSpace(Channel)) + Channel = "master"; + if (OperatingSystem.IsWindows()) _updatePlatform = Platform.Windows; else if (OperatingSystem.IsLinux()) @@ -53,8 +59,7 @@ public class UpdateService : IUpdateService _updatePlatform = Platform.Osx; else throw new PlatformNotSupportedException("Cannot auto update on the current platform"); - - _channel = settingsService.GetSetting("UI.Updating.Channel", "master"); + _autoCheck = settingsService.GetSetting("UI.Updating.AutoCheck", true); _autoInstall = settingsService.GetSetting("UI.Updating.AutoInstall", false); _autoCheck.SettingChanged += HandleAutoUpdateEvent; @@ -63,13 +68,14 @@ public class UpdateService : IUpdateService timer.Elapsed += HandleAutoUpdateEvent; timer.Start(); - _channel.Value = "feature/gh-actions"; - _channel.Save(); - - InstallQueuedUpdate(); + + _logger.Information("Update service initialized for {Channel} channel", Channel); } + public string Channel { get; } + public IGetNextRelease_NextPublishedRelease? CachedLatestRelease { get; private set; } + private void InstallQueuedUpdate() { if (!_queuedActionRepository.IsTypeQueued("InstallUpdate")) @@ -109,18 +115,16 @@ public class UpdateService : IUpdateService } } - public IGetNextRelease_NextPublishedRelease? CachedLatestRelease { get; private set; } - /// public async Task CacheLatestRelease() { - IOperationResult result = await _updatingClient.GetNextRelease.ExecuteAsync(Constants.CurrentVersion, _channel.Value, _updatePlatform); + IOperationResult result = await _updatingClient.GetNextRelease.ExecuteAsync(Constants.CurrentVersion, Channel, _updatePlatform); CachedLatestRelease = result.Data?.NextPublishedRelease; } public async Task CheckForUpdate() { - IOperationResult result = await _updatingClient.GetNextRelease.ExecuteAsync(Constants.CurrentVersion, _channel.Value, _updatePlatform); + IOperationResult result = await _updatingClient.GetNextRelease.ExecuteAsync(Constants.CurrentVersion, Channel, _updatePlatform); result.EnsureNoErrors(); // Update cache