Skip to content

Commit 86501e7

Browse files
committed
Fix UI context menu auto-search
1 parent 8bd4dda commit 86501e7

File tree

13 files changed

+59
-39
lines changed

13 files changed

+59
-39
lines changed

SmartImage.Lib/Engines/Impl/Search/RepostSleuthEngine.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ public override async Task<SearchResult> GetResultAsync(SearchQuery query, Cance
8787
sr.Results.Add(rpm.Convert(sr));
8888
}
8989

90+
if (sr.HasResults) {
91+
sr.Status = SearchResultStatus.Success;
92+
}
9093
ret:
9194
sr.Update();
9295
return sr;

SmartImage.Lib/Engines/Impl/Search/SauceNaoEngine.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Kantan.Monad;
1414
using Kantan.Net.Utilities;
1515
using Kantan.Text;
16+
using Microsoft.Extensions.Logging;
1617
using SmartImage.Lib.Results;
1718
using SmartImage.Lib.Results.Data;
1819
using static Kantan.Diagnostics.LogCategories;
@@ -86,7 +87,7 @@ public override async Task<SearchResult> GetResultAsync(SearchQuery query, Cance
8687
return result;
8788
}
8889

89-
if (!result.Results.Any()) {
90+
if (!result.HasResults) {
9091
result.ErrorMessage = "Daily search limit (50) exceeded";
9192
result.Status = SearchResultStatus.Cooldown;
9293

@@ -170,7 +171,10 @@ private async ValueTask GetWebResultsAsync(SearchQuery query, SearchResult sr)
170171
*/
171172

172173
if (response.StatusCode == (int) HttpStatusCode.TooManyRequests) {
173-
Trace.WriteLine("On cooldown!", Name);
174+
Logger.LogTrace("{Name} on cooldown", Name);
175+
sr.Status = SearchResultStatus.Cooldown;
176+
sr.ErrorMessage = "On cooldown!";
177+
sr.Flags = SearchResultFlags.NoResults;
174178
goto ret;
175179
}
176180

SmartImage.Lib/SmartImage.Lib.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<PackageReference Include="System.Reactive" Version="6.0.1" />
7272
<PackageReference Include="System.Runtime.Caching" Version="9.0.3" />
7373
<PackageReference Include="System.Text.Json" Version="9.0.3" />
74-
<PackageReference Include="Verify.Flurl" Version="1.0.0" />
74+
<PackageReference Include="Verify.Flurl" Version="1.0.1" />
7575
</ItemGroup>
7676

7777
<ItemGroup>

SmartImage.Lib/Utilities/Integration/WindowsOSIntegration.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Diagnostics;
55
using System.Runtime.InteropServices;
66
using System.Runtime.Versioning;
7+
using JetBrains.Annotations;
78
using Microsoft.Win32;
89
using Novus.OS;
910
using Novus.Win32;
@@ -16,9 +17,10 @@ namespace SmartImage.Lib.Utilities.Integration;
1617
[SupportedOSPlatform(OS_WIN)]
1718
public sealed class WindowsOSIntegration : BaseOSIntegration
1819
{
19-
20+
[NN]
2021
public override string ChromePath => Path.Combine(ProgramFilesPath, @"Google\Chrome\Application\chrome.exe");
2122

23+
[NN]
2224
public override string FirefoxPath => Path.Combine(AppDataPath, @"Mozilla");
2325

2426
public override string LaunchArgs { get; } = R1.Reg_Launch_Args;

SmartImage.Lib/Utilities/SearchUtil.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ namespace SmartImage.Lib.Utilities;
1111
public static class SearchUtil
1212
{
1313

14+
/*public static bool IsSuccessful(this SearchResultStatus s)
15+
=> s is SearchResultStatus.Success || (!s.IsError() && !s.IsUnknown());*/
16+
1417
public static bool IsSuccessful(this SearchResultStatus s)
15-
=> s is SearchResultStatus.Success || (!s.IsError() && !s.IsUnknown());
18+
=> s is SearchResultStatus.Success;
1619

1720
public static bool IsUnknown(this SearchResultStatus s)
1821
=> s is SearchResultStatus.None;
@@ -26,4 +29,5 @@ public static bool IsError(this SearchResultStatus s)
2629

2730
public static bool HasFlagFast(this SearchResultFlags value, SearchResultFlags status)
2831
=> (value & status) != 0;
32+
2933
}

SmartImage.Rdx/SmartImage.Rdx.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,18 @@
6767
<PackageReference Include="Microsoft.VisualStudio.Validation" Version="17.8.8" />
6868
<PackageReference Include="Microsoft.Win32.Primitives" Version="4.3.0" />
6969
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.7" />
70-
<PackageReference Include="Spectre.Console" Version="0.49.1" />
70+
<PackageReference Include="Spectre.Console" Version="0.50.0" />
7171
<PackageReference Include="Spectre.Console.Analyzer" Version="1.0.0">
7272
<PrivateAssets>all</PrivateAssets>
7373
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
7474
</PackageReference>
75-
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" />
76-
<PackageReference Include="Spectre.Console.ImageSharp" Version="0.49.1" />
75+
<PackageReference Include="Spectre.Console.Cli" Version="0.50.0" />
76+
<PackageReference Include="Spectre.Console.ImageSharp" Version="0.50.0" />
7777
<PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.3" />
7878
<PackageReference Include="System.Net.Primitives" Version="4.3.1" />
7979
<PackageReference Include="System.Reactive" Version="6.0.1" />
8080
<PackageReference Include="System.Text.Json" Version="9.0.3" />
81-
<PackageReference Include="Verify.Flurl" Version="1.0.0" />
81+
<PackageReference Include="Verify.Flurl" Version="1.0.1" />
8282
</ItemGroup>
8383

8484
<ItemGroup>

SmartImage.UI/App.xaml.cs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using JetBrains.Annotations;
1111
using Novus.Utilities;
1212
using Novus.Win32;
13+
1314
#nullable disable
1415
namespace SmartImage.UI;
1516

@@ -49,9 +50,11 @@ private void Application_Startup(object sender, StartupEventArgs startupArgs)
4950
case "-mi":
5051
multipleInstances = true;
5152
break;
53+
5254
case "-nms":
5355
pipeServer = false;
5456
break;
57+
5558
default:
5659
break;
5760
}
@@ -66,6 +69,7 @@ private void Application_Startup(object sender, StartupEventArgs startupArgs)
6669

6770
// Release SingleInstance Mutex
6871
_singleMutex.ReleaseMutex();
72+
6973
if (pipeServer) {
7074
StartServer();
7175

@@ -107,24 +111,27 @@ private void StartServer()
107111
{
108112
PipeServer = new NamedPipeServerStream(IPC_PIPE_NAME, PipeDirection.In);
109113

110-
PipeThread = new Thread([DebuggerHidden]() =>
111-
{
112-
while (true) {
113-
PipeServer.WaitForConnection();
114-
var sr = new StreamReader(PipeServer);
115-
116-
while (!sr.EndOfStream) {
117-
var v = sr.ReadLine();
118-
OnPipeMessage?.Invoke(v);
119-
}
120-
121-
PipeServer.Disconnect();
122-
}
123-
})
114+
PipeThread = new Thread(Start)
124115
{
125116
IsBackground = true
126117
};
127118
PipeThread.Start();
128119
}
129120

121+
[DebuggerHidden]
122+
private void Start()
123+
{
124+
while (true) {
125+
PipeServer.WaitForConnection();
126+
var sr = new StreamReader(PipeServer);
127+
128+
while (!sr.EndOfStream) {
129+
var v = sr.ReadLine();
130+
OnPipeMessage?.Invoke(v);
131+
}
132+
133+
PipeServer.Disconnect();
134+
}
135+
}
136+
130137
}

SmartImage.UI/MainWindow.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public SearchQuery? Query
243243
public bool UseContextMenu
244244
{
245245
get => BaseOSIntegration.Integration.IsContextMenuAdded;
246-
set => BaseOSIntegration.Integration.HandleContextMenu(value, R2.Reg_Launch_Args);
246+
set => BaseOSIntegration.Integration.HandleContextMenu(value, R2.Reg_Launch_Args2);
247247
}
248248

249249
public bool InPath
@@ -776,7 +776,7 @@ private void OnComplete(object sender, SearchResult[] e)
776776
private void OnResult(object o, SearchResult result)
777777
{
778778
++m_cntResults;
779-
var cle = Client.Engines.Length;
779+
var cle = Client.Engines.Count;
780780

781781
Tb_Status.Text = $"{m_cntResults}/{cle} | {(DateTime.Now - SearchStart).TotalSeconds:F3} sec";
782782
Pb_Preview.Value = (m_cntResults / (double) cle) * 100;

SmartImage.UI/Model/QueryModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
namespace SmartImage.UI.Model;
3232

3333
#pragma warning disable CS8618
34-
public class QueryModel : INotifyPropertyChanged, IDisposable, IBitmapImageSource, INamed, IItemSize
34+
public class QueryModel : INotifyPropertyChanged, IBitmapImageSource, INamed, IDisposable
3535
{
3636

3737
//todo

SmartImage.UI/Model/ResultItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace SmartImage.UI.Model;
3939

4040
#pragma warning disable CS8618
4141

42-
public class ResultItem : INotifyPropertyChanged, IBitmapImageSource, INamed, IItemSize, IDisposable
42+
public class ResultItem : INotifyPropertyChanged, IBitmapImageSource, INamed, IDisposable
4343
{
4444

4545
private string m_previewText;

0 commit comments

Comments
 (0)