mirror of
https://github.com/gwdevhub/Daybreak.git
synced 2026-07-15 15:19:57 +00:00
Update SimplePlugin example (#1264)
This commit is contained in:
@@ -1,51 +0,0 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Visual Studio Version 17
|
|
||||||
VisualStudioVersion = 17.7.34024.191
|
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimplePlugin", "SimplePlugin\SimplePlugin.csproj", "{F03854ED-C610-47DC-85FF-BB8CD59AAEDD}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Daybreak.Shared", "..\..\..\Daybreak.Shared\Daybreak.Shared.csproj", "{ED216205-2F90-0BB5-0D98-3A415A0CFC17}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Any CPU = Debug|Any CPU
|
|
||||||
Debug|x64 = Debug|x64
|
|
||||||
Debug|x86 = Debug|x86
|
|
||||||
Release|Any CPU = Release|Any CPU
|
|
||||||
Release|x64 = Release|x64
|
|
||||||
Release|x86 = Release|x86
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{F03854ED-C610-47DC-85FF-BB8CD59AAEDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{F03854ED-C610-47DC-85FF-BB8CD59AAEDD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{F03854ED-C610-47DC-85FF-BB8CD59AAEDD}.Debug|x64.ActiveCfg = Debug|Any CPU
|
|
||||||
{F03854ED-C610-47DC-85FF-BB8CD59AAEDD}.Debug|x64.Build.0 = Debug|Any CPU
|
|
||||||
{F03854ED-C610-47DC-85FF-BB8CD59AAEDD}.Debug|x86.ActiveCfg = Debug|Any CPU
|
|
||||||
{F03854ED-C610-47DC-85FF-BB8CD59AAEDD}.Debug|x86.Build.0 = Debug|Any CPU
|
|
||||||
{F03854ED-C610-47DC-85FF-BB8CD59AAEDD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{F03854ED-C610-47DC-85FF-BB8CD59AAEDD}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{F03854ED-C610-47DC-85FF-BB8CD59AAEDD}.Release|x64.ActiveCfg = Release|Any CPU
|
|
||||||
{F03854ED-C610-47DC-85FF-BB8CD59AAEDD}.Release|x64.Build.0 = Release|Any CPU
|
|
||||||
{F03854ED-C610-47DC-85FF-BB8CD59AAEDD}.Release|x86.ActiveCfg = Release|Any CPU
|
|
||||||
{F03854ED-C610-47DC-85FF-BB8CD59AAEDD}.Release|x86.Build.0 = Release|Any CPU
|
|
||||||
{ED216205-2F90-0BB5-0D98-3A415A0CFC17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{ED216205-2F90-0BB5-0D98-3A415A0CFC17}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{ED216205-2F90-0BB5-0D98-3A415A0CFC17}.Debug|x64.ActiveCfg = Debug|Any CPU
|
|
||||||
{ED216205-2F90-0BB5-0D98-3A415A0CFC17}.Debug|x64.Build.0 = Debug|Any CPU
|
|
||||||
{ED216205-2F90-0BB5-0D98-3A415A0CFC17}.Debug|x86.ActiveCfg = Debug|Any CPU
|
|
||||||
{ED216205-2F90-0BB5-0D98-3A415A0CFC17}.Debug|x86.Build.0 = Debug|Any CPU
|
|
||||||
{ED216205-2F90-0BB5-0D98-3A415A0CFC17}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{ED216205-2F90-0BB5-0D98-3A415A0CFC17}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{ED216205-2F90-0BB5-0D98-3A415A0CFC17}.Release|x64.ActiveCfg = Release|Any CPU
|
|
||||||
{ED216205-2F90-0BB5-0D98-3A415A0CFC17}.Release|x64.Build.0 = Release|Any CPU
|
|
||||||
{ED216205-2F90-0BB5-0D98-3A415A0CFC17}.Release|x86.ActiveCfg = Release|Any CPU
|
|
||||||
{ED216205-2F90-0BB5-0D98-3A415A0CFC17}.Release|x86.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
|
||||||
SolutionGuid = {FCED30C2-186B-4550-A55A-FBD7489ED4B9}
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<Solution>
|
||||||
|
<Configurations>
|
||||||
|
<Configuration Name="Debug" />
|
||||||
|
<Configuration Name="Release" />
|
||||||
|
<Platform Name="x64" />
|
||||||
|
</Configurations>
|
||||||
|
<Project Path="SimplePlugin/SimplePlugin.csproj" />
|
||||||
|
</Solution>
|
||||||
@@ -1,16 +1,59 @@
|
|||||||
using Daybreak.Shared.Shared.Models.Plugins;
|
using Daybreak.Shared.Models.Plugins;
|
||||||
|
using Daybreak.Shared.Services.Initialization;
|
||||||
|
using Daybreak.Shared.Services.Notifications;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using SimplePlugin.Services;
|
using SimplePlugin.Services;
|
||||||
using System.Core.Extensions;
|
|
||||||
|
|
||||||
namespace SimplePlugin.Configuration;
|
namespace SimplePlugin.Configuration;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This class acts as the manifest of the plugin.
|
||||||
|
/// This is where you can declare everything that the plugin provides.
|
||||||
|
/// Provides configuration and registration logic for plugins.
|
||||||
|
/// </summary>
|
||||||
public sealed class PluginConfiguration : PluginConfigurationBase
|
public sealed class PluginConfiguration : PluginConfigurationBase
|
||||||
{
|
{
|
||||||
|
public override void RegisterViews(IViewProducer viewProducer)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void RegisterThemes(IThemeProducer themeProducer)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void RegisterStartupActions(IStartupActionProducer startupActionProducer)
|
||||||
|
{
|
||||||
|
startupActionProducer.RegisterAction<SimpleNotificationStartupAction>();
|
||||||
|
}
|
||||||
|
|
||||||
public override void RegisterServices(IServiceCollection services)
|
public override void RegisterServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.ThrowIfNull();
|
}
|
||||||
|
|
||||||
services.AddSingleton<EmitLoadedNotificationService>();
|
public override void RegisterPostUpdateActions(IPostUpdateActionProducer postUpdateActionProducer)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void RegisterOptions(IOptionsProducer optionsProducer)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void RegisterNotificationHandlers(INotificationHandlerProducer notificationHandlerProducer)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void RegisterMenuButtons(IMenuServiceProducer menuServiceProducer)
|
||||||
|
{
|
||||||
|
menuServiceProducer.CreateIfNotExistCategory("Simple Plugin Category")
|
||||||
|
.RegisterButton("Click me", "I dare you!", sp => sp.GetRequiredService<INotificationService>().NotifyError(title: "Gotcha!", description: "Not so simple, is it?"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void RegisterLaunchArgumentHandlers(IArgumentHandlerProducer argumentHandlerProducer)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void RegisterMods(IModsProducer modsProducer)
|
||||||
|
{
|
||||||
|
modsProducer.RegisterMod<SimpleNotificationMod, SimpleNotificationMod>(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using Daybreak.Shared.Attributes;
|
||||||
|
|
||||||
|
namespace SimplePlugin.Options;
|
||||||
|
|
||||||
|
[OptionsName(Name = "Simple Plugin Options")]
|
||||||
|
public sealed class SimpleOptions
|
||||||
|
{
|
||||||
|
[OptionName(Name = "Enable Feature X", Description = "Enables or disables Feature X in the Simple Plugin (does nothing but looks cool)")]
|
||||||
|
public bool EnableFeatureX { get; set; } = true;
|
||||||
|
[OptionName(Name = "Things Count", Description = "Specifies the number of things to process (just a number for demonstration)")]
|
||||||
|
public int ThingsCount { get; set; }
|
||||||
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
using Daybreak.Shared.Services.Notifications;
|
|
||||||
using System.Core.Extensions;
|
|
||||||
using System.Windows.Extensions.Services;
|
|
||||||
|
|
||||||
namespace SimplePlugin.Services;
|
|
||||||
public sealed class EmitLoadedNotificationService : IApplicationLifetimeService
|
|
||||||
{
|
|
||||||
private readonly INotificationService notificationService;
|
|
||||||
|
|
||||||
public EmitLoadedNotificationService(
|
|
||||||
INotificationService notificationService)
|
|
||||||
{
|
|
||||||
this.notificationService = notificationService.ThrowIfNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnClosing()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public async void OnStartup()
|
|
||||||
{
|
|
||||||
await Task.Delay(2000);
|
|
||||||
this.notificationService.NotifyInformation("SimplePlugin", "Successfully loaded!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
using Daybreak.Shared.Models.Async;
|
||||||
|
using Daybreak.Shared.Models.Mods;
|
||||||
|
using Daybreak.Shared.Services.Mods;
|
||||||
|
using Daybreak.Shared.Services.Notifications;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using SimplePlugin.Options;
|
||||||
|
using System.Core.Extensions;
|
||||||
|
using System.Extensions.Core;
|
||||||
|
|
||||||
|
namespace SimplePlugin.Services;
|
||||||
|
|
||||||
|
public sealed class SimpleNotificationMod(
|
||||||
|
INotificationService notificationService,
|
||||||
|
IOptionsMonitor<SimpleOptions> simpleOptions,
|
||||||
|
ILogger<SimpleNotificationMod> logger)
|
||||||
|
: IModService
|
||||||
|
{
|
||||||
|
private readonly INotificationService notificationService = notificationService.ThrowIfNull();
|
||||||
|
private readonly IOptionsMonitor<SimpleOptions> simpleOptions = simpleOptions.ThrowIfNull();
|
||||||
|
private readonly ILogger<SimpleNotificationMod> logger = logger.ThrowIfNull();
|
||||||
|
|
||||||
|
public string Name { get; } = "Simple Notification Mod";
|
||||||
|
public string Description { get; } = "A simple mod that shows notifications on Guild Wars application lifetime.";
|
||||||
|
public bool IsEnabled { get; set; } = true;
|
||||||
|
public bool IsInstalled { get; } = true;
|
||||||
|
public bool IsVisible { get; } = true;
|
||||||
|
public bool CanCustomManage { get; } = false;
|
||||||
|
public bool CanUninstall { get; } = false;
|
||||||
|
|
||||||
|
public IEnumerable<string> GetCustomArguments() => [];
|
||||||
|
|
||||||
|
public Task<bool> IsUpdateAvailable(CancellationToken cancellationToken) => Task.FromResult(false);
|
||||||
|
|
||||||
|
public Task OnCustomManagement(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||||
|
|
||||||
|
public Task OnGuildWarsCreated(GuildWarsCreatedContext guildWarsCreatedContext, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var scopedLogger = this.logger.CreateScopedLogger();
|
||||||
|
var notificationToken = this.notificationService.NotifyInformation(
|
||||||
|
title: nameof(this.OnGuildWarsCreated),
|
||||||
|
description: $"You've been notified by {nameof(SimpleNotificationMod)}!");
|
||||||
|
|
||||||
|
|
||||||
|
scopedLogger.LogWarning("Find me in the logs!");
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task OnGuildWarsRunning(GuildWarsRunningContext guildWarsRunningContext, CancellationToken cancellationToken) => Task.CompletedTask;
|
||||||
|
|
||||||
|
public Task OnGuildWarsStarted(GuildWarsStartedContext guildWarsStartedContext, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var scopedLogger = this.logger.CreateScopedLogger();
|
||||||
|
var notificationToken = this.notificationService.NotifyInformation(
|
||||||
|
title: nameof(this.OnGuildWarsStarted),
|
||||||
|
description: $"{nameof(SimpleNotificationMod)} is under your bed!");
|
||||||
|
|
||||||
|
|
||||||
|
scopedLogger.LogWarning("No seriously, where am I?");
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task OnGuildWarsStarting(GuildWarsStartingContext guildWarsStartingContext, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var scopedLogger = this.logger.CreateScopedLogger();
|
||||||
|
var notificationToken = this.notificationService.NotifyInformation(
|
||||||
|
title: nameof(this.OnGuildWarsStarting),
|
||||||
|
description: $"{nameof(SimpleNotificationMod)} is looking straight at you!");
|
||||||
|
|
||||||
|
|
||||||
|
scopedLogger.LogWarning("Peekaboo!");
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task OnGuildWarsStartingDisabled(GuildWarsStartingDisabledContext guildWarsStartingDisabledContext, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var scopedLogger = this.logger.CreateScopedLogger();
|
||||||
|
var notificationToken = this.notificationService.NotifyInformation(
|
||||||
|
title: nameof(this.OnGuildWarsStartingDisabled),
|
||||||
|
description: $"{nameof(SimpleNotificationMod)}: How did you manage that?");
|
||||||
|
|
||||||
|
|
||||||
|
scopedLogger.LogWarning("You're no fun!");
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IProgressAsyncOperation<bool> PerformInstallation(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IProgressAsyncOperation<bool> PerformUninstallation(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<bool> PerformUpdate(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<bool> ShouldRunAgain(GuildWarsRunningContext guildWarsRunningContext, CancellationToken cancellationToken) => Task.FromResult(false);
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
using Daybreak.Shared.Models;
|
||||||
|
using Daybreak.Shared.Services.Notifications;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Extensions.Core;
|
||||||
|
|
||||||
|
namespace SimplePlugin.Services;
|
||||||
|
|
||||||
|
public sealed class SimpleNotificationStartupAction(
|
||||||
|
INotificationService notificationService,
|
||||||
|
ILogger<SimpleNotificationStartupAction> logger)
|
||||||
|
: StartupActionBase
|
||||||
|
{
|
||||||
|
private readonly INotificationService notificationService = notificationService;
|
||||||
|
private readonly ILogger<SimpleNotificationStartupAction> logger = logger;
|
||||||
|
|
||||||
|
public override void ExecuteOnStartup()
|
||||||
|
{
|
||||||
|
var scopedLogger = this.logger.CreateScopedLogger();
|
||||||
|
Task.Factory.StartNew(async () =>
|
||||||
|
{
|
||||||
|
scopedLogger.LogInformation("SimpleNotificationStartupAction: Waiting for 3 seconds before sending notification.");
|
||||||
|
await Task.Delay(3000);
|
||||||
|
|
||||||
|
scopedLogger.LogInformation("SimpleNotificationStartupAction: Sending startup notification.");
|
||||||
|
this.notificationService.NotifyInformation(
|
||||||
|
title: "Simple Plugin",
|
||||||
|
description: "Reporting for duty!");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0-windows</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user