Skip to content

Commit 4e8272f

Browse files
committed
- Removed "Remove Cache" button
- Changed nuget for SVG - Changed SVG code
1 parent cb8b5f2 commit 4e8272f

File tree

4 files changed

+48
-92
lines changed

4 files changed

+48
-92
lines changed

Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ protected List<Bookmark> GetBookmarksFromPath(string placesPath)
8282
{
8383
LoadFaviconsFromDb(faviconDbPath, bookmarks);
8484
}
85-
8685
// https://github.com/dotnet/efcore/issues/26580
8786
SqliteConnection.ClearPool(dbConnection);
8887
dbConnection.Close();
@@ -168,14 +167,14 @@ ORDER BY i.width DESC -- Select largest icon available
168167
}
169168
else
170169
{
171-
// 변환 실패 시 빈 문자열 설정 (기본 아이콘 사용)
170+
// Set empty string on conversion failure (will use default icon)
172171
bookmark.FaviconPath = string.Empty;
173172
continue;
174173
}
175174
}
176175
else
177176
{
178-
// PNG는 그대로 저장
177+
// Save PNG directly
179178
SaveBitmapData(imageData, faviconPath);
180179
}
181180
}
@@ -208,37 +207,58 @@ ORDER BY i.width DESC -- Select largest icon available
208207
}
209208
}
210209

211-
private byte[] ConvertSvgToPng(byte[] svgData)
212-
{
213-
try
210+
private byte[] ConvertSvgToPng(byte[] svgData)
214211
{
215-
using var memoryStream = new MemoryStream();
216-
// 메모리에 SVG 데이터 로드
217-
using (var image = new ImageMagick.MagickImage(svgData))
212+
try
218213
{
219-
// 적절한 크기로 리사이징 (32x32가 일반적인 파비콘 크기)
220-
image.Resize(32, 32);
221-
// PNG 형식으로 변환하여 메모리 스트림에 저장
222-
image.Format = ImageMagick.MagickFormat.Png;
223-
image.Write(memoryStream);
224-
}
214+
// Create SKSvg object from SVG data
215+
using var stream = new MemoryStream(svgData);
216+
var svg = new SkiaSharp.Extended.Svg.SKSvg();
217+
svg.Load(stream);
218+
219+
// Set default values if SVG size is invalid or missing
220+
float width = svg.Picture.CullRect.Width > 0 ? svg.Picture.CullRect.Width : 32;
221+
float height = svg.Picture.CullRect.Height > 0 ? svg.Picture.CullRect.Height : 32;
225222

226-
return memoryStream.ToArray();
227-
}
228-
catch (Exception ex)
229-
{
230-
Log.Exception("SVG to PNG conversion failed", ex);
231-
return null;
223+
// Calculate scale for 32x32 favicon size
224+
float scaleX = 32 / width;
225+
float scaleY = 32 / height;
226+
float scale = Math.Min(scaleX, scaleY);
227+
228+
// Calculate final image dimensions (maintaining aspect ratio)
229+
int finalWidth = (int)(width * scale);
230+
int finalHeight = (int)(height * scale);
231+
232+
// Render to PNG
233+
using var surface = SkiaSharp.SKSurface.Create(new SkiaSharp.SKImageInfo(finalWidth, finalHeight));
234+
var canvas = surface.Canvas;
235+
236+
// Set transparent background
237+
canvas.Clear(SkiaSharp.SKColors.Transparent);
238+
239+
// Draw SVG (scaled to fit)
240+
canvas.Scale(scale);
241+
canvas.DrawPicture(svg.Picture);
242+
243+
// Extract image data
244+
using var image = surface.Snapshot();
245+
using var data = image.Encode(SkiaSharp.SKEncodedImageFormat.Png, 100);
246+
return data.ToArray();
247+
}
248+
catch (Exception ex)
249+
{
250+
Log.Exception("SVG to PNG conversion failed", ex);
251+
return null;
252+
}
232253
}
233-
}
234254

235255
private static bool IsSvgData(byte[] data)
236256
{
237257
if (data == null || data.Length < 5)
238258
return false;
239259

240-
// SVG 파일 시그니처 확인
241-
// ASCII로 시작하는 SVG XML 헤더 확인
260+
// Check SVG file signature
261+
// Verify SVG XML header starting with ASCII
242262
string header = System.Text.Encoding.ASCII.GetString(data, 0, Math.Min(data.Length, 200)).ToLower();
243263

244264
return header.Contains("<svg") ||

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@
9595
</ItemGroup>
9696

9797
<ItemGroup>
98-
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="14.5.0" />
9998
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.3" />
99+
<PackageReference Include="SkiaSharp" Version="3.116.1" />
100+
<PackageReference Include="SkiaSharp.Svg" Version="1.60.0" />
100101
</ItemGroup>
101102

102103
</Project>

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/SettingsControl.xaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
Margin="0,0,15,0"
3232
Click="Others_Click"
3333
Content="{DynamicResource flowlauncher_plugin_browserbookmark_others}" />
34-
<Button
35-
Margin="0,0,15,0"
36-
Click="RemoveFaviconCache_Click"
37-
Content="Remove Favicon Cache" />
3834
</StackPanel>
3935
<StackPanel Name="CustomBrowsersList" Visibility="Collapsed">
4036
<ListView

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/SettingsControl.xaml.cs

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@ namespace Flow.Launcher.Plugin.BrowserBookmark.Views;
1616
public partial class SettingsControl : INotifyPropertyChanged
1717
{
1818
public Settings Settings { get; }
19-
private readonly PluginInitContext _context;
19+
public CustomBrowser SelectedCustomBrowser { get; set; }
20+
2021
public SettingsControl(Settings settings)
2122
{
22-
// Settings 객체를 직접 받도록 수정
2323
Settings = settings;
2424
InitializeComponent();
25-
DataContext = this;
2625
}
27-
public CustomBrowser SelectedCustomBrowser { get; set; }
28-
2926
public bool LoadChromeBookmark
3027
{
3128
get => Settings.LoadChromeBookmark;
@@ -123,62 +120,4 @@ private void EditSelectedCustomBrowser()
123120
_ = Task.Run(() => Main.ReloadAllBookmarks());
124121
}
125122
}
126-
private void RemoveFaviconCache_Click(object sender, RoutedEventArgs e)
127-
{
128-
try
129-
{
130-
// 플러그인 디렉토리 경로 가져오기
131-
var pluginDir = Main.GetPluginDirectory();
132-
if (string.IsNullOrEmpty(pluginDir))
133-
{
134-
MessageBox.Show("플러그인 디렉토리를 찾을 수 없습니다.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
135-
return;
136-
}
137-
138-
// 파비콘 캐시 디렉토리 경로 지정
139-
string cacheDir = Path.Combine(pluginDir, "Images", "Favicons");
140-
141-
// 디렉토리 존재 확인 및 생성
142-
if (!Directory.Exists(cacheDir))
143-
{
144-
MessageBox.Show("파비콘 캐시 디렉토리가 존재하지 않습니다. 캐시가 비어있거나 아직 생성되지 않았을 수 있습니다.", "알림", MessageBoxButton.OK, MessageBoxImage.Information);
145-
return;
146-
}
147-
148-
// 파일 수 확인
149-
var files = Directory.GetFiles(cacheDir);
150-
if (files.Length == 0)
151-
{
152-
MessageBox.Show("파비콘 캐시가 이미 비어 있습니다.", "알림", MessageBoxButton.OK, MessageBoxImage.Information);
153-
return;
154-
}
155-
156-
// 디렉토리 내 모든 파일 삭제
157-
int deletedCount = 0;
158-
foreach (var file in files)
159-
{
160-
try
161-
{
162-
File.Delete(file);
163-
deletedCount++;
164-
}
165-
catch (Exception ex)
166-
{
167-
Flow.Launcher.Infrastructure.Logger.Log.Exception(
168-
$"Failed to delete favicon cache file: {file}", ex);
169-
}
170-
}
171-
172-
// 북마크 다시 로드
173-
Main.ReloadAllBookmarks();
174-
175-
// 완료 메시지 표시
176-
MessageBox.Show($"{deletedCount}개의 파비콘 캐시 파일이 삭제되었습니다.", "캐시 삭제 완료", MessageBoxButton.OK, MessageBoxImage.Information);
177-
}
178-
catch (Exception ex)
179-
{
180-
Flow.Launcher.Infrastructure.Logger.Log.Exception("Failed to remove favicon cache", ex);
181-
MessageBox.Show($"파비콘 캐시 삭제 중 오류가 발생했습니다: {ex.Message}", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
182-
}
183-
}
184123
}

0 commit comments

Comments
 (0)