change getting last history item to get the same result if exists

This commit is contained in:
Jeremy 2025-10-19 21:46:02 +11:00
parent 10d3ba268d
commit 26ad473592

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
@ -44,11 +44,11 @@ namespace Flow.Launcher.Storage
LastOpenedHistoryItems.RemoveAt(0);
}
// If the last item is the same as the current result, just update the timestamp
if (LastOpenedHistoryItems.Count > 0 &&
LastOpenedHistoryItems.Last().Equals(result))
if (LastOpenedHistoryItems.Count > 0 &&
TryGetLastOpenedHistoryResult(result, out var existingHistoryItem))
{
LastOpenedHistoryItems.Last().ExecutedDateTime = DateTime.Now;
existingHistoryItem.IcoPath = result.IcoPath;
existingHistoryItem.ExecutedDateTime = DateTime.Now;
}
else
{
@ -65,5 +65,11 @@ namespace Flow.Launcher.Storage
});
}
}
private bool TryGetLastOpenedHistoryResult(Result result, out LastOpenedHistoryItem historyItem)
{
historyItem = LastOpenedHistoryItems.FirstOrDefault(x => x.Equals(result));
return historyItem is not null;
}
}
}