Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,28 @@ jobs:
/o:"${{ vars.SONAR_ORGANIZATION }}"
/d:sonar.host.url="https://sonarcloud.io"
/d:sonar.token="${{ secrets.SONAR_TOKEN }}"
/d:sonar.cs.opencover.reportsPaths="${{ github.workspace }}/coverage/**/coverage.opencover.xml"
/d:sonar.coverage.exclusions="Tests/**"
/d:sonar.cs.opencover.reportsPaths="coverage/core/**/coverage.opencover.xml,coverage/listener/**/coverage.opencover.xml,coverage/ui/**/coverage.opencover.xml"
/d:sonar.dotnet.excludeTestProjects=true
/d:sonar.exclusions="**/obj/**,**/bin/**,**/AssemblyInfo.cs,**/GlobalSuppressions.cs,**/*.xaml,**/Assets/**,**/Localization/Languages/**,CopyPaste.Launcher/**"
/d:sonar.coverage.exclusions="**/AssemblyInfo.cs,**/GlobalSuppressions.cs,**/App.xaml.cs,**/*Window.xaml.cs,**/*Window.cs,**/*Panel.cs,**/Win32WindowHelper.cs,**/HotkeyHelper.cs,**/ClipboardFilterChipsHelper.cs,**/WindowsClipboardListener.cs,**/ClipboardHelper.cs,**/CopyPasteEngine.cs,**/FocusHelper.cs,**/WindowsThumbnailExtractor.cs"

- name: Restore dependencies
run: dotnet restore -p:Platform=x64

- name: Build Solution
run: dotnet build CopyPaste.slnx -c Debug -p:Platform=x64 --no-restore
run: dotnet build CopyPaste.slnx -c Debug -p:Platform=x64 -p:DeterministicSourcePaths=false --no-restore

- name: Run Tests with Coverage
run: >
dotnet test CopyPaste.slnx -c Debug -p:Platform=x64 --no-build
--collect:"XPlat Code Coverage"
--results-directory coverage
--settings coverage.runsettings
run: |
dotnet test Tests/CopyPaste.Core.Tests/ -c Debug -p:Platform=x64 --no-build `
--collect:"XPlat Code Coverage" --results-directory coverage/core `
--settings coverage.core.runsettings
dotnet test Tests/CopyPaste.Listener.Tests/ -c Debug -p:Platform=x64 --no-build `
--collect:"XPlat Code Coverage" --results-directory coverage/listener `
--settings coverage.listener.runsettings
dotnet test Tests/CopyPaste.UI.Tests/ -c Debug -p:Platform=x64 --no-build `
--collect:"XPlat Code Coverage" --results-directory coverage/ui `
--settings coverage.ui.runsettings

- name: SonarScanner End
env:
Expand Down
2 changes: 2 additions & 0 deletions CopyPaste.Core/ClipboardHelper.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;
using Windows.Storage.Streams;

namespace CopyPaste.Core;

[ExcludeFromCodeCoverage(Justification = "Requires Windows Clipboard runtime (WinRT) — not unit testable")]
public static class ClipboardHelper
{
public static bool SetClipboardContent(ClipboardItem item, bool plainText = false)
Expand Down Expand Up @@ -32,7 +34,7 @@
}
}

private static bool SetText(string content, string? metadata, bool plainText)

Check warning on line 37 in CopyPaste.Core/ClipboardHelper.cs

View workflow job for this annotation

GitHub Actions / SonarCloud

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
if (string.IsNullOrEmpty(content))
return false;
Expand Down Expand Up @@ -72,7 +74,7 @@
}
}
catch (JsonException)
{

Check warning on line 77 in CopyPaste.Core/ClipboardHelper.cs

View workflow job for this annotation

GitHub Actions / SonarCloud

Either remove or fill this block of code. (https://rules.sonarsource.com/csharp/RSPEC-108)
}
}

Expand Down
3 changes: 3 additions & 0 deletions CopyPaste.Core/CopyPasteEngine.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System.Diagnostics.CodeAnalysis;

namespace CopyPaste.Core;

[ExcludeFromCodeCoverage(Justification = "Orchestrates Win32 clipboard listener — requires running system")]
public sealed class CopyPasteEngine : IDisposable
{
private readonly SqliteRepository _repository;
Expand Down Expand Up @@ -61,7 +64,7 @@
_repository.Dispose();
}
catch (ObjectDisposedException)
{

Check warning on line 67 in CopyPaste.Core/CopyPasteEngine.cs

View workflow job for this annotation

GitHub Actions / SonarCloud

Either remove or fill this block of code. (https://rules.sonarsource.com/csharp/RSPEC-108)
}

_isDisposed = true;
Expand Down
4 changes: 3 additions & 1 deletion CopyPaste.Core/FocusHelper.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;

namespace CopyPaste.Core;

[System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA5392:Use DefaultDllImportSearchPaths attribute for P/Invokes",
[SuppressMessage("Security", "CA5392:Use DefaultDllImportSearchPaths attribute for P/Invokes",
Justification = "P/Invokes target well-known system DLLs (user32.dll, kernel32.dll)")]
[ExcludeFromCodeCoverage(Justification = "Win32 P/Invoke (user32.dll SendInput/SetForegroundWindow) — not unit testable")]
public static partial class FocusHelper
{
#region P/Invoke Declarations
Expand Down
2 changes: 2 additions & 0 deletions CopyPaste.Core/WindowsThumbnailExtractor.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
using System.Diagnostics.CodeAnalysis;
using SkiaSharp;
using System.Runtime.InteropServices;

namespace CopyPaste.Core;

[ExcludeFromCodeCoverage(Justification = "Windows Shell IShellItemImageFactory P/Invoke — not unit testable")]
public static partial class WindowsThumbnailExtractor
{
private static readonly Guid _iShellItemImageFactoryGuid = new("bcc18b79-ba16-442f-80c4-8a59c30c463b");

[Flags]
private enum SIIGBF : uint

Check warning on line 13 in CopyPaste.Core/WindowsThumbnailExtractor.cs

View workflow job for this annotation

GitHub Actions / SonarCloud

Rename the enumeration 'SIIGBF' to match the regular expression: '^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$'. (https://rules.sonarsource.com/csharp/RSPEC-2342)
{
ResizeToFit = 0x00000000,

Check warning on line 15 in CopyPaste.Core/WindowsThumbnailExtractor.cs

View workflow job for this annotation

GitHub Actions / SonarCloud

Rename 'ResizeToFit' to 'None'. (https://rules.sonarsource.com/csharp/RSPEC-2346)
BiggerSizeOk = 0x00000001,
MemoryOnly = 0x00000002,
IconOnly = 0x00000004,
Expand All @@ -32,7 +34,7 @@
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool DeleteObject(IntPtr hObject);

public static byte[]? GetThumbnail(string filePath, int width = 300)

Check warning on line 37 in CopyPaste.Core/WindowsThumbnailExtractor.cs

View workflow job for this annotation

GitHub Actions / SonarCloud

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
if (string.IsNullOrWhiteSpace(filePath)) return null;
if (!File.Exists(filePath)) return null;
Expand Down Expand Up @@ -202,14 +204,14 @@
}

[StructLayout(LayoutKind.Sequential)]
private struct SIZE

Check warning on line 207 in CopyPaste.Core/WindowsThumbnailExtractor.cs

View workflow job for this annotation

GitHub Actions / SonarCloud

Rename struct 'SIZE' to match pascal case naming rules, consider using 'Size'. (https://rules.sonarsource.com/csharp/RSPEC-101)
{
public int cx;
public int cy;
}

[StructLayout(LayoutKind.Sequential)]
private struct BITMAP

Check warning on line 214 in CopyPaste.Core/WindowsThumbnailExtractor.cs

View workflow job for this annotation

GitHub Actions / SonarCloud

Rename struct 'BITMAP' to match pascal case naming rules, consider using 'Bitmap'. (https://rules.sonarsource.com/csharp/RSPEC-101)
{
public int bmType;
public int bmWidth;
Expand All @@ -221,7 +223,7 @@
}

[StructLayout(LayoutKind.Sequential)]
private struct BITMAPINFOHEADER

Check warning on line 226 in CopyPaste.Core/WindowsThumbnailExtractor.cs

View workflow job for this annotation

GitHub Actions / SonarCloud

Rename struct 'BITMAPINFOHEADER' to match pascal case naming rules, consider using 'Bitmapinfoheader'. (https://rules.sonarsource.com/csharp/RSPEC-101)
{
public uint biSize;
public int biWidth;
Expand All @@ -237,7 +239,7 @@
}

[StructLayout(LayoutKind.Sequential)]
private struct BITMAPINFO

Check warning on line 242 in CopyPaste.Core/WindowsThumbnailExtractor.cs

View workflow job for this annotation

GitHub Actions / SonarCloud

Rename struct 'BITMAPINFO' to match pascal case naming rules, consider using 'Bitmapinfo'. (https://rules.sonarsource.com/csharp/RSPEC-101)
{
public BITMAPINFOHEADER bmiHeader;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
Expand Down
2 changes: 2 additions & 0 deletions CopyPaste.Listener/WindowsClipboardListener.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using CopyPaste.Core;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Threading.Channels;

namespace CopyPaste.Listener;

[ExcludeFromCodeCoverage(Justification = "Win32 message loop and Windows clipboard API — requires running Windows message pump")]
public sealed partial class WindowsClipboardListener(IClipboardService service) : IClipboardListener
{
private const uint _cF_UNICODETEXT = 13;
Expand Down
2 changes: 2 additions & 0 deletions CopyPaste.UI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
using Microsoft.UI.Xaml;
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Threading;

namespace CopyPaste.UI;

[ExcludeFromCodeCoverage(Justification = "WinUI3 Application entry point with Win32 lifecycle — not unit testable")]
public sealed partial class App : Application, IDisposable
{
private const string _launcherReadyEventName = "CopyPaste_AppReady";
Expand Down
139 changes: 139 additions & 0 deletions CopyPaste.UI/Helpers/ClipboardFilterChipsHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
using CopyPaste.Core;
using CopyPaste.UI.Themes;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Shapes;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Windows.UI;

namespace CopyPaste.UI.Helpers;

[ExcludeFromCodeCoverage(Justification = "Manipulates WinUI3 UI controls directly — requires WinUI3 runtime")]
internal static class ClipboardFilterChipsHelper
{
internal static void SyncFilterChipsState(ClipboardThemeViewModelBase vm, FrameworkElement root)
{
SetChecked(root, "ColorCheckRed", vm.IsColorSelected(CardColor.Red));
SetChecked(root, "ColorCheckGreen", vm.IsColorSelected(CardColor.Green));
SetChecked(root, "ColorCheckPurple", vm.IsColorSelected(CardColor.Purple));
SetChecked(root, "ColorCheckYellow", vm.IsColorSelected(CardColor.Yellow));
SetChecked(root, "ColorCheckBlue", vm.IsColorSelected(CardColor.Blue));
SetChecked(root, "ColorCheckOrange", vm.IsColorSelected(CardColor.Orange));

SetChecked(root, "TypeCheckText", vm.IsTypeSelected(ClipboardContentType.Text));
SetChecked(root, "TypeCheckImage", vm.IsTypeSelected(ClipboardContentType.Image));
SetChecked(root, "TypeCheckFile", vm.IsTypeSelected(ClipboardContentType.File));
SetChecked(root, "TypeCheckFolder", vm.IsTypeSelected(ClipboardContentType.Folder));
SetChecked(root, "TypeCheckLink", vm.IsTypeSelected(ClipboardContentType.Link));
SetChecked(root, "TypeCheckAudio", vm.IsTypeSelected(ClipboardContentType.Audio));
SetChecked(root, "TypeCheckVideo", vm.IsTypeSelected(ClipboardContentType.Video));

SetChecked(root, "FilterModeContent", vm.ActiveFilterMode == 0);
SetChecked(root, "FilterModeCategory", vm.ActiveFilterMode == 1);
SetChecked(root, "FilterModeType", vm.ActiveFilterMode == 2);

UpdateSelectedColorsDisplay(vm, root);
UpdateSelectedTypesDisplay(vm, root);
}

internal static void UpdateSelectedColorsDisplay(ClipboardThemeViewModelBase vm, FrameworkElement root)
{
if (root.FindName("SelectedColorsPanel") is not Panel panel) return;
if (root.FindName("ColorPlaceholder") is not UIElement placeholder) return;

while (panel.Children.Count > 1)
panel.Children.RemoveAt(1);

var selectedColors = new List<(CardColor color, string hex)>();
if (vm.IsColorSelected(CardColor.Red)) selectedColors.Add((CardColor.Red, "#E74C3C"));
if (vm.IsColorSelected(CardColor.Green)) selectedColors.Add((CardColor.Green, "#2ECC71"));
if (vm.IsColorSelected(CardColor.Purple)) selectedColors.Add((CardColor.Purple, "#9B59B6"));
if (vm.IsColorSelected(CardColor.Yellow)) selectedColors.Add((CardColor.Yellow, "#F1C40F"));
if (vm.IsColorSelected(CardColor.Blue)) selectedColors.Add((CardColor.Blue, "#3498DB"));
if (vm.IsColorSelected(CardColor.Orange)) selectedColors.Add((CardColor.Orange, "#E67E22"));

if (selectedColors.Count == 0)
{
placeholder.Visibility = Visibility.Visible;
}
else
{
placeholder.Visibility = Visibility.Collapsed;
foreach (var (_, hex) in selectedColors)
{
var chip = new Ellipse
{
Width = 16,
Height = 16,
Fill = new SolidColorBrush(ClipboardWindowHelpers.ParseColor(hex)),
Stroke = new SolidColorBrush(Color.FromArgb(40, 0, 0, 0)),
StrokeThickness = 1,
Margin = new Thickness(0, 0, 2, 0)
};
panel.Children.Add(chip);
}
}
}

internal static void UpdateSelectedTypesDisplay(ClipboardThemeViewModelBase vm, FrameworkElement root)
{
if (root.FindName("SelectedTypesPanel") is not Panel panel) return;
if (root.FindName("TypePlaceholder") is not UIElement placeholder) return;

while (panel.Children.Count > 1)
panel.Children.RemoveAt(1);

var selectedTypes = new List<(ClipboardContentType type, string glyph)>();
if (vm.IsTypeSelected(ClipboardContentType.Text)) selectedTypes.Add((ClipboardContentType.Text, "\uE8C1"));
if (vm.IsTypeSelected(ClipboardContentType.Image)) selectedTypes.Add((ClipboardContentType.Image, "\uE91B"));
if (vm.IsTypeSelected(ClipboardContentType.File)) selectedTypes.Add((ClipboardContentType.File, "\uE7C3"));
if (vm.IsTypeSelected(ClipboardContentType.Folder)) selectedTypes.Add((ClipboardContentType.Folder, "\uE8B7"));
if (vm.IsTypeSelected(ClipboardContentType.Link)) selectedTypes.Add((ClipboardContentType.Link, "\uE71B"));
if (vm.IsTypeSelected(ClipboardContentType.Audio)) selectedTypes.Add((ClipboardContentType.Audio, "\uE8D6"));
if (vm.IsTypeSelected(ClipboardContentType.Video)) selectedTypes.Add((ClipboardContentType.Video, "\uE714"));

if (selectedTypes.Count == 0)
{
placeholder.Visibility = Visibility.Visible;
}
else
{
placeholder.Visibility = Visibility.Collapsed;
var maxToShow = 5;
var shown = 0;
foreach (var (_, glyph) in selectedTypes)
{
if (shown >= maxToShow)
{
var moreText = new TextBlock
{
Text = $"+{selectedTypes.Count - maxToShow}",
FontSize = 10,
Opacity = 0.6,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(4, 0, 0, 0)
};
panel.Children.Add(moreText);
break;
}
var chipBorder = new Border
{
Background = new SolidColorBrush(Color.FromArgb(30, 128, 128, 128)),
CornerRadius = new CornerRadius(4),
Padding = new Thickness(6, 3, 6, 3),
Child = new FontIcon { Glyph = glyph, FontSize = 12 }
};
panel.Children.Add(chipBorder);
shown++;
}
}
}

private static void SetChecked(FrameworkElement root, string name, bool value)
{
if (root.FindName(name) is CheckBox cb) cb.IsChecked = value;
else if (root.FindName(name) is RadioMenuFlyoutItem item) item.IsChecked = value;
}
}
Loading
Loading