diff --git a/DesktopNotifications.Apple/AppleNotificationManager.cs b/DesktopNotifications.Apple/AppleNotificationManager.cs index 203b03d..e709b6a 100644 --- a/DesktopNotifications.Apple/AppleNotificationManager.cs +++ b/DesktopNotifications.Apple/AppleNotificationManager.cs @@ -8,9 +8,6 @@ namespace DesktopNotifications.Apple { public class AppleNotificationManager : INotificationManager { - [DllImport("DesktopNotifications.Apple.Native.dylib")] - private static extern void ShowNotification(); - public void Dispose() { } @@ -42,5 +39,8 @@ public Task HideNotification(Notification notification) { return Task.CompletedTask; } + + [DllImport("DesktopNotifications.Apple.Native.dylib")] + private static extern void ShowNotification(); } -} +} \ No newline at end of file diff --git a/DesktopNotifications.Avalonia/AppBuilderExtensions.cs b/DesktopNotifications.Avalonia/AppBuilderExtensions.cs index be5dc84..f38d608 100644 --- a/DesktopNotifications.Avalonia/AppBuilderExtensions.cs +++ b/DesktopNotifications.Avalonia/AppBuilderExtensions.cs @@ -8,13 +8,13 @@ namespace DesktopNotifications.Avalonia { /// - /// Extensions for + /// Extensions for /// public static class AppBuilderExtensions { /// - /// Setups the for the current platform and - /// binds it to the service locator (). + /// Setups the for the current platform and + /// binds it to the service locator (). /// /// /// @@ -52,10 +52,7 @@ public static TAppBuilder SetupDesktopNotifications(this TAppBuilde { if (b.Instance.ApplicationLifetime is IControlledApplicationLifetime lifetime) { - lifetime.Exit += (s, e) => - { - manager.Dispose(); - }; + lifetime.Exit += (s, e) => { manager.Dispose(); }; } }); diff --git a/DesktopNotifications.FreeDesktop/FreeDesktopNotificationManager.cs b/DesktopNotifications.FreeDesktop/FreeDesktopNotificationManager.cs index 40e77d1..2f36563 100644 --- a/DesktopNotifications.FreeDesktop/FreeDesktopNotificationManager.cs +++ b/DesktopNotifications.FreeDesktop/FreeDesktopNotificationManager.cs @@ -3,17 +3,16 @@ using System.Linq; using System.Threading.Tasks; using Tmds.DBus; -using static DesktopNotifications.Extensions; namespace DesktopNotifications.FreeDesktop { public class FreeDesktopNotificationManager : INotificationManager, IDisposable { - private readonly FreeDesktopApplicationContext _appContext; private const string NotificationsService = "org.freedesktop.Notifications"; private static readonly ObjectPath NotificationsPath = new ObjectPath("/org/freedesktop/Notifications"); private readonly Dictionary _activeNotifications; + private readonly FreeDesktopApplicationContext _appContext; private Connection? _connection; private IDisposable? _notificationActionSubscription; private IDisposable? _notificationCloseSubscription; @@ -21,7 +20,6 @@ public class FreeDesktopNotificationManager : INotificationManager, IDisposable private IFreeDesktopNotificationsProxy? _proxy; /// - /// /// /// public FreeDesktopNotificationManager(FreeDesktopApplicationContext? appContext = null) @@ -88,14 +86,6 @@ public async Task ShowNotification(Notification notification, DateTimeOffset? ex _activeNotifications[id] = notification; } - private void CheckConnection() - { - if (_connection == null || _proxy == null) - { - throw new InvalidOperationException("Not connected. Call Initialize() first."); - } - } - public async Task HideNotification(Notification notification) { CheckConnection(); @@ -125,6 +115,14 @@ public async Task ScheduleNotification( await ShowNotification(notification, expirationTime); } + private void CheckConnection() + { + if (_connection == null || _proxy == null) + { + throw new InvalidOperationException("Not connected. Call Initialize() first."); + } + } + private static IEnumerable GenerateActions(Notification notification) { foreach (var (title, actionId) in notification.Buttons) @@ -182,4 +180,4 @@ private void OnNotificationActionInvoked((uint id, string actionKey) @event) new NotificationActivatedEventArgs(notification, @event.actionKey)); } } -} +} \ No newline at end of file diff --git a/DesktopNotifications.FreeDesktop/FreeDesktopNotificationProxy.cs b/DesktopNotifications.FreeDesktop/FreeDesktopNotificationProxy.cs index 7f3864c..a0296c1 100644 --- a/DesktopNotifications.FreeDesktop/FreeDesktopNotificationProxy.cs +++ b/DesktopNotifications.FreeDesktop/FreeDesktopNotificationProxy.cs @@ -17,7 +17,8 @@ namespace DesktopNotifications.FreeDesktop [DBusInterface("org.freedesktop.Notifications")] internal interface IFreeDesktopNotificationsProxy : IDBusObject { - Task NotifyAsync(string appName, uint replacesId, string appIcon, string summary, string body, string[] actions, IDictionary hints, int expireTimeout); + Task NotifyAsync(string appName, uint replacesId, string appIcon, string summary, string body, + string[] actions, IDictionary hints, int expireTimeout); Task CloseNotificationAsync(uint id); @@ -25,9 +26,10 @@ internal interface IFreeDesktopNotificationsProxy : IDBusObject Task<(string name, string vendor, string version, string spec_version)> GetServerInformationAsync(); - Task WatchNotificationClosedAsync(Action<(uint id, uint reason)> handler, Action onError = null); + Task WatchNotificationClosedAsync(Action<(uint id, uint reason)> handler, + Action onError = null); - Task WatchActionInvokedAsync(Action<(uint id, string action_key)> handler, Action onError = null); + Task WatchActionInvokedAsync(Action<(uint id, string action_key)> handler, + Action onError = null); } - } \ No newline at end of file diff --git a/DesktopNotifications.Windows/ShellLink.cs b/DesktopNotifications.Windows/ShellLink.cs index 4cf6b7a..16ece8c 100644 --- a/DesktopNotifications.Windows/ShellLink.cs +++ b/DesktopNotifications.Windows/ShellLink.cs @@ -20,27 +20,23 @@ public class ShellLink : IDisposable [Guid("000214F9-0000-0000-C000-000000000046")] private interface IShellLinkW { - uint GetPath([Out] [MarshalAs(UnmanagedType.LPWStr)] - StringBuilder pszFile, + uint GetPath([Out] [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxPath, ref WIN32_FIND_DATAW pfd, uint fFlags); uint GetIDList(out IntPtr ppidl); uint SetIDList(IntPtr pidl); - uint GetDescription([Out] [MarshalAs(UnmanagedType.LPWStr)] - StringBuilder pszName, + uint GetDescription([Out] [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszName, int cchMaxName); uint SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName); - uint GetWorkingDirectory([Out] [MarshalAs(UnmanagedType.LPWStr)] - StringBuilder pszDir, + uint GetWorkingDirectory([Out] [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir, int cchMaxPath); uint SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir); - uint GetArguments([Out] [MarshalAs(UnmanagedType.LPWStr)] - StringBuilder pszArgs, + uint GetArguments([Out] [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs, int cchMaxPath); uint SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs); @@ -49,8 +45,7 @@ uint GetArguments([Out] [MarshalAs(UnmanagedType.LPWStr)] uint GetShowCmd(out int piShowCmd); uint SetShowCmd(int iShowCmd); - uint GetIconLocation([Out] [MarshalAs(UnmanagedType.LPWStr)] - StringBuilder pszIconPath, + uint GetIconLocation([Out] [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath, int cchIconPath, out int piIcon); uint SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon); @@ -164,14 +159,14 @@ private sealed class PropVariant : IDisposable // Value type (System.Runtime.InteropServices.VarEnum) public VarEnum VarType { - get => (VarEnum) valueType; - set => valueType = (ushort) value; + get => (VarEnum)valueType; + set => valueType = (ushort)value; } // Whether value is empty or null public bool IsNullOrEmpty => - valueType == (ushort) VarEnum.VT_EMPTY || - valueType == (ushort) VarEnum.VT_NULL; + valueType == (ushort)VarEnum.VT_EMPTY || + valueType == (ushort)VarEnum.VT_NULL; // Value (only for string value) public string? Value => Marshal.PtrToStringUni(ptr); @@ -192,7 +187,7 @@ public PropVariant(string value) throw new ArgumentException("Failed to set value."); } - valueType = (ushort) VarEnum.VT_LPWSTR; + valueType = (ushort)VarEnum.VT_LPWSTR; ptr = Marshal.StringToCoTaskMemUni(value); } @@ -290,7 +285,7 @@ public string TargetPath get { // No limitation to length of buffer string in the case of Unicode though. - StringBuilder targetPath = new StringBuilder(MAX_PATH); + var targetPath = new StringBuilder(MAX_PATH); var data = new WIN32_FIND_DATAW(); @@ -307,7 +302,7 @@ public string Arguments get { // No limitation to length of buffer string in the case of Unicode though. - StringBuilder arguments = new StringBuilder(INFOTIPSIZE); + var arguments = new StringBuilder(INFOTIPSIZE); VerifySucceeded(shellLinkW!.GetArguments(arguments, arguments.Capacity)); @@ -321,7 +316,7 @@ public string AppUserModelID { get { - using (PropVariant pv = new PropVariant()) + using (var pv = new PropVariant()) { VerifySucceeded(PropertyStore.GetValue(AppUserModelIDKey, pv)); @@ -335,7 +330,7 @@ public string AppUserModelID } set { - using (PropVariant pv = new PropVariant(value)) + using (var pv = new PropVariant(value)) { VerifySucceeded(PropertyStore.SetValue(AppUserModelIDKey, pv)); VerifySucceeded(PropertyStore.Commit()); @@ -357,7 +352,7 @@ public ShellLink(string? file) { try { - shellLinkW = (IShellLinkW) new CShellLink(); + shellLinkW = (IShellLinkW)new CShellLink(); } catch { @@ -402,7 +397,7 @@ protected virtual void Dispose(bool disposing) // Save shortcut file. public void Save() { - string file = ShortcutFile; + var file = ShortcutFile; if (file == null) { diff --git a/DesktopNotifications.Windows/WindowsNotificationManager.cs b/DesktopNotifications.Windows/WindowsNotificationManager.cs index b43c90d..15ed210 100644 --- a/DesktopNotifications.Windows/WindowsNotificationManager.cs +++ b/DesktopNotifications.Windows/WindowsNotificationManager.cs @@ -1,17 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Windows.UI.Notifications; -using XmlDocument = Windows.Data.Xml.Dom.XmlDocument; -using System.Linq; - -#if NETSTANDARD +#if NETSTANDARD using System.IO; using System.Xml; #else using System.Diagnostics; using Microsoft.Toolkit.Uwp.Notifications; #endif +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Windows.Data.Xml.Dom; +using Windows.UI.Notifications; namespace DesktopNotifications.Windows { diff --git a/DesktopNotifications/INotificationManager.cs b/DesktopNotifications/INotificationManager.cs index 287bfcc..dda4904 100644 --- a/DesktopNotifications/INotificationManager.cs +++ b/DesktopNotifications/INotificationManager.cs @@ -42,7 +42,7 @@ public interface INotificationManager : IDisposable Task ShowNotification(Notification notification, DateTimeOffset? expirationTime = null); /// - /// Hides an already delivered notification (if possible). + /// Hides an already delivered notification (if possible). /// If the notification is scheduled for delivery the schedule will be cancelled. /// /// The notification to hide @@ -55,7 +55,7 @@ public interface INotificationManager : IDisposable /// /// Task ScheduleNotification( - Notification notification, + Notification notification, DateTimeOffset deliveryTime, DateTimeOffset? expirationTime = null); } diff --git a/DesktopNotifications/NotificationActivatedEventArgs.cs b/DesktopNotifications/NotificationActivatedEventArgs.cs index b129995..0eeae27 100644 --- a/DesktopNotifications/NotificationActivatedEventArgs.cs +++ b/DesktopNotifications/NotificationActivatedEventArgs.cs @@ -1,7 +1,6 @@ namespace DesktopNotifications { /// - /// /// public class NotificationActivatedEventArgs : NotificationEventArgs { diff --git a/Example.Avalonia/App.axaml b/Example.Avalonia/App.axaml index 5143a3d..02587ec 100644 --- a/Example.Avalonia/App.axaml +++ b/Example.Avalonia/App.axaml @@ -2,6 +2,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="Example.Avalonia.App"> - + - + \ No newline at end of file diff --git a/Example.Avalonia/App.axaml.cs b/Example.Avalonia/App.axaml.cs index 8e1a798..eb5e7f3 100644 --- a/Example.Avalonia/App.axaml.cs +++ b/Example.Avalonia/App.axaml.cs @@ -21,4 +21,4 @@ public override void OnFrameworkInitializationCompleted() base.OnFrameworkInitializationCompleted(); } } -} +} \ No newline at end of file diff --git a/Example.Avalonia/MainWindow.axaml b/Example.Avalonia/MainWindow.axaml index d3c7c87..b93082a 100644 --- a/Example.Avalonia/MainWindow.axaml +++ b/Example.Avalonia/MainWindow.axaml @@ -13,7 +13,7 @@