Skip to content

Fix Dialog Owner & Improve Window Exiting & Improve WindowsThumbnailProvider & Fix Warnings #3467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 15, 2025
4 changes: 2 additions & 2 deletions Flow.Launcher.Infrastructure/Image/ImageLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ private static async ValueTask<ImageResult> LoadInternalAsync(string path, bool
}
catch (System.Exception e2)
{
Log.Exception(ClassName, $"|ImageLoader.Load|Failed to get thumbnail for {path} on first try", e);
Log.Exception(ClassName, $"|ImageLoader.Load|Failed to get thumbnail for {path} on second try", e2);
Log.Exception(ClassName, $"Failed to get thumbnail for {path} on first try", e);
Log.Exception(ClassName, $"Failed to get thumbnail for {path} on second try", e2);

ImageSource image = ImageCache[Constant.MissingImgIcon, false];
ImageCache[path, false] = image;
Expand Down
16 changes: 12 additions & 4 deletions Flow.Launcher.Infrastructure/Image/ThumbnailReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Flow.Launcher.Infrastructure.Image
{
/// <summary>
/// Subclass of <see cref="Windows.Win32.UI.Shell.SIIGBF"/>
/// Subclass of <see cref="SIIGBF"/>
/// </summary>
[Flags]
public enum ThumbnailOptions
Expand All @@ -31,7 +31,9 @@ public class WindowsThumbnailProvider

private static readonly Guid GUID_IShellItem = typeof(IShellItem).GUID;

private static readonly HRESULT S_ExtractionFailed = (HRESULT)0x8004B200;
private static readonly HRESULT S_EXTRACTIONFAILED = (HRESULT)0x8004B200;

private static readonly HRESULT S_PATHNOTFOUND = (HRESULT)0x8004B205;

public static BitmapSource GetThumbnail(string fileName, int width, int height, ThumbnailOptions options)
{
Expand Down Expand Up @@ -79,16 +81,22 @@ private static unsafe HBITMAP GetHBitmap(string fileName, int width, int height,
{
imageFactory.GetImage(size, (SIIGBF)options, &hBitmap);
}
catch (COMException ex) when (ex.HResult == S_ExtractionFailed && options == ThumbnailOptions.ThumbnailOnly)
catch (COMException ex) when (options == ThumbnailOptions.ThumbnailOnly &&
(ex.HResult == S_PATHNOTFOUND || ex.HResult == S_EXTRACTIONFAILED))
{
// Fallback to IconOnly if ThumbnailOnly fails
// Fallback to IconOnly if extraction fails or files cannot be found
imageFactory.GetImage(size, (SIIGBF)ThumbnailOptions.IconOnly, &hBitmap);
}
catch (FileNotFoundException) when (options == ThumbnailOptions.ThumbnailOnly)
{
// Fallback to IconOnly if files cannot be found
imageFactory.GetImage(size, (SIIGBF)ThumbnailOptions.IconOnly, &hBitmap);
}
catch (System.Exception ex)
{
// Handle other exceptions
throw new InvalidOperationException("Failed to get thumbnail", ex);
}
}
finally
{
Expand Down
1 change: 1 addition & 0 deletions Flow.Launcher/Msg.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private void fadeOutStoryboard_Completed(object sender, EventArgs e)
Close();
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD100:Avoid async void methods", Justification = "<Pending>")]
public async void Show(string title, string subTitle, string iconPath)
{
tbTitle.Text = title;
Expand Down
2 changes: 0 additions & 2 deletions Flow.Launcher/ReportWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace Flow.Launcher
{
internal partial class ReportWindow
{
private static readonly string ClassName = nameof(ReportWindow);

public ReportWindow(Exception exception)
{
InitializeComponent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ public SettingsPanePluginsViewModel(Settings settings)
.ToList();

[RelayCommand]
private async Task OpenHelperAsync()
private async Task OpenHelperAsync(Button button)
{
var helpDialog = new ContentDialog()
{
Owner = Application.Current.MainWindow,
Owner = Window.GetWindow(button),
Content = new StackPanel
{
Children =
Expand Down
1 change: 1 addition & 0 deletions Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
Height="34"
Margin="0 0 20 0"
Command="{Binding OpenHelperCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource Self}}"
Content="&#xe9ce;"
FontFamily="{DynamicResource SymbolThemeFontFamily}"
FontSize="14" />
Expand Down
4 changes: 2 additions & 2 deletions Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Windows.Navigation;
using System.Windows.Navigation;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.SettingPages.ViewModels;
using Page = ModernWpf.Controls.Page;
using Flow.Launcher.Infrastructure.UserSettings;
using Page = ModernWpf.Controls.Page;

namespace Flow.Launcher.SettingPages.Views;

Expand Down
29 changes: 0 additions & 29 deletions Flow.Launcher/ViewModel/RelayCommand.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<!-- Do not upgrade System.Data.OleDb since we are .Net7.0 -->
<PackageReference Include="System.Data.OleDb" Version="8.0.1" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
Expand Down Expand Up @@ -341,7 +341,7 @@ protected IntPtr[] GetPIDLs(DirectoryInfo[] arrFI)
return null;
}

IShellFolder oParentFolder = GetParentFolder(arrFI[0].Parent.FullName);
IShellFolder oParentFolder = GetParentFolder(arrFI[0].Parent!.FullName);
if (null == oParentFolder)
{
return null;
Expand Down Expand Up @@ -1535,7 +1535,7 @@ public void Install()
m_hookType,
m_filterFunc,
IntPtr.Zero,
(int)AppDomain.GetCurrentThreadId());
Environment.CurrentManagedThreadId);
}
// ************************************************************************

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static string GetTranslatedName(this SortOption sortOption)
ArgumentNullException.ThrowIfNull(API);

var enumName = Enum.GetName(sortOption);
var splited = enumName.Split('_');
var splited = enumName!.Split('_');
var name = string.Join('_', splited[..^1]);
var direction = splited[^1];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private static void LoadEnvironmentStringPaths()

foreach (DictionaryEntry special in Environment.GetEnvironmentVariables())
{
var path = special.Value.ToString();
var path = special.Value!.ToString();
// we add a trailing slash to the path to make sure drive paths become valid absolute paths.
// for example, if %systemdrive% is C: we turn it to C:\
path = path.EnsureTrailingSlash();
Expand All @@ -61,7 +61,7 @@ private static void LoadEnvironmentStringPaths()
{
// Variables are returned with a mixture of all upper/lower case.
// Call ToUpper() to make the results look consistent
_envStringPaths.Add(special.Key.ToString().ToUpper(), path);
_envStringPaths.Add(special.Key.ToString()!.ToUpper(), path);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;

#nullable enable

namespace Flow.Launcher.Plugin.Explorer.Views
{
public class ActionKeywordModel : INotifyPropertyChanged
{
private static Settings _settings;
private static Settings _settings = null!;

public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangedEventHandler? PropertyChanged;

public static void Init(Settings settings)
{
Expand Down Expand Up @@ -54,4 +56,4 @@ public bool Enabled
}
}
}
}
}
27 changes: 0 additions & 27 deletions Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/RelayCommand.cs

This file was deleted.

Loading
Loading