mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-01-01 10:13:30 +00:00
Updating - Fix crash when client has internet
Updating - Check for updates periodically and when window opens (if auto-update enabled) Webserver - Don't write wildcard to webserver.txt
This commit is contained in:
parent
98b9770250
commit
f829743b6c
@ -46,7 +46,14 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly BuildInfo BuildInfo = File.Exists(Path.Combine(ApplicationFolder, "buildinfo.json"))
|
public static readonly BuildInfo BuildInfo = File.Exists(Path.Combine(ApplicationFolder, "buildinfo.json"))
|
||||||
? JsonConvert.DeserializeObject<BuildInfo>(File.ReadAllText(Path.Combine(ApplicationFolder, "buildinfo.json")))
|
? JsonConvert.DeserializeObject<BuildInfo>(File.ReadAllText(Path.Combine(ApplicationFolder, "buildinfo.json")))
|
||||||
: new BuildInfo();
|
: new BuildInfo
|
||||||
|
{
|
||||||
|
IsLocalBuild = true,
|
||||||
|
BuildId = 1337,
|
||||||
|
BuildNumber = 1337,
|
||||||
|
SourceBranch = "local",
|
||||||
|
SourceVersion = "local"
|
||||||
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The plugin used by core components of Artemis
|
/// The plugin used by core components of Artemis
|
||||||
@ -108,6 +115,6 @@ namespace Artemis.Core
|
|||||||
typeof(float),
|
typeof(float),
|
||||||
typeof(double),
|
typeof(double),
|
||||||
typeof(decimal)
|
typeof(decimal)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,5 +38,10 @@ namespace Artemis.Core.Services.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public string SourceVersion { get; internal set; } = null!;
|
public string SourceVersion { get; internal set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a boolean indicating whether the current build is a local build
|
||||||
|
/// </summary>
|
||||||
|
public bool IsLocalBuild { get; internal set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ namespace Artemis.Core.Services
|
|||||||
server.StateChanged += (s, e) => _logger.Verbose("WebServer new state - {state}", e.NewState);
|
server.StateChanged += (s, e) => _logger.Verbose("WebServer new state - {state}", e.NewState);
|
||||||
|
|
||||||
// Store the URL in a webserver.txt file so that remote applications can find it
|
// Store the URL in a webserver.txt file so that remote applications can find it
|
||||||
File.WriteAllText(Path.Combine(Constants.DataFolder, "webserver.txt"), url);
|
File.WriteAllText(Path.Combine(Constants.DataFolder, "webserver.txt"), $"http://localhost:{_webServerPortSetting.Value}/");
|
||||||
|
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -334,9 +334,6 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="buildinfo.json">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="Properties\Settings.settings">
|
<None Update="Properties\Settings.settings">
|
||||||
<Generator>SettingsSingleFileGenerator</Generator>
|
<Generator>SettingsSingleFileGenerator</Generator>
|
||||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||||
|
|||||||
@ -32,13 +32,20 @@
|
|||||||
<ProgressBar IsIndeterminate="True" />
|
<ProgressBar IsIndeterminate="True" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<ItemsControl ItemsSource="{Binding Changes}" Visibility="{Binding RetrievingChanges, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}">
|
<Grid Visibility="{Binding RetrievingChanges, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}">
|
||||||
<ItemsControl.ItemTemplate>
|
<ItemsControl ItemsSource="{Binding Changes}" Visibility="{Binding HasChanges, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
|
||||||
<DataTemplate>
|
<ItemsControl.ItemTemplate>
|
||||||
<TextBlock Text="{Binding}" Style="{StaticResource MaterialDesignSubtitle1TextBlock}" Foreground="{DynamicResource MaterialDesignBodyLight}"></TextBlock>
|
<DataTemplate>
|
||||||
</DataTemplate>
|
<TextBlock Text="{Binding}" Style="{StaticResource MaterialDesignSubtitle1TextBlock}" Foreground="{DynamicResource MaterialDesignBodyLight}"></TextBlock>
|
||||||
</ItemsControl.ItemTemplate>
|
</DataTemplate>
|
||||||
</ItemsControl>
|
</ItemsControl.ItemTemplate>
|
||||||
|
</ItemsControl>
|
||||||
|
<TextBlock Visibility="{Binding HasChanges, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}"
|
||||||
|
Style="{StaticResource MaterialDesignSubtitle1TextBlock}"
|
||||||
|
Foreground="{DynamicResource MaterialDesignBodyLight}">
|
||||||
|
Couldn't retrieve changes, sorry :(
|
||||||
|
</TextBlock>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0 8 0 0">
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0 8 0 0">
|
||||||
<Button Style="{StaticResource MaterialDesignFlatButton}"
|
<Button Style="{StaticResource MaterialDesignFlatButton}"
|
||||||
|
|||||||
@ -1,28 +1,42 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
using Artemis.UI.Services;
|
using Artemis.UI.Services;
|
||||||
using Artemis.UI.Services.Models.UpdateService;
|
using Artemis.UI.Services.Models.UpdateService;
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using Stylet;
|
using Stylet;
|
||||||
|
|
||||||
namespace Artemis.UI.Screens.Settings.Dialogs
|
namespace Artemis.UI.Screens.Settings.Dialogs
|
||||||
{
|
{
|
||||||
public class UpdateDialogViewModel : DialogViewModelBase
|
public class UpdateDialogViewModel : DialogViewModelBase
|
||||||
{
|
{
|
||||||
private readonly DevOpsBuild _buildInfo;
|
|
||||||
private readonly IDialogService _dialogService;
|
private readonly IDialogService _dialogService;
|
||||||
|
|
||||||
|
// Based on https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/github?view=azure-devops&tabs=yaml#skipping-ci-for-individual-commits
|
||||||
|
private readonly string[] _excludedCommitMessages =
|
||||||
|
{
|
||||||
|
"[skip ci]",
|
||||||
|
"[ci skip]",
|
||||||
|
"skip-checks: true",
|
||||||
|
"skip-checks:true",
|
||||||
|
"[skip azurepipelines]",
|
||||||
|
"[azurepipelines skip]",
|
||||||
|
"[skip azpipelines]",
|
||||||
|
"[azpipelines skip]",
|
||||||
|
"[skip azp]",
|
||||||
|
"[azp skip]",
|
||||||
|
"***NO_CI***"
|
||||||
|
};
|
||||||
|
|
||||||
private readonly IMessageService _messageService;
|
private readonly IMessageService _messageService;
|
||||||
private readonly IUpdateService _updateService;
|
private readonly IUpdateService _updateService;
|
||||||
private bool _canUpdate = true;
|
private bool _canUpdate = true;
|
||||||
|
private bool _hasChanges;
|
||||||
private bool _retrievingChanges;
|
private bool _retrievingChanges;
|
||||||
|
|
||||||
public UpdateDialogViewModel(DevOpsBuild buildInfo, IUpdateService updateService, IDialogService dialogService, IMessageService messageService)
|
public UpdateDialogViewModel(DevOpsBuild buildInfo, IUpdateService updateService, IDialogService dialogService, IMessageService messageService)
|
||||||
{
|
{
|
||||||
_buildInfo = buildInfo;
|
|
||||||
_updateService = updateService;
|
_updateService = updateService;
|
||||||
_dialogService = dialogService;
|
_dialogService = dialogService;
|
||||||
_messageService = messageService;
|
_messageService = messageService;
|
||||||
@ -44,12 +58,37 @@ namespace Artemis.UI.Screens.Settings.Dialogs
|
|||||||
set => SetAndNotify(ref _retrievingChanges, value);
|
set => SetAndNotify(ref _retrievingChanges, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool HasChanges
|
||||||
|
{
|
||||||
|
get => _hasChanges;
|
||||||
|
set => SetAndNotify(ref _hasChanges, value);
|
||||||
|
}
|
||||||
|
|
||||||
public bool CanUpdate
|
public bool CanUpdate
|
||||||
{
|
{
|
||||||
get => _canUpdate;
|
get => _canUpdate;
|
||||||
set => SetAndNotify(ref _canUpdate, value);
|
set => SetAndNotify(ref _canUpdate, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task Update()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CanUpdate = false;
|
||||||
|
await _updateService.ApplyUpdate();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_dialogService.ShowExceptionDialog("An exception occurred while applying the update", e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
CanUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Session.Close(true);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task GetBuildChanges()
|
private async Task GetBuildChanges()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -70,9 +109,10 @@ namespace Artemis.UI.Screens.Settings.Dialogs
|
|||||||
Changes.AddRange(difference.Commits.Where(c => c.Parents.Count == 1)
|
Changes.AddRange(difference.Commits.Where(c => c.Parents.Count == 1)
|
||||||
.SelectMany(c => c.Commit.Message.Split("\n"))
|
.SelectMany(c => c.Commit.Message.Split("\n"))
|
||||||
.Select(m => m.Trim())
|
.Select(m => m.Trim())
|
||||||
.Where(m => !string.IsNullOrWhiteSpace(m))
|
.Where(m => !string.IsNullOrWhiteSpace(m) && !_excludedCommitMessages.Contains(m))
|
||||||
.OrderBy(m => m)
|
.OrderBy(m => m)
|
||||||
);
|
);
|
||||||
|
HasChanges = Changes.Any();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -84,24 +124,5 @@ namespace Artemis.UI.Screens.Settings.Dialogs
|
|||||||
RetrievingChanges = false;
|
RetrievingChanges = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Update()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
CanUpdate = false;
|
|
||||||
await _updateService.ApplyUpdate();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
_dialogService.ShowExceptionDialog("An exception occurred while applying the update", e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
CanUpdate = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Session.Close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -274,10 +274,20 @@ namespace Artemis.UI.Screens.Settings.Tabs.General
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
CanOfferUpdatesIfFound = false;
|
CanOfferUpdatesIfFound = false;
|
||||||
bool updateFound = await _updateService.OfferUpdateIfFound();
|
try
|
||||||
if (!updateFound)
|
{
|
||||||
_messageService.ShowMessage("You are already running the latest Artemis build. (☞゚ヮ゚)☞");
|
bool updateFound = await _updateService.OfferUpdateIfFound();
|
||||||
CanOfferUpdatesIfFound = true;
|
if (!updateFound)
|
||||||
|
_messageService.ShowMessage("You are already running the latest Artemis build. (☞゚ヮ゚)☞");
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
_messageService.ShowMessage($"Failed to check for updates: {exception.Message}");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
CanOfferUpdatesIfFound = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnInitialActivate()
|
protected override void OnInitialActivate()
|
||||||
|
|||||||
@ -7,6 +7,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Timers;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
using Artemis.Core.Services;
|
using Artemis.Core.Services;
|
||||||
using Artemis.UI.Exceptions;
|
using Artemis.UI.Exceptions;
|
||||||
@ -23,7 +24,9 @@ namespace Artemis.UI.Services
|
|||||||
{
|
{
|
||||||
public class UpdateService : IUpdateService
|
public class UpdateService : IUpdateService
|
||||||
{
|
{
|
||||||
|
private const double UpdateCheckInterval = 3600000; // once per hour
|
||||||
private const string ApiUrl = "https://dev.azure.com/artemis-rgb/Artemis/_apis/";
|
private const string ApiUrl = "https://dev.azure.com/artemis-rgb/Artemis/_apis/";
|
||||||
|
|
||||||
private readonly PluginSetting<bool> _autoInstallUpdates;
|
private readonly PluginSetting<bool> _autoInstallUpdates;
|
||||||
private readonly PluginSetting<bool> _checkForUpdates;
|
private readonly PluginSetting<bool> _checkForUpdates;
|
||||||
private readonly IDialogService _dialogService;
|
private readonly IDialogService _dialogService;
|
||||||
@ -41,13 +44,20 @@ namespace Artemis.UI.Services
|
|||||||
|
|
||||||
_checkForUpdates = settingsService.GetSetting("UI.CheckForUpdates", true);
|
_checkForUpdates = settingsService.GetSetting("UI.CheckForUpdates", true);
|
||||||
_autoInstallUpdates = settingsService.GetSetting("UI.AutoInstallUpdates", false);
|
_autoInstallUpdates = settingsService.GetSetting("UI.AutoInstallUpdates", false);
|
||||||
|
|
||||||
_checkForUpdates.SettingChanged += CheckForUpdatesOnSettingChanged;
|
_checkForUpdates.SettingChanged += CheckForUpdatesOnSettingChanged;
|
||||||
|
|
||||||
|
Timer timer = new(UpdateCheckInterval);
|
||||||
|
timer.Elapsed += async (_, _) => await AutoUpdate();
|
||||||
|
timer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool SuspendAutoUpdate { get; set; }
|
||||||
|
|
||||||
private async Task OfferUpdate(DevOpsBuild buildInfo)
|
private async Task OfferUpdate(DevOpsBuild buildInfo)
|
||||||
{
|
{
|
||||||
await _dialogService.ShowDialog<UpdateDialogViewModel>(new Dictionary<string, object> {{"buildInfo", buildInfo}});
|
object result = await _dialogService.ShowDialog<UpdateDialogViewModel>(new Dictionary<string, object> {{"buildInfo", buildInfo}});
|
||||||
|
if (result is bool resultBool && resultBool == false)
|
||||||
|
SuspendAutoUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UpdateInstaller()
|
private async Task UpdateInstaller()
|
||||||
@ -73,10 +83,20 @@ namespace Artemis.UI.Services
|
|||||||
|
|
||||||
public async Task<bool> AutoUpdate()
|
public async Task<bool> AutoUpdate()
|
||||||
{
|
{
|
||||||
if (!_checkForUpdates.Value)
|
if (Constants.BuildInfo.IsLocalBuild)
|
||||||
|
return false;
|
||||||
|
if (!_checkForUpdates.Value || SuspendAutoUpdate)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return await OfferUpdateIfFound();
|
try
|
||||||
|
{
|
||||||
|
return await OfferUpdateIfFound();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.Warning(e, "Auto update failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> OfferUpdateIfFound()
|
public async Task<bool> OfferUpdateIfFound()
|
||||||
@ -186,13 +206,13 @@ namespace Artemis.UI.Services
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(e, "GetBuildInfo: Failed to retrieve build info JSON");
|
_logger.Warning(e, "GetBuildInfo: Failed to retrieve build info JSON");
|
||||||
return null;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (FlurlHttpException e)
|
catch (FlurlHttpException e)
|
||||||
{
|
{
|
||||||
_logger.Warning("GetBuildInfo: Getting build info, request returned {statusCode}", e.StatusCode);
|
_logger.Warning("GetBuildInfo: Getting build info, request returned {statusCode}", e.StatusCode);
|
||||||
return null;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,16 +228,16 @@ namespace Artemis.UI.Services
|
|||||||
|
|
||||||
#region Event handlers
|
#region Event handlers
|
||||||
|
|
||||||
private void CheckForUpdatesOnSettingChanged(object sender, EventArgs e)
|
private async void CheckForUpdatesOnSettingChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// Run an auto-update as soon as the setting gets changed to enabled
|
// Run an auto-update as soon as the setting gets changed to enabled
|
||||||
if (_checkForUpdates.Value)
|
if (_checkForUpdates.Value)
|
||||||
AutoUpdate();
|
await AutoUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WindowServiceOnMainWindowOpened(object sender, EventArgs e)
|
private async void WindowServiceOnMainWindowOpened(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
_logger.Information("Main window opened!");
|
await AutoUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -225,6 +245,8 @@ namespace Artemis.UI.Services
|
|||||||
|
|
||||||
public interface IUpdateService : IArtemisUIService
|
public interface IUpdateService : IArtemisUIService
|
||||||
{
|
{
|
||||||
|
bool SuspendAutoUpdate { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If auto-update is enabled this will offer updates if found
|
/// If auto-update is enabled this will offer updates if found
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"BuildId": 442,
|
|
||||||
"BuildNumber": 20210130.3,
|
|
||||||
"SourceBranch": "refs/heads/master",
|
|
||||||
"SourceVersion": "b29ab064ae46d93141f31afaa8ee3ea9063c6263"
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user