Skip to content

Commit 4c11b66

Browse files
committed
Work on cookies 2; fixes
1 parent 4db6056 commit 4c11b66

File tree

15 files changed

+43
-74
lines changed

15 files changed

+43
-74
lines changed

SmartImage.Lib/Engines/BaseSearchEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
using SmartImage.Lib.Engines.Impl.Search.Other;
2121
using SmartImage.Lib.Images;
2222
using SmartImage.Lib.Utilities;
23-
using SmartImage.Lib.Model;
23+
using SmartImage.Lib.Results.Data;
2424

2525
namespace SmartImage.Lib.Engines;
2626
#nullable enable

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ public async ValueTask<bool> ApplyCookiesAsync(ICookieProvider provider, Cancell
119119
return false;
120120
}*/
121121

122-
var cookies = await provider.LoadCookiesAsync(ct);
122+
var ok = await provider.LoadCookiesAsync(ct);
123+
var cookies = provider.Cookies;
123124

124125
var fcc = cookies.OfType<FirefoxCookie>().Where(x =>
125126
{

SmartImage.Lib/Engines/WebSearchEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using JetBrains.Annotations;
88
using Kantan.Diagnostics;
99
using Kantan.Net.Utilities;
10-
using SmartImage.Lib.Model;
10+
using SmartImage.Lib.Results.Data;
1111
using SmartImage.Lib.Results;
1212

1313
namespace SmartImage.Lib.Engines;

SmartImage.Lib/Utilities/CookiesManager.cs renamed to SmartImage.Lib/Results/Data/FirefoxCookiesProvider.cs

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
using System.Runtime.CompilerServices;
88
using Flurl.Http;
99
using Kantan.Net.Web;
10-
using SmartImage.Lib.Results.Data;
1110

12-
namespace SmartImage.Lib.Utilities;
11+
namespace SmartImage.Lib.Results.Data;
1312

1413
public class AsyncLazy<T> : Lazy<Task<T>>
1514
{
@@ -18,13 +17,13 @@ public AsyncLazy(Func<T> valueFactory, CancellationToken ct = default) :
1817
base(() => Task.Factory.StartNew(valueFactory, ct)) { }
1918

2019
public AsyncLazy(Func<Task<T>> taskFactory, CancellationToken ct = default) :
21-
base(() => Task.Factory.StartNew(() => taskFactory(), ct).Unwrap()) { }
20+
base(() => Task.Factory.StartNew(taskFactory, ct).Unwrap()) { }
2221

2322
public AsyncLazy(Func<object, T> valueFactory, CancellationToken ct = default)
24-
: base(() => Task.Factory.StartNew((z) => valueFactory(z), ct)) { }
23+
: base(() => Task.Factory.StartNew(valueFactory, ct)) { }
2524

2625
public AsyncLazy(Func<object, Task<T>> valueFactory, CancellationToken ct = default)
27-
: base(() => Task.Factory.StartNew((z) => valueFactory(z), ct).Unwrap()) { }
26+
: base(() => Task.Factory.StartNew(valueFactory, ct).Unwrap()) { }
2827

2928
/*public AsyncLazy(Func<object, Task<T>> valueFactory, CancellationToken ct = default)
3029
: base(() => Task.Factory.StartNew(z => valueFactory(z)), ct) { }*/
@@ -42,18 +41,18 @@ public class FirefoxCookiesProvider : ICookieProvider
4241
private readonly FirefoxCookieReader m_reader;
4342

4443

45-
public IEnumerable<IBrowserCookie> Cookies { get; }
44+
public IList<IBrowserCookie> Cookies { get; private set; }
4645

4746
public FirefoxCookiesProvider()
4847
{
4948
m_reader = new FirefoxCookieReader();
50-
Cookies = [];
49+
Cookies = null;
5150
}
5251

5352
public async ValueTask<bool> LoadCookiesAsync(CancellationToken ct = default)
5453
{
55-
if (((ICookieProvider) this).Loaded) {
56-
if (m_reader.Connection.State == ConnectionState.Open) {
54+
if (!((ICookieProvider) this).Loaded) {
55+
if (m_reader.Connection.State != ConnectionState.Open) {
5756
await m_reader.OpenAsync();
5857

5958
}
@@ -67,49 +66,13 @@ public async ValueTask<bool> LoadCookiesAsync(CancellationToken ct = default)
6766

6867
}
6968

70-
public void Dispose()
71-
{
72-
m_reader.Dispose();
73-
}
74-
75-
}
76-
77-
public class CookiesManager : IDisposable
78-
{
79-
80-
// TODO
81-
82-
// [DebuggerHidden]
83-
private static async Task<List<IBrowserCookie>> ReadCookiesAsync() { }
84-
85-
public List<IBrowserCookie> Cookies { get; private set; }
86-
87-
[MNNW(true, nameof(Cookies))]
88-
public bool Loaded => Cookies != null;
89-
90-
private CookiesManager()
91-
{
92-
Cookies = null;
93-
}
94-
95-
public async Task<bool> LoadCookiesAsync(bool force = false)
96-
{
97-
var b = !Loaded || force;
98-
99-
if (b) {
100-
Cookies = await ReadCookiesAsync();
101-
102-
}
103-
104-
return Loaded;
105-
}
106-
107-
public static readonly CookiesManager Instance = new();
108-
10969
public void Dispose()
11070
{
11171
Cookies.Clear();
11272
Cookies = null;
73+
m_reader.Dispose();
11374
}
11475

76+
public static readonly ICookieProvider Instance = new FirefoxCookiesProvider();
77+
11578
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Author: Deci | Project: SmartImage.Lib | Name: ICookieProvider.cs
2+
// Date: 2024/10/15 @ 12:10:00
3+
4+
using Kantan.Net.Web;
5+
6+
namespace SmartImage.Lib.Results.Data;
7+
8+
public interface ICookieProvider : IDisposable
9+
{
10+
11+
public IList<IBrowserCookie> Cookies { get; }
12+
13+
[MNNW(true, nameof(Cookies))]
14+
public bool Loaded => Cookies != null && Cookies.Count != 0;
15+
16+
public ValueTask<bool> LoadCookiesAsync(CancellationToken ct = default);
17+
18+
}
Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Author: Deci | Project: SmartImage.Lib | Name: ICookieReceiver.cs
22
// Date: 2024/06/06 @ 17:06:56
33

4-
using Kantan.Net.Web;
54
using SmartImage.Lib.Utilities;
65

76
namespace SmartImage.Lib.Results.Data;
@@ -11,16 +10,4 @@ public interface ICookieReceiver
1110

1211
public ValueTask<bool> ApplyCookiesAsync(ICookieProvider provider, CancellationToken ct = default);
1312

14-
}
15-
16-
public interface ICookieProvider : IDisposable
17-
{
18-
19-
public IEnumerable<IBrowserCookie> Cookies { get; }
20-
21-
[MNNW(true, nameof(Cookies))]
22-
public bool Loaded => Cookies != null;
23-
24-
public ValueTask<bool> LoadCookiesAsync(CancellationToken ct = default);
25-
2613
}

SmartImage.Lib/SearchClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public async ValueTask LoadEnginesAsync()
312312
Engines = BaseSearchEngine.GetSelectedEngines(Config.SearchEngines).ToArray();
313313

314314
if (Config.ReadCookies) {
315-
if (await CookiesManager.Instance.LoadCookiesAsync()) { }
315+
if (await FirefoxCookiesProvider.Instance.LoadCookiesAsync()) { }
316316
}
317317

318318
foreach (BaseSearchEngine bse in Engines) {
@@ -321,7 +321,7 @@ public async ValueTask LoadEnginesAsync()
321321
}
322322

323323
if (Config.ReadCookies && bse is ICookieReceiver ce) {
324-
await ce.ApplyCookiesAsync(CookiesManager.Instance.Cookies);
324+
await ce.ApplyCookiesAsync(FirefoxCookiesProvider.Instance);
325325

326326
// if (await CookiesManager.Instance.LoadCookiesAsync()) { }
327327
}

SmartImage.Lib/SearchQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
using SixLabors.ImageSharp.Processing;
1919
using SmartImage.Lib.Engines;
2020
using SmartImage.Lib.Engines.Impl.Upload;
21-
using SmartImage.Lib.Model;
21+
using SmartImage.Lib.Results.Data;
2222
using SmartImage.Lib.Results;
2323
using SmartImage.Lib.Utilities;
2424
using SixLabors.ImageSharp.Formats;

SmartImage.UI/Controls/Converters/BoolToValConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Text;
55
using System.Windows;
66
using System.Windows.Data;
7-
using SmartImage.Lib.Model;
7+
using SmartImage.Lib.Results.Data;
88

99
namespace SmartImage.UI.Controls.Converters;
1010

SmartImage.UI/Controls/Converters/ImageDimensionConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using System.Threading.Tasks;
99
using System.Windows.Controls;
1010
using System.Windows.Data;
11-
using SmartImage.Lib.Model;
11+
using SmartImage.Lib.Results.Data;
1212
using SmartImage.UI.Model;
1313

1414
namespace SmartImage.UI.Controls.Converters;

0 commit comments

Comments
 (0)