Files

90 lines
2.8 KiB
C#
Raw Permalink Normal View History

2026-03-02 00:44:29 +01:00
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
using Wino.Core.Domain;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Updates;
namespace Wino.Services;
public class UpdateManager : IUpdateManager
{
private const string UpdateNotesResourcePath = "ms-appx:///Assets/UpdateNotes/vnext.json";
2026-03-05 10:12:03 +01:00
private const string FeaturesResourcePath = "ms-appx:///Assets/UpdateNotes/features.json";
2026-03-02 00:44:29 +01:00
private const string UpdateNotesSeenKeyFormat = "UpdateNotes_{0}_Shown";
private readonly IFileService _fileService;
private readonly IConfigurationService _configurationService;
private readonly INativeAppService _nativeAppService;
private string _versionSeenKey = string.Empty;
2026-03-05 10:12:03 +01:00
private UpdateNotes _latestUpdateNotes = new();
2026-03-02 00:44:29 +01:00
public UpdateManager(IFileService fileService,
IConfigurationService configurationService,
INativeAppService nativeAppService)
{
_fileService = fileService;
_configurationService = configurationService;
_nativeAppService = nativeAppService;
}
private string GetVersionSeenKey()
{
if (string.IsNullOrEmpty(_versionSeenKey))
{
var version = _nativeAppService.GetFullAppVersion();
var sanitized = version.Replace(".", "_");
_versionSeenKey = string.Format(UpdateNotesSeenKeyFormat, sanitized);
}
return _versionSeenKey;
}
public async Task<UpdateNotes> GetLatestUpdateNotesAsync()
{
try
{
var json = await _fileService.GetFileContentByApplicationUriAsync(UpdateNotesResourcePath);
if (string.IsNullOrEmpty(json))
2026-03-05 10:12:03 +01:00
{
_latestUpdateNotes = new UpdateNotes();
return _latestUpdateNotes;
}
2026-03-02 00:44:29 +01:00
2026-03-05 10:12:03 +01:00
_latestUpdateNotes = JsonSerializer.Deserialize(json, BasicTypesJsonContext.Default.UpdateNotes) ?? new UpdateNotes();
return _latestUpdateNotes;
2026-03-02 00:44:29 +01:00
}
catch (Exception)
{
2026-03-05 10:12:03 +01:00
_latestUpdateNotes = new UpdateNotes();
return _latestUpdateNotes;
2026-03-02 00:44:29 +01:00
}
}
public bool ShouldShowUpdateNotes()
=> !_configurationService.Get(GetVersionSeenKey(), false);
2026-03-05 10:12:03 +01:00
public async Task<List<UpdateNoteSection>> GetFeaturesAsync()
{
try
{
var json = await _fileService.GetFileContentByApplicationUriAsync(FeaturesResourcePath);
if (string.IsNullOrEmpty(json))
return [];
return JsonSerializer.Deserialize(json, BasicTypesJsonContext.Default.ListUpdateNoteSection) ?? [];
}
catch (Exception)
{
return [];
}
}
2026-03-02 00:44:29 +01:00
public void MarkUpdateNotesAsSeen()
=> _configurationService.Set(GetVersionSeenKey(), true);
}