@@ -22,7 +22,7 @@ namespace SmartImage.Lib.Engines.Impl.Search;
2222/// <see cref="SearchEngineOptions.EHentai" />
2323/// </summary>
2424/// <remarks>Handles both ExHentai and E-Hentai</remarks>
25- public sealed class EHentaiEngine : WebSearchEngine , ISearchConfigReceiver , ICookiesReceiver , INotifyPropertyChanged
25+ public sealed class EHentaiEngine : WebSearchEngine , INotifyPropertyChanged , ICookiesEngine , ISearchConfigReceiver
2626{
2727
2828 static EHentaiEngine ( ) { }
@@ -167,11 +167,23 @@ protected override ValueTask<INode[]> GetNodes(IDocument d)
167167 */
168168
169169
170- public async ValueTask < bool > ApplyCookiesAsync ( ICookiesProvider provider , CancellationToken ct = default )
170+ public async ValueTask < bool > ApplyCookiesAsync ( CancellationToken ct = default )
171171 {
172- Trace . WriteLine ( $ "Applying cookies to { Name } ") ;
172+ if ( Provider == null ) {
173+ return false ;
174+ }
175+
176+ if ( IsLoggedIn ) {
177+ Trace . WriteLine ( $ "Not applying cookies to { Name } ; already logged in") ;
178+ return IsLoggedIn ;
179+
180+ }
181+ else {
182+ Trace . WriteLine ( $ "Applying cookies to { Name } ") ;
183+ }
184+
173185
174- var cookies = await provider . LoadCookiesAsync ( ct ) ;
186+ var cookies = await Provider . GetOrLoadCookiesAsync ( ct ) ;
175187
176188 foreach ( var bck in cookies ) {
177189 var cookie = bck . AsCookie ( ) ;
@@ -193,7 +205,6 @@ public async ValueTask<bool> ApplyCookiesAsync(ICookiesProvider provider, Cancel
193205 var response = await GetSessionAsync ( ) ;
194206
195207 return IsLoggedIn = response . ResponseMessage . IsSuccessStatusCode ;
196-
197208 }
198209
199210 /*
@@ -206,7 +217,7 @@ public async ValueTask<bool> ApplyCookiesAsync(ICookiesProvider provider, Cancel
206217 * https://gitlab.com/NekoInverter/EhViewer/-/blob/master/app/src/main/java/com/hippo/ehviewer/client/EhCookieStore.java
207218 */
208219
209- public ValueTask ApplyConfigAsync ( SearchConfig cfg )
220+ public ValueTask < bool > ApplyConfigAsync ( SearchConfig cfg , CancellationToken ct = default )
210221 {
211222 /*if (this is { IsLoggedIn: true }/* && !(Username != cfg.EhUsername && Password != cfg.EhPassword)#1#) {
212223 Debug.WriteLine($"{Name} is already logged in", nameof(ApplyConfigAsync));
@@ -215,10 +226,13 @@ public ValueTask ApplyConfigAsync(SearchConfig cfg)
215226 }*/
216227 //
217228
229+ Provider = cfg . CookiesProvider ;
218230
219- return ValueTask . CompletedTask ;
231+ return ValueTask . FromResult ( true ) ;
220232 }
221233
234+ public ICookiesProvider Provider { get ; set ; }
235+
222236 #region
223237
224238 public static readonly Url EHentaiIndex = "https://forums.e-hentai.org/index.php" ;
0 commit comments