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
using SharpVectors . Converters ;
13
14
using SharpVectors . Renderers . Wpf ;
14
15
15
16
namespace Flow . Launcher . Infrastructure . Image
16
17
{
17
18
public static class ImageLoader
18
19
{
20
+ // We should not initialize API in static constructor because it will create another API instance
21
+ private static IPublicAPI api = null ;
22
+ private static IPublicAPI API => api ??= Ioc . Default . GetRequiredService < IPublicAPI > ( ) ;
23
+
24
+ private static readonly string ClassName = nameof ( ImageLoader ) ;
25
+
19
26
private static readonly ImageCache ImageCache = new ( ) ;
20
27
private static SemaphoreSlim storageLock { get ; } = new SemaphoreSlim ( 1 , 1 ) ;
21
28
private static BinaryStorage < List < ( string , bool ) > > _storage ;
@@ -51,15 +58,14 @@ public static async Task InitializeAsync()
51
58
52
59
_ = Task . Run ( async ( ) =>
53
60
{
54
- await Stopwatch . NormalAsync ( "|ImageLoader.Initialize| Preload images cost", async ( ) =>
61
+ await API . StopwatchLogInfoAsync ( ClassName , " Preload images cost", async ( ) =>
55
62
{
56
63
foreach ( var ( path , isFullImage ) in usage )
57
64
{
58
65
await LoadAsync ( path , isFullImage ) ;
59
66
}
60
67
} ) ;
61
- Log . Info (
62
- $ "|ImageLoader.Initialize|Number of preload images is <{ ImageCache . CacheSize ( ) } >, Images Number: { ImageCache . CacheSize ( ) } , Unique Items { ImageCache . UniqueImagesInCache ( ) } ") ;
68
+ API . LogInfo ( ClassName , $ "Number of preload images is <{ ImageCache . CacheSize ( ) } >, Images Number: { ImageCache . CacheSize ( ) } , Unique Items { ImageCache . UniqueImagesInCache ( ) } ") ;
63
69
} ) ;
64
70
}
65
71
@@ -75,7 +81,7 @@ await _storage.SaveAsync(ImageCache.EnumerateEntries()
75
81
}
76
82
catch ( System . Exception e )
77
83
{
78
- Log . Exception ( $ "|ImageLoader.SaveAsync| Failed to save image cache to file", e ) ;
84
+ API . LogException ( ClassName , " Failed to save image cache to file", e ) ;
79
85
}
80
86
finally
81
87
{
@@ -170,8 +176,8 @@ private static async ValueTask<ImageResult> LoadInternalAsync(string path, bool
170
176
}
171
177
catch ( System . Exception e2 )
172
178
{
173
- Log . Exception ( $ "|ImageLoader.Load|Failed to get thumbnail for { path } on first try", e ) ;
174
- Log . Exception ( $ "|ImageLoader.Load|Failed to get thumbnail for { path } on second try", e2 ) ;
179
+ API . LogException ( ClassName , $ "|ImageLoader.Load|Failed to get thumbnail for { path } on first try", e ) ;
180
+ API . LogException ( ClassName , $ "|ImageLoader.Load|Failed to get thumbnail for { path } on second try", e2 ) ;
175
181
176
182
ImageSource image = ImageCache [ Constant . MissingImgIcon , false ] ;
177
183
ImageCache [ path , false ] = image ;
0 commit comments