@@ -12,6 +12,11 @@ namespace Flow.Launcher.Plugin.OneNote.Icons
1212{
1313 public class IconProvider : BaseModel
1414 {
15+ private readonly PluginInitContext context ;
16+ private readonly Settings settings ;
17+ private readonly string imagesDirectory ;
18+ private readonly ConcurrentDictionary < string , ImageSource > iconCache = new ( ) ;
19+
1520 public const string Logo = IC . ImagesDirectory + IC . Logo + ".png" ;
1621 public string Sync => GetIconPath ( IC . Sync ) ;
1722 public string Search => GetIconPath ( IC . Search ) ;
@@ -23,17 +28,12 @@ public class IconProvider : BaseModel
2328 public string NewSectionGroup => GetIconPath ( IC . NewSectionGroup ) ;
2429 public string NewNotebook => GetIconPath ( IC . NewNotebook ) ;
2530 public string Warning => settings . IconTheme == IconTheme . Color
26- ? $ "{ IC . ImagesDirectory } { IC . Warning } .{ GetIconThemeString ( IconTheme . Dark ) } .png"
27- : GetIconPath ( IC . Warning ) ;
28-
29- private readonly Settings settings ;
30- private readonly ConcurrentDictionary < string , ImageSource > iconCache = new ( ) ;
31- private readonly string imagesDirectory ;
31+ ? $ "{ IC . ImagesDirectory } { IC . Warning } .{ GetIconThemeString ( IconTheme . Dark ) } .png"
32+ : GetIconPath ( IC . Warning ) ;
3233
33- public DirectoryInfo GeneratedImagesDirectoryInfo { get ; }
3434 public int CachedIconCount => iconCache . Keys . Count ( k => char . IsDigit ( k . Split ( '.' ) [ 1 ] [ 1 ] ) ) ;
35-
36- private readonly PluginInitContext context ;
35+ public DirectoryInfo GeneratedImagesDirectoryInfo { get ; }
36+
3737
3838 public IconProvider ( PluginInitContext context , Settings settings )
3939 {
@@ -60,7 +60,7 @@ private static string GetIconThemeString(IconTheme iconTheme)
6060 {
6161 iconTheme = FlowLauncherThemeToIconTheme ( ) ;
6262 }
63- return Enum . GetName ( iconTheme ) . ToLower ( ) ;
63+ return iconTheme . ToString ( ) . ToLower ( ) ;
6464 }
6565
6666 private static IconTheme FlowLauncherThemeToIconTheme ( )
@@ -79,38 +79,38 @@ private static IconTheme FlowLauncherThemeToIconTheme()
7979
8080 public Result . IconDelegate GetIcon ( IconGeneratorInfo info )
8181 {
82- bool generate = ( string . CompareOrdinal ( info . Prefix , IC . Notebook ) == 0
83- || string . CompareOrdinal ( info . Prefix , IC . Section ) == 0 )
82+ bool generate = ( string . CompareOrdinal ( info . prefix , IC . Notebook ) == 0
83+ || string . CompareOrdinal ( info . prefix , IC . Section ) == 0 )
8484 && settings . CreateColoredIcons
85- && info . Color . HasValue ;
85+ && info . color . HasValue ;
8686
8787 return generate ? GetIconGenerated : GetIconStatic ;
8888
8989 ImageSource GetIconGenerated ( )
9090 {
91- var imageSource = iconCache . GetOrAdd ( $ "{ info . Prefix } .{ info . Color ! . Value . ToArgb ( ) } .png", ImageSourceFactory , info . Color . Value ) ;
91+ var imageSource = iconCache . GetOrAdd ( $ "{ info . prefix } .{ info . color ! . Value . ToArgb ( ) } .png",
92+ static ( key , t ) => ImageSourceFactory ( t . self , key , t . Color ) ,
93+ ( Color : info . color . Value , self : this ) ) ;
9294 OnPropertyChanged ( nameof ( CachedIconCount ) ) ;
9395 return imageSource ;
9496 }
9597
9698 ImageSource GetIconStatic ( )
9799 {
98- return iconCache . GetOrAdd ( $ "{ info . Prefix } .{ GetIconThemeString ( settings . IconTheme ) } .png", key =>
99- {
100- var path = Path . Combine ( imagesDirectory , key ) ;
101- return BitmapImageFromPath ( path ) ;
102- } ) ;
100+ return iconCache . GetOrAdd ( $ "{ info . prefix } .{ GetIconThemeString ( settings . IconTheme ) } .png",
101+ static ( key , dir ) => BitmapImageFromPath ( Path . Combine ( dir , key ) ) ,
102+ imagesDirectory ) ;
103103 }
104104 }
105105
106- private ImageSource ImageSourceFactory ( string key , Color color )
106+ private static ImageSource ImageSourceFactory ( IconProvider self , string key , Color color )
107107 {
108108 var prefix = key . Split ( '.' ) [ 0 ] ;
109- var path = Path . Combine ( imagesDirectory , $ "{ prefix } .dark.png") ;
109+ var path = Path . Combine ( self . imagesDirectory , $ "{ prefix } .dark.png") ;
110110 var bitmap = BitmapImageFromPath ( path ) ;
111111 var newBitmap = ChangeIconColor ( bitmap , color ) ;
112112
113- path = $ "{ GeneratedImagesDirectoryInfo . FullName } { key } ";
113+ path = $ "{ self . GeneratedImagesDirectoryInfo . FullName } { key } ";
114114
115115 using var fileStream = new FileStream ( path , FileMode . Create ) ;
116116 var encoder = new PngBitmapEncoder ( ) ;
0 commit comments