From 51edeae93a9cb2ed8124b3a55e36b1659ffbbdba Mon Sep 17 00:00:00 2001 From: Macocian Alexandru Victor Date: Sat, 17 May 2025 16:22:47 +0200 Subject: [PATCH] Further decouple shared project from main application (#991) --- .../EventCalendarDayToBrushConverter.cs | 4 +- Daybreak.Shared/Daybreak.Shared.csproj | 27 +------------ Daybreak.Shared/Models/EventViewModel.cs | 2 +- Daybreak.Shared/Models/KeyMacro.cs | 10 ----- .../Models/KeyboardHookEventArgs.cs | 16 -------- Daybreak.Shared/Models/KeyboardInput.cs | 40 ------------------- Daybreak.Shared/Models/KeyboardState.cs | 9 ----- Daybreak.Shared/Models/Win32Window.cs | 15 ------- .../Guildwars/IGuildWarsVersionChecker.cs | 3 +- .../Services/Shortcuts/IShortcutManager.cs | 6 +-- .../Services/Themes/IThemeManager.cs | 6 +-- .../Services/Updater/IApplicationUpdater.cs | 3 +- Daybreak/Daybreak.csproj | 24 +++++++++++ .../Guildwars/GuildWarsVersionChecker.cs | 3 +- .../Services/Screens/SplashScreenService.cs | 11 ++++- .../Services/Shortcuts/ShortcutManager.cs | 3 +- Daybreak/Services/Themes/ThemeManager.cs | 2 +- .../Services/Updater/ApplicationUpdater.cs | 3 +- 18 files changed, 50 insertions(+), 137 deletions(-) delete mode 100644 Daybreak.Shared/Models/KeyMacro.cs delete mode 100644 Daybreak.Shared/Models/KeyboardHookEventArgs.cs delete mode 100644 Daybreak.Shared/Models/KeyboardInput.cs delete mode 100644 Daybreak.Shared/Models/KeyboardState.cs delete mode 100644 Daybreak.Shared/Models/Win32Window.cs diff --git a/Daybreak.Shared/Converters/EventCalendarDayToBrushConverter.cs b/Daybreak.Shared/Converters/EventCalendarDayToBrushConverter.cs index 0b3abe99..19887c5d 100644 --- a/Daybreak.Shared/Converters/EventCalendarDayToBrushConverter.cs +++ b/Daybreak.Shared/Converters/EventCalendarDayToBrushConverter.cs @@ -1,7 +1,5 @@ -using Daybreak.Shared; -using Daybreak.Shared.Models.Guildwars; +using Daybreak.Shared.Models.Guildwars; using Daybreak.Shared.Services.Events; -using ExCSS; using Microsoft.Extensions.DependencyInjection; using System; using System.Globalization; diff --git a/Daybreak.Shared/Daybreak.Shared.csproj b/Daybreak.Shared/Daybreak.Shared.csproj index d36d7a3d..5a9ee277 100644 --- a/Daybreak.Shared/Daybreak.Shared.csproj +++ b/Daybreak.Shared/Daybreak.Shared.csproj @@ -9,43 +9,18 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/Daybreak.Shared/Models/EventViewModel.cs b/Daybreak.Shared/Models/EventViewModel.cs index bc1c1121..9fa99b5b 100644 --- a/Daybreak.Shared/Models/EventViewModel.cs +++ b/Daybreak.Shared/Models/EventViewModel.cs @@ -1,6 +1,6 @@ using Daybreak.Shared.Models.Guildwars; using System.ComponentModel; -using System.Windows.Extensions; +using System.Extensions; namespace Daybreak.Models; public partial class EventViewModel : INotifyPropertyChanged diff --git a/Daybreak.Shared/Models/KeyMacro.cs b/Daybreak.Shared/Models/KeyMacro.cs deleted file mode 100644 index 15173ab4..00000000 --- a/Daybreak.Shared/Models/KeyMacro.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Generic; -using System.Windows.Forms; - -namespace Daybreak.Shared.Models; - -public sealed class KeyMacro -{ - public List? Keys { get; set; } - public Keys TargetKey { get; set; } -} diff --git a/Daybreak.Shared/Models/KeyboardHookEventArgs.cs b/Daybreak.Shared/Models/KeyboardHookEventArgs.cs deleted file mode 100644 index 04954b75..00000000 --- a/Daybreak.Shared/Models/KeyboardHookEventArgs.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Daybreak.Shared.Models; - -public sealed class KeyboardHookEventArgs -{ - public bool Handled { get; set; } - public KeyboardState KeyboardState { get; } - public KeyboardInput KeyboardInput { get; } - - public KeyboardHookEventArgs( - KeyboardState keyboardState, - KeyboardInput keyboardInput) - { - this.KeyboardState = keyboardState; - this.KeyboardInput = keyboardInput; - } -} diff --git a/Daybreak.Shared/Models/KeyboardInput.cs b/Daybreak.Shared/Models/KeyboardInput.cs deleted file mode 100644 index e931968a..00000000 --- a/Daybreak.Shared/Models/KeyboardInput.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Windows.Forms; - -namespace Daybreak.Shared.Models; - -[StructLayout(LayoutKind.Sequential)] -public struct KeyboardInput -{ - /// - /// A virtual-key code. The code must be a value in the range 1 to 254. - /// - public int VirtualCode; - - // EDT: added a conversion from VirtualCode to Keys. - /// - /// The VirtualCode converted to typeof(Keys) for higher usability. - /// - public Keys Key { get { return (Keys)this.VirtualCode; } } - - /// - /// A hardware scan code for the key. - /// - public int HardwareScanCode; - - /// - /// The extended-key flag, event-injected Flags, context code, and transition-state flag. This member is specified as follows. An application can use the following values to test the keystroke Flags. Testing LLKHF_INJECTED (bit 4) will tell you whether the event was injected. If it was, then testing LLKHF_LOWER_IL_INJECTED (bit 1) will tell you whether or not the event was injected from a process running at lower integrity level. - /// - public int Flags; - - /// - /// The time stamp stamp for this message, equivalent to what GetMessageTime would return for this message. - /// - public int TimeStamp; - - /// - /// Additional information associated with the message. - /// - public nint AdditionalInformation; -} diff --git a/Daybreak.Shared/Models/KeyboardState.cs b/Daybreak.Shared/Models/KeyboardState.cs deleted file mode 100644 index 1bdece5c..00000000 --- a/Daybreak.Shared/Models/KeyboardState.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Daybreak.Shared.Models; - -public enum KeyboardState -{ - KeyDown = 0x0100, - KeyUp = 0x0101, - SysKeyDown = 0x0104, - SysKeyUp = 0x0105 -} diff --git a/Daybreak.Shared/Models/Win32Window.cs b/Daybreak.Shared/Models/Win32Window.cs deleted file mode 100644 index 17f637c0..00000000 --- a/Daybreak.Shared/Models/Win32Window.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Windows; -using System.Windows.Interop; - -namespace Daybreak.Shared.Models; - -public sealed class Win32Window : System.Windows.Forms.IWin32Window -{ - public Win32Window(Window window) - { - this.Handle = new WindowInteropHelper(window).Handle; - } - - public nint Handle { get; init; } -} diff --git a/Daybreak.Shared/Services/Guildwars/IGuildWarsVersionChecker.cs b/Daybreak.Shared/Services/Guildwars/IGuildWarsVersionChecker.cs index 3fe0cbc3..a0355943 100644 --- a/Daybreak.Shared/Services/Guildwars/IGuildWarsVersionChecker.cs +++ b/Daybreak.Shared/Services/Guildwars/IGuildWarsVersionChecker.cs @@ -1,7 +1,6 @@ using Daybreak.Shared.Services.Mods; -using System.Windows.Extensions.Services; namespace Daybreak.Shared.Services.Guildwars; -public interface IGuildWarsVersionChecker : IModService, IApplicationLifetimeService +public interface IGuildWarsVersionChecker : IModService { } diff --git a/Daybreak.Shared/Services/Shortcuts/IShortcutManager.cs b/Daybreak.Shared/Services/Shortcuts/IShortcutManager.cs index 0ae8781c..fed4ff5a 100644 --- a/Daybreak.Shared/Services/Shortcuts/IShortcutManager.cs +++ b/Daybreak.Shared/Services/Shortcuts/IShortcutManager.cs @@ -1,8 +1,6 @@ -using System.Windows.Extensions.Services; +namespace Daybreak.Shared.Services.Shortcuts; -namespace Daybreak.Shared.Services.Shortcuts; - -public interface IShortcutManager : IApplicationLifetimeService +public interface IShortcutManager { bool ShortcutEnabled { get; set; } } diff --git a/Daybreak.Shared/Services/Themes/IThemeManager.cs b/Daybreak.Shared/Services/Themes/IThemeManager.cs index ef8ac895..0c53a7cf 100644 --- a/Daybreak.Shared/Services/Themes/IThemeManager.cs +++ b/Daybreak.Shared/Services/Themes/IThemeManager.cs @@ -1,9 +1,9 @@ -using ControlzEx.Theming; -using System.Windows.Media; +using System.Windows.Media; namespace Daybreak.Shared.Services.Themes; public interface IThemeManager { - Theme GetCurrentTheme(); + // Hacky way to pass the theme without having to take a dependency on the theme manager + object? GetCurrentTheme(); Color GetForegroundColor(); } diff --git a/Daybreak.Shared/Services/Updater/IApplicationUpdater.cs b/Daybreak.Shared/Services/Updater/IApplicationUpdater.cs index 23053450..44ad7631 100644 --- a/Daybreak.Shared/Services/Updater/IApplicationUpdater.cs +++ b/Daybreak.Shared/Services/Updater/IApplicationUpdater.cs @@ -1,12 +1,11 @@ using Daybreak.Shared.Models.Progress; using System.Collections.Generic; using System.Threading.Tasks; -using System.Windows.Extensions.Services; using Version = Daybreak.Shared.Models.Versioning.Version; namespace Daybreak.Shared.Services.Updater; -public interface IApplicationUpdater : IApplicationLifetimeService +public interface IApplicationUpdater { Version CurrentVersion { get; } void FinalizeUpdate(); diff --git a/Daybreak/Daybreak.csproj b/Daybreak/Daybreak.csproj index b84b99f4..f19b101d 100644 --- a/Daybreak/Daybreak.csproj +++ b/Daybreak/Daybreak.csproj @@ -53,6 +53,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Daybreak/Services/Guildwars/GuildWarsVersionChecker.cs b/Daybreak/Services/Guildwars/GuildWarsVersionChecker.cs index 902058bf..f0c6161c 100644 --- a/Daybreak/Services/Guildwars/GuildWarsVersionChecker.cs +++ b/Daybreak/Services/Guildwars/GuildWarsVersionChecker.cs @@ -10,9 +10,10 @@ using System.Core.Extensions; using System.Extensions; using System.Threading; using System.Threading.Tasks; +using System.Windows.Extensions.Services; namespace Daybreak.Services.GuildWars; -internal sealed class GuildWarsVersionChecker : IGuildWarsVersionChecker +internal sealed class GuildWarsVersionChecker : IGuildWarsVersionChecker, IApplicationLifetimeService { public string Name => "GuildWars Version Checker"; public bool IsEnabled { get; set; } = true; diff --git a/Daybreak/Services/Screens/SplashScreenService.cs b/Daybreak/Services/Screens/SplashScreenService.cs index 47d23e88..5e0e5ef5 100644 --- a/Daybreak/Services/Screens/SplashScreenService.cs +++ b/Daybreak/Services/Screens/SplashScreenService.cs @@ -1,4 +1,5 @@ -using Daybreak.Configuration.Options; +using ControlzEx.Theming; +using Daybreak.Configuration.Options; using Daybreak.Launch; using Daybreak.Shared.Models; using Daybreak.Shared.Services.Screens; @@ -6,6 +7,7 @@ using Daybreak.Shared.Services.Themes; using Microsoft.Extensions.Options; using System.Collections.Generic; using System.Core.Extensions; +using System.Extensions; using System.Linq; using System.Windows; @@ -51,7 +53,12 @@ internal sealed class SplashScreenService : ISplashScreenService private void SetupThemeResources() { - var theme = this.themeManager.GetCurrentTheme(); + var theme = this.themeManager.GetCurrentTheme()?.As(); + if (theme is null) + { + return; + } + foreach(var key in theme.Resources.Keys) { this.splashWindow.Resources.Add(key, theme.Resources[key]); diff --git a/Daybreak/Services/Shortcuts/ShortcutManager.cs b/Daybreak/Services/Shortcuts/ShortcutManager.cs index b35ab300..bb67af19 100644 --- a/Daybreak/Services/Shortcuts/ShortcutManager.cs +++ b/Daybreak/Services/Shortcuts/ShortcutManager.cs @@ -6,11 +6,12 @@ using System.Configuration; using System.Diagnostics; using System.Extensions; using System.IO; +using System.Windows.Extensions.Services; namespace Daybreak.Services.Shortcuts; //TODO: Fix dependency on IConfigurationManager -internal sealed class ShortcutManager : IShortcutManager +internal sealed class ShortcutManager : IShortcutManager, IApplicationLifetimeService { private const string ShortcutName = "Daybreak.lnk"; diff --git a/Daybreak/Services/Themes/ThemeManager.cs b/Daybreak/Services/Themes/ThemeManager.cs index 38ee2ded..daceadf4 100644 --- a/Daybreak/Services/Themes/ThemeManager.cs +++ b/Daybreak/Services/Themes/ThemeManager.cs @@ -44,7 +44,7 @@ internal sealed class ThemeManager : IThemeManager, IApplicationLifetimeService return (Color)mahAppsResources!["MahApps.Colors.ThemeForeground"]; } - public Theme GetCurrentTheme() + public object? GetCurrentTheme() { return ControlzEx.Theming.ThemeManager.Current.DetectTheme(Launcher.Instance) ?? throw new InvalidOperationException("Unable to retrieve theme"); } diff --git a/Daybreak/Services/Updater/ApplicationUpdater.cs b/Daybreak/Services/Updater/ApplicationUpdater.cs index 29e71327..ef920742 100644 --- a/Daybreak/Services/Updater/ApplicationUpdater.cs +++ b/Daybreak/Services/Updater/ApplicationUpdater.cs @@ -25,12 +25,13 @@ using System.Reflection; using System.Text; using System.Threading; using System.Threading.Tasks; +using System.Windows.Extensions.Services; using UpdateStatus = Daybreak.Shared.Models.Progress.UpdateStatus; using Version = Daybreak.Shared.Models.Versioning.Version; namespace Daybreak.Services.Updater; -internal sealed class ApplicationUpdater : IApplicationUpdater +internal sealed class ApplicationUpdater : IApplicationUpdater, IApplicationLifetimeService { private const string UpdatePkgSubPath = "update.pkg"; private const string TempInstallerFileNameSubPath = "Daybreak.Installer.Temp.exe";