mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
- Removed "Remove Cache" button
- Changed nuget for SVG - Changed SVG code
This commit is contained in:
parent
cb8b5f2b7d
commit
4e8272ffbc
4 changed files with 51 additions and 95 deletions
|
|
@ -82,7 +82,6 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
|
|||
{
|
||||
LoadFaviconsFromDb(faviconDbPath, bookmarks);
|
||||
}
|
||||
|
||||
// https://github.com/dotnet/efcore/issues/26580
|
||||
SqliteConnection.ClearPool(dbConnection);
|
||||
dbConnection.Close();
|
||||
|
|
@ -168,14 +167,14 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
|
|||
}
|
||||
else
|
||||
{
|
||||
// 변환 실패 시 빈 문자열 설정 (기본 아이콘 사용)
|
||||
// Set empty string on conversion failure (will use default icon)
|
||||
bookmark.FaviconPath = string.Empty;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// PNG는 그대로 저장
|
||||
// Save PNG directly
|
||||
SaveBitmapData(imageData, faviconPath);
|
||||
}
|
||||
}
|
||||
|
|
@ -208,37 +207,58 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
|
|||
}
|
||||
}
|
||||
|
||||
private byte[] ConvertSvgToPng(byte[] svgData)
|
||||
{
|
||||
try
|
||||
private byte[] ConvertSvgToPng(byte[] svgData)
|
||||
{
|
||||
using var memoryStream = new MemoryStream();
|
||||
// 메모리에 SVG 데이터 로드
|
||||
using (var image = new ImageMagick.MagickImage(svgData))
|
||||
try
|
||||
{
|
||||
// 적절한 크기로 리사이징 (32x32가 일반적인 파비콘 크기)
|
||||
image.Resize(32, 32);
|
||||
// PNG 형식으로 변환하여 메모리 스트림에 저장
|
||||
image.Format = ImageMagick.MagickFormat.Png;
|
||||
image.Write(memoryStream);
|
||||
}
|
||||
// Create SKSvg object from SVG data
|
||||
using var stream = new MemoryStream(svgData);
|
||||
var svg = new SkiaSharp.Extended.Svg.SKSvg();
|
||||
svg.Load(stream);
|
||||
|
||||
// Set default values if SVG size is invalid or missing
|
||||
float width = svg.Picture.CullRect.Width > 0 ? svg.Picture.CullRect.Width : 32;
|
||||
float height = svg.Picture.CullRect.Height > 0 ? svg.Picture.CullRect.Height : 32;
|
||||
|
||||
return memoryStream.ToArray();
|
||||
// Calculate scale for 32x32 favicon size
|
||||
float scaleX = 32 / width;
|
||||
float scaleY = 32 / height;
|
||||
float scale = Math.Min(scaleX, scaleY);
|
||||
|
||||
// Calculate final image dimensions (maintaining aspect ratio)
|
||||
int finalWidth = (int)(width * scale);
|
||||
int finalHeight = (int)(height * scale);
|
||||
|
||||
// Render to PNG
|
||||
using var surface = SkiaSharp.SKSurface.Create(new SkiaSharp.SKImageInfo(finalWidth, finalHeight));
|
||||
var canvas = surface.Canvas;
|
||||
|
||||
// Set transparent background
|
||||
canvas.Clear(SkiaSharp.SKColors.Transparent);
|
||||
|
||||
// Draw SVG (scaled to fit)
|
||||
canvas.Scale(scale);
|
||||
canvas.DrawPicture(svg.Picture);
|
||||
|
||||
// Extract image data
|
||||
using var image = surface.Snapshot();
|
||||
using var data = image.Encode(SkiaSharp.SKEncodedImageFormat.Png, 100);
|
||||
return data.ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Exception("SVG to PNG conversion failed", ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Exception("SVG to PNG conversion failed", ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsSvgData(byte[] data)
|
||||
{
|
||||
if (data == null || data.Length < 5)
|
||||
return false;
|
||||
|
||||
// SVG 파일 시그니처 확인
|
||||
// ASCII로 시작하는 SVG XML 헤더 확인
|
||||
// Check SVG file signature
|
||||
// Verify SVG XML header starting with ASCII
|
||||
string header = System.Text.Encoding.ASCII.GetString(data, 0, Math.Min(data.Length, 200)).ToLower();
|
||||
|
||||
return header.Contains("<svg") ||
|
||||
|
|
|
|||
|
|
@ -95,8 +95,9 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="14.5.0" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.3" />
|
||||
<PackageReference Include="SkiaSharp" Version="3.116.1" />
|
||||
<PackageReference Include="SkiaSharp.Svg" Version="1.60.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -31,10 +31,6 @@
|
|||
Margin="0,0,15,0"
|
||||
Click="Others_Click"
|
||||
Content="{DynamicResource flowlauncher_plugin_browserbookmark_others}" />
|
||||
<Button
|
||||
Margin="0,0,15,0"
|
||||
Click="RemoveFaviconCache_Click"
|
||||
Content="Remove Favicon Cache" />
|
||||
</StackPanel>
|
||||
<StackPanel Name="CustomBrowsersList" Visibility="Collapsed">
|
||||
<ListView
|
||||
|
|
|
|||
|
|
@ -16,16 +16,13 @@ namespace Flow.Launcher.Plugin.BrowserBookmark.Views;
|
|||
public partial class SettingsControl : INotifyPropertyChanged
|
||||
{
|
||||
public Settings Settings { get; }
|
||||
private readonly PluginInitContext _context;
|
||||
public SettingsControl(Settings settings)
|
||||
{
|
||||
// Settings 객체를 직접 받도록 수정
|
||||
Settings = settings;
|
||||
InitializeComponent();
|
||||
DataContext = this;
|
||||
}
|
||||
public CustomBrowser SelectedCustomBrowser { get; set; }
|
||||
|
||||
public SettingsControl(Settings settings)
|
||||
{
|
||||
Settings = settings;
|
||||
InitializeComponent();
|
||||
}
|
||||
public bool LoadChromeBookmark
|
||||
{
|
||||
get => Settings.LoadChromeBookmark;
|
||||
|
|
@ -123,62 +120,4 @@ public partial class SettingsControl : INotifyPropertyChanged
|
|||
_ = Task.Run(() => Main.ReloadAllBookmarks());
|
||||
}
|
||||
}
|
||||
private void RemoveFaviconCache_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 플러그인 디렉토리 경로 가져오기
|
||||
var pluginDir = Main.GetPluginDirectory();
|
||||
if (string.IsNullOrEmpty(pluginDir))
|
||||
{
|
||||
MessageBox.Show("플러그인 디렉토리를 찾을 수 없습니다.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
// 파비콘 캐시 디렉토리 경로 지정
|
||||
string cacheDir = Path.Combine(pluginDir, "Images", "Favicons");
|
||||
|
||||
// 디렉토리 존재 확인 및 생성
|
||||
if (!Directory.Exists(cacheDir))
|
||||
{
|
||||
MessageBox.Show("파비콘 캐시 디렉토리가 존재하지 않습니다. 캐시가 비어있거나 아직 생성되지 않았을 수 있습니다.", "알림", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
// 파일 수 확인
|
||||
var files = Directory.GetFiles(cacheDir);
|
||||
if (files.Length == 0)
|
||||
{
|
||||
MessageBox.Show("파비콘 캐시가 이미 비어 있습니다.", "알림", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
// 디렉토리 내 모든 파일 삭제
|
||||
int deletedCount = 0;
|
||||
foreach (var file in files)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(file);
|
||||
deletedCount++;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Flow.Launcher.Infrastructure.Logger.Log.Exception(
|
||||
$"Failed to delete favicon cache file: {file}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
// 북마크 다시 로드
|
||||
Main.ReloadAllBookmarks();
|
||||
|
||||
// 완료 메시지 표시
|
||||
MessageBox.Show($"{deletedCount}개의 파비콘 캐시 파일이 삭제되었습니다.", "캐시 삭제 완료", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Flow.Launcher.Infrastructure.Logger.Log.Exception("Failed to remove favicon cache", ex);
|
||||
MessageBox.Show($"파비콘 캐시 삭제 중 오류가 발생했습니다: {ex.Message}", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue