Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertBeekman committed Jul 4, 2024
2 parents 7052ee3 + 00948de commit bd90417
Show file tree
Hide file tree
Showing 46 changed files with 1,172 additions and 326 deletions.
2 changes: 2 additions & 0 deletions src/Artemis.Core/Services/DeviceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ public DeviceService(ILogger logger,
_renderService = renderService;
_getLayoutProviders = getLayoutProviders;

SuspendedDeviceProviders = new ReadOnlyCollection<DeviceProvider>(_suspendedDeviceProviders);
EnabledDevices = new ReadOnlyCollection<ArtemisDevice>(_enabledDevices);
Devices = new ReadOnlyCollection<ArtemisDevice>(_devices);

RenderScale.RenderScaleMultiplierChanged += RenderScaleOnRenderScaleMultiplierChanged;
}

public IReadOnlyCollection<DeviceProvider> SuspendedDeviceProviders { get; }
public IReadOnlyCollection<ArtemisDevice> EnabledDevices { get; }
public IReadOnlyCollection<ArtemisDevice> Devices { get; }

Expand Down
9 changes: 7 additions & 2 deletions src/Artemis.Core/Services/Interfaces/IDeviceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ namespace Artemis.Core.Services;
/// </summary>
public interface IDeviceService : IArtemisService
{
/// <summary>
/// Gets a read-only collection containing all enabled but suspended device providers
/// </summary>
IReadOnlyCollection<DeviceProvider> SuspendedDeviceProviders { get; }

/// <summary>
/// Gets a read-only collection containing all enabled devices
/// </summary>
Expand Down Expand Up @@ -42,7 +47,7 @@ public interface IDeviceService : IArtemisService
/// Applies auto-arranging logic to the surface
/// </summary>
void AutoArrangeDevices();

/// <summary>
/// Apples the best available to the provided <see cref="ArtemisDevice" />
/// </summary>
Expand Down Expand Up @@ -111,7 +116,7 @@ public interface IDeviceService : IArtemisService
/// Occurs when a device provider was removed.
/// </summary>
event EventHandler<DeviceProviderEventArgs> DeviceProviderRemoved;

/// <summary>
/// Occurs when the surface has had modifications to its LED collection
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ public interface IPluginManagementService : IArtemisService, IDisposable
/// </summary>
event EventHandler<PluginEventArgs> PluginDisabled;

/// <summary>
/// Occurs when a plugin is removed
/// </summary>
event EventHandler<PluginEventArgs> PluginRemoved;

/// <summary>
/// Occurs when a plugin feature is being enabled
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions src/Artemis.Core/Services/PluginManagementService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,8 @@ public void RemovePlugin(Plugin plugin, bool removeSettings)

if (removeSettings)
RemovePluginSettings(plugin);

OnPluginRemoved(new PluginEventArgs(plugin));
}

public void RemovePluginSettings(Plugin plugin)
Expand Down Expand Up @@ -850,6 +852,7 @@ private void SavePlugin(Plugin plugin)
public event EventHandler<PluginEventArgs>? PluginEnabling;
public event EventHandler<PluginEventArgs>? PluginEnabled;
public event EventHandler<PluginEventArgs>? PluginDisabled;
public event EventHandler<PluginEventArgs>? PluginRemoved;

public event EventHandler<PluginFeatureEventArgs>? PluginFeatureEnabling;
public event EventHandler<PluginFeatureEventArgs>? PluginFeatureEnabled;
Expand Down Expand Up @@ -890,6 +893,11 @@ protected virtual void OnPluginDisabled(PluginEventArgs e)
{
PluginDisabled?.Invoke(this, e);
}

protected virtual void OnPluginRemoved(PluginEventArgs e)
{
PluginRemoved?.Invoke(this, e);
}

protected virtual void OnPluginFeatureEnabling(PluginFeatureEventArgs e)
{
Expand Down
26 changes: 14 additions & 12 deletions src/Artemis.Core/Services/Storage/Interfaces/IProfileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface IProfileService : IArtemisService
/// Gets or sets a value indicating whether the currently focused profile should receive updates.
/// </summary>
bool UpdateFocusProfile { get; set; }

/// <summary>
/// Gets or sets whether profiles are rendered each frame by calling their Render method
/// </summary>
Expand All @@ -54,7 +54,7 @@ public interface IProfileService : IArtemisService
/// </summary>
/// <param name="profileConfiguration">The profile configuration of the profile to activate.</param>
void DeactivateProfile(ProfileConfiguration profileConfiguration);

/// <summary>
/// Saves the provided <see cref="ProfileCategory" /> and it's <see cref="ProfileConfiguration" />s but not the
/// <see cref="Profile" />s themselves.
Expand Down Expand Up @@ -117,15 +117,8 @@ public interface IProfileService : IArtemisService
/// <param name="nameAffix">Text to add after the name of the profile (separated by a dash).</param>
/// <param name="target">The profile before which to import the profile into the category.</param>
/// <returns>The resulting profile configuration.</returns>
Task<ProfileConfiguration> ImportProfile(Stream archiveStream, ProfileCategory category, bool makeUnique, bool markAsFreshImport, string? nameAffix = "imported", ProfileConfiguration? target = null);

/// <summary>
/// Imports the provided ZIP archive stream into the provided profile configuration
/// </summary>
/// <param name="archiveStream">The zip archive containing the profile to import.</param>
/// <param name="profileConfiguration">The profile configuration to overwrite.</param>
/// <returns>The resulting profile configuration.</returns>
Task<ProfileConfiguration> OverwriteProfile(MemoryStream archiveStream, ProfileConfiguration profileConfiguration);
Task<ProfileConfiguration> ImportProfile(Stream archiveStream, ProfileCategory category, bool makeUnique, bool markAsFreshImport, string? nameAffix = "imported",
ProfileConfiguration? target = null);

/// <summary>
/// Adapts a given profile to the currently active devices.
Expand Down Expand Up @@ -163,5 +156,14 @@ public interface IProfileService : IArtemisService
/// Occurs whenever a profile category is removed.
/// </summary>
public event EventHandler<ProfileCategoryEventArgs>? ProfileCategoryRemoved;


/// <summary>
/// Occurs whenever a profile is added.
/// </summary>
public event EventHandler<ProfileConfigurationEventArgs>? ProfileRemoved;

/// <summary>
/// Occurs whenever a profile is removed.
/// </summary>
public event EventHandler<ProfileConfigurationEventArgs>? ProfileAdded;
}
32 changes: 17 additions & 15 deletions src/Artemis.Core/Services/Storage/ProfileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ internal class ProfileService : IProfileService
private readonly IPluginManagementService _pluginManagementService;
private readonly IDeviceService _deviceService;
private readonly List<ArtemisKeyboardKeyEventArgs> _pendingKeyboardEvents = new();
private readonly List<IProfileMigration> _profileMigrators;
private readonly List<Exception> _renderExceptions = new();
private readonly List<Exception> _updateExceptions = new();

Expand All @@ -38,15 +37,13 @@ public ProfileService(ILogger logger,
IProfileRepository profileRepository,
IPluginManagementService pluginManagementService,
IInputService inputService,
IDeviceService deviceService,
List<IProfileMigration> profileMigrators)
IDeviceService deviceService)
{
_logger = logger;
_profileCategoryRepository = profileCategoryRepository;
_profileRepository = profileRepository;
_pluginManagementService = pluginManagementService;
_deviceService = deviceService;
_profileMigrators = profileMigrators;

ProfileCategories = new ReadOnlyCollection<ProfileCategory>(_profileCategoryRepository.GetAll().Select(c => new ProfileCategory(c)).OrderBy(c => c.Order).ToList());

Expand Down Expand Up @@ -264,6 +261,8 @@ public ProfileConfiguration CreateProfileConfiguration(ProfileCategory category,

category.AddProfileConfiguration(configuration, category.ProfileConfigurations.FirstOrDefault());
SaveProfileCategory(category);

OnProfileAdded(new ProfileConfigurationEventArgs(configuration));
return configuration;
}

Expand All @@ -279,6 +278,8 @@ public void RemoveProfileConfiguration(ProfileConfiguration profileConfiguration

_profileRepository.Remove(profileConfiguration.Entity);
_profileCategoryRepository.Save(category.Entity);

OnProfileRemoved(new ProfileConfigurationEventArgs(profileConfiguration));
}

/// <inheritdoc />
Expand Down Expand Up @@ -433,17 +434,6 @@ public async Task<ProfileConfiguration> ImportProfile(Stream archiveStream, Prof
return profileConfiguration;
}

/// <inheritdoc />
public async Task<ProfileConfiguration> OverwriteProfile(MemoryStream archiveStream, ProfileConfiguration profileConfiguration)
{
ProfileConfiguration imported = await ImportProfile(archiveStream, profileConfiguration.Category, true, true, null, profileConfiguration);

RemoveProfileConfiguration(profileConfiguration);
SaveProfileCategory(imported.Category);

return imported;
}

/// <inheritdoc />
public void AdaptProfile(Profile profile)
{
Expand Down Expand Up @@ -588,6 +578,8 @@ private void LogProfileRenderExceptions()
public event EventHandler<ProfileConfigurationEventArgs>? ProfileDeactivated;
public event EventHandler<ProfileCategoryEventArgs>? ProfileCategoryAdded;
public event EventHandler<ProfileCategoryEventArgs>? ProfileCategoryRemoved;
public event EventHandler<ProfileConfigurationEventArgs>? ProfileRemoved;
public event EventHandler<ProfileConfigurationEventArgs>? ProfileAdded;

protected virtual void OnProfileActivated(ProfileConfigurationEventArgs e)
{
Expand All @@ -610,4 +602,14 @@ protected virtual void OnProfileCategoryRemoved(ProfileCategoryEventArgs e)
}

#endregion

protected virtual void OnProfileRemoved(ProfileConfigurationEventArgs e)
{
ProfileRemoved?.Invoke(this, e);
}

protected virtual void OnProfileAdded(ProfileConfigurationEventArgs e)
{
ProfileAdded?.Invoke(this, e);
}
}
2 changes: 1 addition & 1 deletion src/Artemis.UI.Shared/Routing/Router/IRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public interface IRouter
/// Asynchronously navigates upwards to the parent route.
/// </summary>
/// <returns></returns>
Task<bool> GoUp();
Task<bool> GoUp(RouterNavigationOptions? options = null);

/// <summary>
/// Clears the navigation history.
Expand Down
8 changes: 7 additions & 1 deletion src/Artemis.UI.Shared/Routing/Router/NavigationArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ namespace Artemis.UI.Shared.Routing;
/// </summary>
public class NavigationArguments
{
internal NavigationArguments(IRouter router, string path, object[] routeParameters)
internal NavigationArguments(IRouter router, RouterNavigationOptions options, string path, object[] routeParameters)
{
Router = router;
Options = options;
Path = path;
RouteParameters = routeParameters;
SegmentParameters = Array.Empty<object>();
Expand All @@ -21,6 +22,11 @@ internal NavigationArguments(IRouter router, string path, object[] routeParamete
/// </summary>
public IRouter Router { get; }

/// <summary>
/// Gets the options that are being used for this navigation.
/// </summary>
public RouterNavigationOptions Options { get; }

/// <summary>
/// Gets the path of the route that is being navigated to.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions src/Artemis.UI.Shared/Routing/Router/Router.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private async Task InternalNavigate(string path, RouterNavigationOptions options
return;
}

NavigationArguments args = new(this, resolution.Path, resolution.GetAllParameters());
NavigationArguments args = new(this, options, resolution.Path, resolution.GetAllParameters());

if (!await RequestClose(_root, args))
return;
Expand Down Expand Up @@ -169,7 +169,7 @@ public async Task<bool> GoForward()
}

/// <inheritdoc />
public async Task<bool> GoUp()
public async Task<bool> GoUp(RouterNavigationOptions? options = null)
{
string? currentPath = _currentRouteSubject.Value;

Expand All @@ -180,7 +180,7 @@ public async Task<bool> GoUp()
RouteResolution resolution = Resolve(parentPath);
if (resolution.Success)
{
await Navigate(parentPath, new RouterNavigationOptions {AddToHistory = false});
await Navigate(parentPath, options);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public class RouterNavigationOptions
/// </summary>
public bool EnableLogging { get; set; } = true;

/// <summary>
/// Gets or sets any additional arguments to pass to the screen.
/// </summary>
public object? AdditionalArguments { get; set; }

/// <summary>
/// Determines whether the given two paths are considered equal using these navigation options.
/// </summary>
Expand Down
28 changes: 17 additions & 11 deletions src/Artemis.UI/Screens/Plugins/PluginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Artemis.UI.Shared.Services.Builders;
using Artemis.WebClient.Workshop.Models;
using Artemis.WebClient.Workshop.Services;
using Avalonia.Controls;
using Avalonia.Threading;
using Material.Icons;
Expand All @@ -26,7 +24,6 @@ public partial class PluginViewModel : ActivatableViewModelBase
private readonly ICoreService _coreService;
private readonly INotificationService _notificationService;
private readonly IPluginManagementService _pluginManagementService;
private readonly IWorkshopService _workshopService;
private readonly IWindowService _windowService;
private Window? _settingsWindow;
[Notify] private bool _canInstallPrerequisites;
Expand All @@ -39,15 +36,13 @@ public PluginViewModel(Plugin plugin,
ICoreService coreService,
IWindowService windowService,
INotificationService notificationService,
IPluginManagementService pluginManagementService,
IWorkshopService workshopService)
IPluginManagementService pluginManagementService)
{
_plugin = plugin;
_coreService = coreService;
_windowService = windowService;
_notificationService = notificationService;
_pluginManagementService = pluginManagementService;
_workshopService = workshopService;

Platforms = new ObservableCollection<PluginPlatformViewModel>();
if (Plugin.Info.Platforms != null)
Expand Down Expand Up @@ -249,7 +244,7 @@ private async Task ExecuteRemove()
return;

// If the plugin or any of its features has uninstall actions, offer to run these
await ExecuteRemovePrerequisites(true);
await ExecuteRemovePrerequisites(true);

try
{
Expand All @@ -260,10 +255,6 @@ private async Task ExecuteRemove()
_windowService.ShowExceptionDialog("Failed to remove plugin", e);
throw;
}

InstalledEntry? entry = _workshopService.GetInstalledEntries().FirstOrDefault(e => e.TryGetMetadata("PluginId", out Guid pluginId) && pluginId == Plugin.Guid);
if (entry != null)
_workshopService.RemoveInstalledEntry(entry);

_notificationService.CreateNotification().WithTitle("Removed plugin.").Show();
}
Expand Down Expand Up @@ -303,4 +294,19 @@ private void OnPluginToggled(object? sender, EventArgs e)
_settingsWindow?.Close();
});
}

public async Task AutoEnable()
{
if (IsEnabled)
return;

await UpdateEnabled(true);

// If enabling failed, don't offer to show the settings
if (!IsEnabled || Plugin.ConfigurationDialog == null)
return;

if (await _windowService.ShowConfirmContentDialog("Open plugin settings", "This plugin has settings, would you like to view them?", "Yes", "No"))
ExecuteOpenSettings();
}
}
Loading

0 comments on commit bd90417

Please sign in to comment.