Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New API for Record Key of Results & Fix Result Clone Issue #3194

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions Flow.Launcher.Plugin/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ public Result Clone()
TitleHighlightData = TitleHighlightData,
OriginQuery = OriginQuery,
PluginDirectory = PluginDirectory,
ContextData = ContextData,
PluginID = PluginID,
TitleToolTip = TitleToolTip,
SubTitleToolTip = SubTitleToolTip,
PreviewPanel = PreviewPanel,
ProgressBar = ProgressBar,
ProgressBarColor = ProgressBarColor,
Preview = Preview,
AddSelectedCount = AddSelectedCount,
RecordKey = RecordKey
};
}

Expand Down Expand Up @@ -252,6 +262,13 @@ public ValueTask<bool> ExecuteAsync(ActionContext context)
/// </summary>
public const int MaxScore = int.MaxValue;

/// <summary>
/// The key to identify the record. This is used when FL checks whether the result is the topmost record. Or FL calculates the hashcode of the result for user selected records.
/// This can be useful when your plugin will change the Title or SubTitle of the result dynamically.
/// If the plugin does not specific this, FL just uses Title and SubTitle to identify this result.
/// </summary>
public string RecordKey { get; set; } = string.Empty;

/// <summary>
/// Info of the preview section of a <see cref="Result"/>
/// </summary>
Expand Down
18 changes: 14 additions & 4 deletions Flow.Launcher/Storage/TopMostRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ internal void AddOrUpdate(Result result)
{
PluginID = result.PluginID,
Title = result.Title,
SubTitle = result.SubTitle
SubTitle = result.SubTitle,
RecordKey = result.RecordKey
};
records.AddOrUpdate(result.OriginQuery.RawQuery, record, (key, oldValue) => record);
}
Expand All @@ -49,12 +50,21 @@ public class Record
public string Title { get; set; }
public string SubTitle { get; set; }
public string PluginID { get; set; }
public string RecordKey { get; set; }

public bool Equals(Result r)
{
return Title == r.Title
&& SubTitle == r.SubTitle
&& PluginID == r.PluginID;
if (string.IsNullOrEmpty(RecordKey) || string.IsNullOrEmpty(r.RecordKey))
{
return Title == r.Title
&& SubTitle == r.SubTitle
&& PluginID == r.PluginID;
}
else
{
return RecordKey == r.RecordKey
&& PluginID == r.PluginID;
}
}
}
}
24 changes: 19 additions & 5 deletions Flow.Launcher/Storage/UserSelectedRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class UserSelectedRecord
[JsonInclude, JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public Dictionary<string, int> records { get; private set; }


public UserSelectedRecord()
{
recordsWithQuery = new Dictionary<int, int>();
Expand Down Expand Up @@ -45,8 +44,15 @@ private static int GenerateStaticHashCode(string s, int start = HASH_INITIAL)

private static int GenerateResultHashCode(Result result)
{
int hashcode = GenerateStaticHashCode(result.Title);
return GenerateStaticHashCode(result.SubTitle, hashcode);
if (string.IsNullOrEmpty(result.RecordKey))
{
int hashcode = GenerateStaticHashCode(result.Title);
return GenerateStaticHashCode(result.SubTitle, hashcode);
}
else
{
return GenerateStaticHashCode(result.RecordKey);
}
}

private static int GenerateQueryAndResultHashCode(Query query, Result result)
Expand All @@ -58,8 +64,16 @@ private static int GenerateQueryAndResultHashCode(Query query, Result result)

int hashcode = GenerateStaticHashCode(query.ActionKeyword);
hashcode = GenerateStaticHashCode(query.Search, hashcode);
hashcode = GenerateStaticHashCode(result.Title, hashcode);
hashcode = GenerateStaticHashCode(result.SubTitle, hashcode);

if (string.IsNullOrEmpty(result.RecordKey))
{
hashcode = GenerateStaticHashCode(result.Title, hashcode);
hashcode = GenerateStaticHashCode(result.SubTitle, hashcode);
}
else
{
hashcode = GenerateStaticHashCode(result.RecordKey, hashcode);
}

return hashcode;
}
Expand Down
Loading