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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reveal file in file explorer #18
Conversation
Looks good, I just made some changes:
Any thoughts? edit: I found one little issue which I also encountered in a related PR: On Windows, if you reveal a non-existent file, no error is returned; the explorer just opens the top-level "This PC" view. |
Makes sense - I wasn't sure about the binary's purpose :) Regarding the non-existent file handling on Windows: Should I manually check that the file exists? |
I found there is a Windows API function we could use instead, which does return an error code if the file doesn't exist. I think that would be the best solution for Windows. I found this repo which demonstrates that approach (though I think for correctness with respect to COM, it should be using a separate thread). |
I have experimented with this function before, but I was worried about the Should I spawn a thread for each call to I'll take a look at the example repostitory, maybe I can incorporate that. |
Since you linked the Chromium repo above, I was curious how they implemented this on Windows so I looked at the source and that's where I learned about this Windows API function. I also noticed they were using a worker thread. Source link I think spawning a thread for each call is fine; this is a function that would be called infrequently, so the overhead of spawning a thread is negligible. |
The latest version now calls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just this one other detail and I can merge this.
I'm finally done 馃コ
Resolves #17
Name
I chose
reveal
because that's the name used in macOS'sopen
command, but I'm open to better suggestions :)Linux
I found a good explanation of Chromium's solution and used that as an inspiration.
If it fails, I'm using your suggested fallback of opening the containing directory with
open
.Errors
I didn't want to expose
dbus::Error
, so I decided to wrap it instd::io::Error
instead.Dependencies
dbus
dbus-send
command, but it does not support variant dictionaries which is one of the parameters for theorg.freedesktop.portal.OpenURI
interface.libdbus
library. I hope that's OK :)reveal
function behind a feature as to not push the dependency on consumers of this crate.url
Url::from_file_path
function. I took a quick peek at the source code and should you not want the dependency onurl
I think it should be fairly easy to implement it ourselves.Tested on