Skip to content
34 changes: 34 additions & 0 deletions Flow.Launcher.Plugin/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class Result

private string _icoPath;

private string _QuickLookPath;

/// <summary>
/// The title of the result. This is always required.
/// </summary>
Expand Down Expand Up @@ -64,6 +66,38 @@ public string IcoPath
}
}

public string QuickLookPath
{
get
{
if (!string.IsNullOrEmpty(_QuickLookPath))
{
return _QuickLookPath;
}
else if (File.Exists(Title) || Directory.Exists(Title))
{
return Title;
}
else if (File.Exists(SubTitle) || Directory.Exists(SubTitle))
{
return SubTitle;
}
else if (!string.IsNullOrEmpty(IcoPath))
{
return IcoPath;
}
else
{
return _QuickLookPath;
}

}
set
{
_QuickLookPath = value;
}
}

public delegate ImageSource IconDelegate();

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</Window.Resources>
<Window.InputBindings>
<KeyBinding Key="Escape" Command="{Binding EscCommand}" />
<KeyBinding Key="F1" Command="{Binding StartHelpCommand}" />
<KeyBinding Key="F1" Command="{Binding OpenQuickLook}" />
<KeyBinding Key="F5" Command="{Binding ReloadPluginDataCommand}" />
<KeyBinding Key="Tab" Command="{Binding AutocompleteQueryCommand}" />
<KeyBinding
Expand Down
54 changes: 50 additions & 4 deletions Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
using System.Threading.Channels;
using ISavable = Flow.Launcher.Plugin.ISavable;
using System.IO;
using System.Security.Principal;
using System.IO.Pipes;
using System.Collections.Specialized;
using System.Text;
using System.Buffers;

namespace Flow.Launcher.ViewModel
{
Expand Down Expand Up @@ -179,14 +183,57 @@ private void InitializeKeyCommands()
}
});

SelectNextItemCommand = new RelayCommand(_ => { SelectedResults.SelectNextResult(); });
SelectNextItemCommand = new RelayCommand(_ => {
SelectedResults.SelectNextResult();
OpenQuickLook.Execute("Switch");
});

SelectPrevItemCommand = new RelayCommand(_ => { SelectedResults.SelectPrevResult(); });
SelectPrevItemCommand = new RelayCommand(_ => {
SelectedResults.SelectPrevResult();
OpenQuickLook.Execute("Switch");
});

SelectNextPageCommand = new RelayCommand(_ => { SelectedResults.SelectNextPage(); });

SelectPrevPageCommand = new RelayCommand(_ => { SelectedResults.SelectPrevPage(); });



#pragma warning disable VSTHRD101 // Avoid unsupported async delegates
OpenQuickLook = new RelayCommand(async command =>
{
var results = SelectedResults;
var result = results.SelectedItem?.Result;

if (result is null)
return;
if (command is null)
{
command = "Toggle";
}
string pipeName = "QuickLook.App.Pipe." + WindowsIdentity.GetCurrent().User?.Value;

await using var client = new NamedPipeClientStream(".", pipeName, PipeDirection.Out);
try
{
await client.ConnectAsync(100).ConfigureAwait(false);
var message = $"QuickLook.App.PipeMessages.{command}|{result.QuickLookPath}\n";
using var buffer = MemoryPool<byte>.Shared.Rent(Encoding.UTF8.GetMaxByteCount(message.Length));
var count = Encoding.UTF8.GetBytes(message, buffer.Memory.Span);
await client.WriteAsync(buffer.Memory[..count]);
}
catch (System.TimeoutException)
{
if ((string)command == "Toggle")
{
Log.Warn("MainViewModel", "Unable to activate quicklook");
}

}

});
#pragma warning restore VSTHRD101 // Avoid unsupported async delegates

SelectFirstResultCommand = new RelayCommand(_ => SelectedResults.SelectFirstResult());

StartHelpCommand = new RelayCommand(_ =>
Expand Down Expand Up @@ -425,9 +472,8 @@ private ResultsViewModel SelectedResults
public ICommand OpenSettingCommand { get; set; }
public ICommand ReloadPluginDataCommand { get; set; }
public ICommand ClearQueryCommand { get; private set; }

public ICommand OpenQuickLook { get; set; }
public ICommand CopyToClipboard { get; set; }

public ICommand AutocompleteQueryCommand { get; set; }

public string OpenResultCommandModifiers { get; private set; }
Expand Down