7
7
using System . Threading . Tasks ;
8
8
using System . Windows . Media ;
9
9
using System . Windows . Media . Imaging ;
10
- using Flow . Launcher . Infrastructure . Logger ;
10
+ using CommunityToolkit . Mvvm . DependencyInjection ;
11
11
using Flow . Launcher . Infrastructure . Storage ;
12
+ using Flow . Launcher . Plugin ;
12
13
13
14
namespace Flow . Launcher . Infrastructure . Image
14
15
{
15
16
public static class ImageLoader
16
17
{
18
+ // We should not initialize API in static constructor because it will create another API instance
19
+ private static IPublicAPI api = null ;
20
+ private static IPublicAPI API => api ??= Ioc . Default . GetRequiredService < IPublicAPI > ( ) ;
21
+
22
+ private static readonly string ClassName = nameof ( ImageLoader ) ;
23
+
17
24
private static readonly ImageCache ImageCache = new ( ) ;
18
25
private static SemaphoreSlim storageLock { get ; } = new SemaphoreSlim ( 1 , 1 ) ;
19
26
private static BinaryStorage < List < ( string , bool ) > > _storage ;
@@ -47,15 +54,14 @@ public static async Task InitializeAsync()
47
54
48
55
_ = Task . Run ( async ( ) =>
49
56
{
50
- await Stopwatch . NormalAsync ( "|ImageLoader.Initialize| Preload images cost", async ( ) =>
57
+ await API . StopwatchLogInfoAsync ( ClassName , " Preload images cost", async ( ) =>
51
58
{
52
59
foreach ( var ( path , isFullImage ) in usage )
53
60
{
54
61
await LoadAsync ( path , isFullImage ) ;
55
62
}
56
63
} ) ;
57
- Log . Info (
58
- $ "|ImageLoader.Initialize|Number of preload images is <{ ImageCache . CacheSize ( ) } >, Images Number: { ImageCache . CacheSize ( ) } , Unique Items { ImageCache . UniqueImagesInCache ( ) } ") ;
64
+ API . LogInfo ( ClassName , $ "Number of preload images is <{ ImageCache . CacheSize ( ) } >, Images Number: { ImageCache . CacheSize ( ) } , Unique Items { ImageCache . UniqueImagesInCache ( ) } ") ;
59
65
} ) ;
60
66
}
61
67
@@ -71,7 +77,7 @@ await _storage.SaveAsync(ImageCache.EnumerateEntries()
71
77
}
72
78
catch ( System . Exception e )
73
79
{
74
- Log . Exception ( $ "|ImageLoader.SaveAsync| Failed to save image cache to file", e ) ;
80
+ API . LogException ( ClassName , " Failed to save image cache to file", e ) ;
75
81
}
76
82
finally
77
83
{
@@ -166,8 +172,8 @@ private static async ValueTask<ImageResult> LoadInternalAsync(string path, bool
166
172
}
167
173
catch ( System . Exception e2 )
168
174
{
169
- Log . Exception ( $ "|ImageLoader.Load|Failed to get thumbnail for { path } on first try", e ) ;
170
- Log . Exception ( $ "|ImageLoader.Load|Failed to get thumbnail for { path } on second try", e2 ) ;
175
+ API . LogException ( ClassName , $ "|ImageLoader.Load|Failed to get thumbnail for { path } on first try", e ) ;
176
+ API . LogException ( ClassName , $ "|ImageLoader.Load|Failed to get thumbnail for { path } on second try", e2 ) ;
171
177
172
178
ImageSource image = ImageCache [ Constant . MissingImgIcon , false ] ;
173
179
ImageCache [ path , false ] = image ;
0 commit comments