Skip to content
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

Integration with other file managers #557

Closed
m1l opened this issue Oct 9, 2019 · 6 comments
Closed

Integration with other file managers #557

m1l opened this issue Oct 9, 2019 · 6 comments

Comments

@m1l
Copy link

m1l commented Oct 9, 2019

I'm developing a file manager and one of users asked about supporting QuickLook. I have tried passing the path to .exe as parameter but that does not work. Is it possible to already pass a file to be previewed in some way?

@xupefei
Copy link
Member

xupefei commented Oct 9, 2019

Passing a path to QuickLook.exe should work -- but only when the user is using MSI or ZIP version of QuickLook (does not work for Windows Store version).

The best option is to send a message to a named pipe (code):

string PipeName = "QuickLook.App.Pipe." + WindowsIdentity.GetCurrent().User?.Value;
string Toggle = "QuickLook.App.PipeMessages.Toggle";

public static void SendMessage(string pipeMessage, string path = null)
{
    if (path == null)
        path = "";

    try
    {
        using (var client = new NamedPipeClientStream(".", PipeName, PipeDirection.Out))
        {
            client.Connect();

            using (var writer = new StreamWriter(client))
            {
                writer.WriteLine($"{pipeMessage}|{path}");
                writer.Flush();
            }
        }
    }
    catch (Exception e)
    {
        Debug.WriteLine(e.ToString());
    }
}

The code above can be used like this:

SendMessage(Toggle, "C:\path\to\file.txt");

The preview window will be closed when the same message is sent for the second time.
If the second message is still PipeMessages.Toggle but with a different path, QuickLook will switch to preview the new path.


If sending a message is too complicated to your application, you can instead provide something e.g. WM_COPYDATA so I can get the selected file from QuickLook's side, like what I have done for Directory Opus (code).

@m1l
Copy link
Author

m1l commented Oct 10, 2019

Thank you! With the provided code it was 5 minute to integrate. The only place I have trouble with now is how to check if preview window is already open (in case user selects another file, to show preview only if preview window is already opened). I have tried the MainWindowHandle of the "QuickLook" process but it is 0. Is there a proper way to check?

@xupefei
Copy link
Member

xupefei commented Oct 11, 2019

No, there isn't any direct method to ask QuickLook for that, but it is possible with Windows APIs. I would suggest the following steps:

  1. Use EnumWindows and GetClassName to check if any window is having a class name starting HwndWrapper[QuickLook.exe;; (full class name looks like HwndWrapper[QuickLook.exe;;8a9110c8-bad4-4b12-b2f7-fb06c505b290]).

  2. On your side, Send Toggle message when Spacebar is pressed. Additionally, if a preview window is visible, send Switch message when the selection changes. Although the Switch message does nothing when no preview is visible, it is good to avoid wasting CPU time by checking for any window before sending the message.

The Switch message has the same format with Toggle: SendMessage("QuickLook.App.PipeMessages.Switch", "C:\path\to\file.txt");

@m1l
Copy link
Author

m1l commented Oct 11, 2019

Great. I did have to additionally use IsWindowVisible from user32.dll or it finds that class even when the window is closed. Total of <6 ms per check. Thank you!

@QL-Win QL-Win deleted a comment from fzxj520 Oct 15, 2019
@LunarLanding
Copy link

I tried using it from the command line and it stops working.
Steps:

  • verify it works normally.
  • verify pipe works and exists with get-childitem \\.\pipe\ | out-string -stream | Select-String -Pattern "QuickLook" on powershell
  • execute on command prompt echo "QuickLook.App.PipeMessages.Toggle|[absolute path to document.pdf]" > \\.\pipe\QuickLook.App.Pipe.[SID]
  • expected preview to open, but nothing happens, the pipe is gone and the normal spacebar shortcut on windows explorer does not work.

@xupefei
Copy link
Member

xupefei commented Dec 5, 2019

@LunarLanding Any exception log?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants