mirror of
https://github.com/rommapp/playnite-plugin.git
synced 2026-01-09 06:33:15 +08:00
template for search support
This commit is contained in:
parent
61c0b5f442
commit
7b13445c14
@ -7,7 +7,6 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using ProtoBuf;
|
||||
using Playnite.SDK;
|
||||
|
||||
namespace RomM.Games
|
||||
{
|
||||
@ -30,7 +29,7 @@ namespace RomM.Games
|
||||
{
|
||||
get
|
||||
{
|
||||
return Settings.SettingsViewModel.Instance.Mappings.FirstOrDefault(m => m.MappingId == MappingId);
|
||||
return SettingsViewModel.Instance.Mappings.FirstOrDefault(m => m.MappingId == MappingId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
3
RomM.cs
3
RomM.cs
@ -13,12 +13,10 @@ using System.Collections.Specialized;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RomM.Settings;
|
||||
using Playnite.SDK.Events;
|
||||
using RomM.Games;
|
||||
using System.Security;
|
||||
|
||||
|
||||
namespace RomM
|
||||
@ -78,6 +76,7 @@ namespace RomM
|
||||
base.OnApplicationStarted(args);
|
||||
Settings = new SettingsViewModel(this, this);
|
||||
HttpClientSingleton.ConfigureBasicAuth(Settings.RomMUsername, Settings.RomMPassword);
|
||||
this.Searches = new List<SearchSupport> { new SearchSupport("romm", "RomM", new RomMSearchContext()) };
|
||||
}
|
||||
|
||||
public static async Task<HttpResponseMessage> GetAsync(string baseUrl, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead)
|
||||
|
||||
56
Search/SearchContext.cs
Normal file
56
Search/SearchContext.cs
Normal file
@ -0,0 +1,56 @@
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Playnite.SDK.Plugins;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace RomM.Settings
|
||||
{
|
||||
public class RomMSearchContext : SearchContext
|
||||
{
|
||||
public RomMSearchContext()
|
||||
{
|
||||
Description = "Default search description";
|
||||
Label = "Default search";
|
||||
Hint = "Search hint goes here";
|
||||
}
|
||||
|
||||
public override IEnumerable<SearchItem> GetSearchResults(GetSearchResultsArgs args)
|
||||
{
|
||||
if (args.CancelToken.IsCancellationRequested)
|
||||
yield break;
|
||||
|
||||
// Use args.SearchTerm to access search query
|
||||
string url = $"{SettingsViewModel.Instance.RomMHost}/api/roms";
|
||||
NameValueCollection queryParams = new NameValueCollection
|
||||
{
|
||||
{ "size", "250" },
|
||||
{ "search_term", args.SearchTerm },
|
||||
{ "order_by", "name" },
|
||||
{ "order_dir", "asc" }
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
// Make the request and get the response
|
||||
HttpResponseMessage response = RomM.GetAsyncWithParams(url, queryParams).GetAwaiter().GetResult();
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
// Assuming the response is in JSON format
|
||||
string body = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
|
||||
JObject jsonObject = JObject.Parse(body);
|
||||
var items = jsonObject["items"].Children();
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user