From 057d96d63d7378cde626f0ff964f6141f71ac4fa Mon Sep 17 00:00:00 2001 From: Matus Horvath Date: Wed, 22 Oct 2025 11:20:12 +0200 Subject: [PATCH] Replace dialogs with toasts WIP --- Directory.Packages.props | 6 ++---- Installer/ShadowKVM.wxs | 5 +++-- README.md | 2 +- ShadowKVM.Tests/ShadowKVM.Tests.csproj | 2 +- ShadowKVM.Tests/UserInterface/ConfigEditor.cs | 6 +++--- ShadowKVM/Devices/WindowsAPI.cs | 2 -- ShadowKVM/ShadowKVM.csproj | 5 +++-- ShadowKVM/UserInterface/ConfigEditor.cs | 2 +- ShadowKVM/UserInterface/NativeUserInterface.cs | 16 ++++++++++------ 9 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index b01d18a..55b0ffa 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,10 +1,8 @@ - true - @@ -12,6 +10,7 @@ + @@ -29,5 +28,4 @@ - - + \ No newline at end of file diff --git a/Installer/ShadowKVM.wxs b/Installer/ShadowKVM.wxs index 944022f..6022c2d 100644 --- a/Installer/ShadowKVM.wxs +++ b/Installer/ShadowKVM.wxs @@ -18,10 +18,11 @@ - + + + Message="This application requires Windows 10 or newer." /> - net9.0-windows + net9.0-windows10.0.17763.0 enable enable false diff --git a/ShadowKVM.Tests/UserInterface/ConfigEditor.cs b/ShadowKVM.Tests/UserInterface/ConfigEditor.cs index b6f4144..202b45a 100644 --- a/ShadowKVM.Tests/UserInterface/ConfigEditor.cs +++ b/ShadowKVM.Tests/UserInterface/ConfigEditor.cs @@ -45,7 +45,7 @@ public async Task EditConfig_WithNoChanges() _nativeUserInterface.Verify(); _logger.Verify(); - _nativeUserInterface.Verify(m => m.InfoBox(It.IsAny(), It.IsAny()), Times.Never); + _nativeUserInterface.Verify(m => m.InfoToast(It.IsAny()), Times.Never); Assert.True(openedEvent); Assert.True(closedEvent); @@ -70,7 +70,7 @@ public async Task EditConfig_WithChanges() .Verifiable(); _nativeUserInterface - .Setup(m => m.InfoBox("Configuration file loaded successfully", "Shadow KVM")) + .Setup(m => m.InfoToast("Configuration file loaded successfully")) .Verifiable(); var editor = new ConfigEditor(_configService.Object, _nativeUserInterface.Object, _logger.Object); @@ -184,6 +184,6 @@ public async Task EditConfig_WithoutEventHandlers() _nativeUserInterface.Verify(); _logger.Verify(); - _nativeUserInterface.Verify(m => m.InfoBox(It.IsAny(), It.IsAny()), Times.Never); + _nativeUserInterface.Verify(m => m.InfoToast(It.IsAny()), Times.Never); } } diff --git a/ShadowKVM/Devices/WindowsAPI.cs b/ShadowKVM/Devices/WindowsAPI.cs index 9d20e91..b830268 100644 --- a/ShadowKVM/Devices/WindowsAPI.cs +++ b/ShadowKVM/Devices/WindowsAPI.cs @@ -1,7 +1,6 @@ using System.Diagnostics.CodeAnalysis; using System.Management; using System.Runtime.InteropServices; -using System.Runtime.Versioning; using Windows.Win32; using Windows.Win32.Devices.Display; using Windows.Win32.Devices.DeviceAndDriverInstallation; @@ -113,7 +112,6 @@ public unsafe int GetVCPFeatureAndVCPFeatureReply( } // For DeviceNotificationService - [SupportedOSPlatform("windows8.0")] public unsafe CONFIGRET CM_Register_Notification(CM_NOTIFY_FILTER pFilter, nuint pContext, PCM_NOTIFY_CALLBACK pCallback, out CM_Unregister_NotificationSafeHandle pNotifyContext) { diff --git a/ShadowKVM/ShadowKVM.csproj b/ShadowKVM/ShadowKVM.csproj index 226ec83..b81c4fd 100644 --- a/ShadowKVM/ShadowKVM.csproj +++ b/ShadowKVM/ShadowKVM.csproj @@ -3,7 +3,7 @@ WinExe - net9.0-windows + net9.0-windows10.0.17763.0 enable enable true @@ -11,7 +11,7 @@ UserInterface/Application.ico - Shadow KVM: Sync your monitor inputs with a USB switch for seamless multi-PC control + Shadow KVM Matúš Horváth © 2025 Matúš Horváth. All rights reserved. Shadow KVM @@ -26,6 +26,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/ShadowKVM/UserInterface/ConfigEditor.cs b/ShadowKVM/UserInterface/ConfigEditor.cs index 412ca9e..e6e1a22 100644 --- a/ShadowKVM/UserInterface/ConfigEditor.cs +++ b/ShadowKVM/UserInterface/ConfigEditor.cs @@ -31,7 +31,7 @@ public async Task EditConfig() return; } - nativeUserInterface.InfoBox("Configuration file loaded successfully", "Shadow KVM"); + nativeUserInterface.InfoToast("Configuration file loaded successfully"); } finally { diff --git a/ShadowKVM/UserInterface/NativeUserInterface.cs b/ShadowKVM/UserInterface/NativeUserInterface.cs index c2e8aa6..e7be47f 100644 --- a/ShadowKVM/UserInterface/NativeUserInterface.cs +++ b/ShadowKVM/UserInterface/NativeUserInterface.cs @@ -1,6 +1,7 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Windows; +using Microsoft.Toolkit.Uwp.Notifications; namespace ShadowKVM; @@ -10,9 +11,10 @@ public interface INativeUserInterface void OpenUrl(string url); void ErrorBox(string message, string title); - void InfoBox(string message, string title); bool QuestionBox(string message, string title); + void InfoToast(string message); + void ShowWindow(TDataContext? dataContext = null, EventHandler? closedHandler = null) where TWindow : Window, new() where TDataContext : class; @@ -42,17 +44,19 @@ public void ErrorBox(string message, string title) MessageBox.Show(message, title, MessageBoxButton.OK, MessageBoxImage.Error); } - public void InfoBox(string message, string title) - { - MessageBox.Show(message, title, MessageBoxButton.OK, MessageBoxImage.Information); - } - public bool QuestionBox(string message, string title) { var result = MessageBox.Show(message, title, MessageBoxButton.YesNo, MessageBoxImage.Question); return result == MessageBoxResult.Yes; } + public void InfoToast(string message) + { + new ToastContentBuilder() + .AddText(message) + .Show(); + } + public void ShowWindow(TDataContext? dataContext = null, EventHandler? closedHandler = null) where TWindow : Window, new() where TDataContext : class