Skip to content

Commit

Permalink
Workshop - Added indicator for official workshop entries
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertBeekman committed Jul 22, 2024
1 parent b00f5ca commit a45d98c
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/Artemis.Storage/Entities/Workshop/EntryEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class EntryEntity
public int EntryType { get; set; }

public string Author { get; set; } = string.Empty;
public bool IsOfficial { get; set; }
public string Name { get; set; } = string.Empty;
public string Summary { get; set; } = string.Empty;
public long Downloads { get; set; }
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Artemis.Storage.Migrations
{
/// <inheritdoc />
public partial class ExpandInstalledEntry : Migration
public partial class AutoUpdating : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
Expand Down Expand Up @@ -38,6 +38,13 @@ protected override void Up(MigrationBuilder migrationBuilder)
nullable: false,
defaultValue: 0L);

migrationBuilder.AddColumn<bool>(
name: "IsOfficial",
table: "Entries",
type: "INTEGER",
nullable: false,
defaultValue: false);

migrationBuilder.AddColumn<long>(
name: "LatestReleaseId",
table: "Entries",
Expand All @@ -50,7 +57,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
type: "TEXT",
nullable: false,
defaultValue: "");

// Enable auto-update on all entries that are not profiles
migrationBuilder.Sql("UPDATE Entries SET AutoUpdate = 1 WHERE EntryType != 2");

Expand Down Expand Up @@ -87,6 +94,10 @@ protected override void Down(MigrationBuilder migrationBuilder)
name: "Downloads",
table: "Entries");

migrationBuilder.DropColumn(
name: "IsOfficial",
table: "Entries");

migrationBuilder.DropColumn(
name: "LatestReleaseId",
table: "Entries");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<DateTimeOffset>("InstalledAt")
.HasColumnType("TEXT");

b.Property<bool>("IsOfficial")
.HasColumnType("INTEGER");

b.Property<long?>("LatestReleaseId")
.HasColumnType("INTEGER");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<TextBlock Grid.Row="0" Margin="0 0 0 5" TextTrimming="CharacterEllipsis">
<Run Classes="h5" Text="{CompiledBinding Entry.Name, FallbackValue=Title}" />
<Run Classes="subtitle">by you</Run>
<Run Classes="subtitle" Text="{CompiledBinding Emoji}" />
<Run Text="{CompiledBinding Emoji}" />
</TextBlock>
<TextBlock Grid.Row="1"
Classes="subtitle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Artemis.UI.Screens.Workshop.Library.Tabs;

public class SubmissionsTabItemViewModel : ViewModelBase
{
private static readonly string[] Emojis = ["❤️", "🧡", "💛", "💚", "💙", "💜", "🤍", "💔", "❣️", "💕", "💞", "💓", "💗", "💖", "💘", "💝", "😍", "🥰"];
private static readonly string[] Emojis = ["❤️", "🧡", "💛", "💚", "💙", "💜", "💔", "❣️", "💕", "💞", "💓", "💗", "💖", "💘", "💝", "😍", "🥰"];
private readonly IRouter _router;

public SubmissionsTabItemViewModel(IGetSubmittedEntries_SubmittedEntries entry, IRouter router)
Expand Down
29 changes: 19 additions & 10 deletions src/Artemis.UI/Services/Updating/WorkshopUpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared.Services;
using Artemis.UI.Shared.Utilities;
using Artemis.WebClient.Workshop;
using Artemis.WebClient.Workshop.Handlers.InstallationHandlers;
Expand All @@ -19,13 +18,11 @@ public class WorkshopUpdateService : IWorkshopUpdateService
{
private readonly ILogger _logger;
private readonly IWorkshopClient _client;
private readonly INotificationService _notificationService;
private readonly IWorkshopService _workshopService;
private readonly Lazy<IUpdateNotificationProvider> _updateNotificationProvider;
private readonly PluginSetting<bool> _showNotifications;

public WorkshopUpdateService(ILogger logger, IWorkshopClient client, IWorkshopService workshopService, ISettingsService settingsService,
Lazy<IUpdateNotificationProvider> updateNotificationProvider)
public WorkshopUpdateService(ILogger logger, IWorkshopClient client, IWorkshopService workshopService, ISettingsService settingsService, Lazy<IUpdateNotificationProvider> updateNotificationProvider)
{
_logger = logger;
_client = client;
Expand Down Expand Up @@ -69,15 +66,27 @@ public async Task<bool> AutoUpdateEntry(InstalledEntry entry)

_logger.Information("Auto-updating entry {Entry} to version {Version}", entry, latestRelease.Version);

EntryInstallResult updateResult = await _workshopService.InstallEntry(entry, latestRelease, new Progress<StreamProgress>(), CancellationToken.None);
try
{
EntryInstallResult updateResult = await _workshopService.InstallEntry(entry, latestRelease, new Progress<StreamProgress>(), CancellationToken.None);

// This happens during installation too but not on our reference of the entry
if (updateResult.IsSuccess)
entry.ApplyRelease(latestRelease);

// This happens during installation too but not on our reference of the entry
if (updateResult.IsSuccess)
entry.ApplyRelease(latestRelease);
if (updateResult.IsSuccess)
_logger.Information("Auto-update successful for entry {Entry}", entry);
else
_logger.Warning("Auto-update failed for entry {Entry}: {Message}", entry, updateResult.Message);

_logger.Information("Auto-update result: {Result}", updateResult);
return updateResult.IsSuccess;
}
catch (Exception e)
{
_logger.Warning(e, "Auto-update failed for entry {Entry}", entry);
}

return updateResult.IsSuccess;
return false;
}

/// <inheritdoc />
Expand Down
2 changes: 2 additions & 0 deletions src/Artemis.WebClient.Workshop/Models/InstalledEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ internal void Load()
{
Id = Entity.EntryId;
Author = Entity.Author;
IsOfficial = Entity.IsOfficial;
Name = Entity.Name;
Summary = Entity.Summary;
EntryType = (EntryType) Entity.EntryType;
Expand All @@ -87,6 +88,7 @@ internal void Save()
Entity.EntryType = (int) EntryType;

Entity.Author = Author;
Entity.IsOfficial = IsOfficial;
Entity.Name = Name;
Entity.Summary = Summary;
Entity.Downloads = Downloads;
Expand Down

0 comments on commit a45d98c

Please sign in to comment.