Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit 61ccfb9

Browse files
committed
fix: some app will add two times
1 parent b2d0ef3 commit 61ccfb9

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

src/ClipboardR.Core/Struct.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace ClipboardR.Core;
55

6-
public struct ClipboardData
6+
public struct ClipboardData : IEquatable<ClipboardData>
77
{
88
public object Data;
99
public string Text;
@@ -14,4 +14,16 @@ public struct ClipboardData
1414
public string PreviewImagePath;
1515
public SharpClipboard.ContentTypes Type;
1616
public int Score;
17+
18+
public bool Equals(ClipboardData b)
19+
{
20+
return GetHashCode() == b.GetHashCode();
21+
}
22+
23+
public override int GetHashCode()
24+
{
25+
var hashcode = (Text?.GetHashCode() ?? 0) ^ (DisplayTitle?.GetHashCode() ?? 0) ^ (Data?.GetHashCode() ?? 0) ^
26+
(SenderApp?.GetHashCode() ?? 0) ^ Type.GetHashCode();
27+
return hashcode;
28+
}
1729
}

src/ClipboardR/Main.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ public List<Result> Query(Query query)
6363
{
6464
var displayData = query.Search.Trim().Length == 0
6565
? _dataList
66-
: _dataList.Where(i => !string.IsNullOrEmpty(i.Text) && i.Text.ToLower().Contains(query.Search.Trim().ToLower()));
66+
: _dataList.Where(i =>
67+
!string.IsNullOrEmpty(i.Text) && i.Text.ToLower().Contains(query.Search.Trim().ToLower()));
6768

6869
var results = new List<Result>();
6970
results.AddRange(displayData.Select(o => new Result
7071
{
7172
Title = o.DisplayTitle,
72-
SubTitle = o.SenderApp,
73+
SubTitle = $"{o.Score}",
7374
// IcoPath = o.IconPath,
7475
Icon = () => o.Icon,
7576
CopyText = o.Text,
@@ -113,7 +114,7 @@ private void _OnClipboardChange(object? sender, SharpClipboard.ClipboardChangedE
113114
IconPath = _defaultIconPath,
114115
Icon = new BitmapImage(new Uri(_defaultIconPath, UriKind.RelativeOrAbsolute)),
115116
PreviewImagePath = _defaultIconPath,
116-
Score = CurrentScore++,
117+
Score = CurrentScore,
117118
};
118119
switch (e.ContentType)
119120
{
@@ -151,11 +152,13 @@ private void _OnClipboardChange(object? sender, SharpClipboard.ClipboardChangedE
151152
? clipboardData.Text[..MaxTitleLength].Trim() + "..."
152153
: clipboardData.Text;
153154

155+
// make sure no repeat
156+
if (_dataList.Any(node => node.Equals(clipboardData)))
157+
return;
154158
_dataList.AddFirst(clipboardData);
155159
if (_dataList.Count > MaxDataCount)
156-
{
157160
_dataList.RemoveLast();
158-
}
161+
CurrentScore++;
159162
}
160163

161164
private string? SaveImageCache(ClipboardData clipboardData)

src/ClipboardR/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Name": "ClipboardR",
55
"Description": "A Clipboard Plugin for FlowLauncher",
66
"Author": "Rainyl",
7-
"Version": "0.1.2",
7+
"Version": "0.1.3",
88
"Language": "csharp",
99
"Website": "https://github.com/rainyl/Flow.Launcher.Plugin.ClipboardR",
1010
"IcoPath": "Images/clipboard.png",

0 commit comments

Comments
 (0)