-
-
Notifications
You must be signed in to change notification settings - Fork 459
Insert active explorer path #1275
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
Changes from 6 commits
fe0153b
79a6fda
1fdaec2
1109f98
aa5ca76
c039b17
81bacdb
ab306d9
1606908
5600880
0a062c3
f78c212
55dee4f
2212eac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| using System; | ||
| using System.Text; | ||
| using System.Runtime.InteropServices; | ||
| using System.IO; | ||
|
|
||
| namespace Flow.Launcher.Helper | ||
| { | ||
| public class FileExplorerHelper | ||
|
||
| { | ||
|
|
||
| /// <summary> | ||
| /// Gets the path of the file explorer that is currently in the foreground | ||
| /// </summary> | ||
| public static string GetActiveExplorerPath() | ||
| { | ||
| var explorerWindow = GetActiveExplorer(); | ||
| string locationUrl = explorerWindow.LocationURL; | ||
| if (!string.IsNullOrEmpty(locationUrl)) | ||
| { | ||
| return new Uri(locationUrl).LocalPath; | ||
|
||
| } | ||
| else | ||
| { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the file explorer that is currently in the foreground | ||
| /// </summary> | ||
| private static SHDocVw.InternetExplorer GetActiveExplorer() | ||
| { | ||
| // get the active window | ||
| IntPtr handle = GetForegroundWindow(); | ||
|
|
||
| // Required ref: SHDocVw (Microsoft Internet Controls COM Object) - C:\Windows\system32\ShDocVw.dll | ||
| var shellWindows = new SHDocVw.ShellWindows(); | ||
|
|
||
| // loop through all windows | ||
| foreach (var window in shellWindows) | ||
| { | ||
| if (window is SHDocVw.InternetExplorer explorerWindow && new IntPtr(explorerWindow.HWND) == handle) | ||
| { | ||
| // we have found the desired window, now let's make sure that it is indeed a file explorer | ||
| // we don't want the Internet Explorer or the classic control panel | ||
| if (explorerWindow.Document is not Shell32.IShellFolderViewDual2) | ||
|
||
| { | ||
| return null; | ||
| } | ||
| if (Path.GetFileName(explorerWindow.FullName) != "explorer.exe") | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| return explorerWindow; | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| // COM Imports | ||
|
|
||
| [DllImport("user32.dll")] | ||
| private static extern IntPtr GetForegroundWindow(); | ||
|
|
||
| [DllImport("user32.dll")] | ||
| static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,9 @@ | |
| using Microsoft.VisualStudio.Threading; | ||
| using System.Threading.Channels; | ||
| using ISavable = Flow.Launcher.Plugin.ISavable; | ||
|
|
||
| using System.Runtime.InteropServices; | ||
| using System.Text; | ||
| using SHDocVw; | ||
|
|
||
| namespace Flow.Launcher.ViewModel | ||
| { | ||
|
|
@@ -734,6 +736,9 @@ public void ToggleFlowLauncher() | |
|
|
||
| public void Show() | ||
| { | ||
| string _explorerPath = FileExplorerHelper.GetActiveExplorerPath(); | ||
|
||
|
|
||
|
|
||
| if (_settings.UseSound) | ||
| { | ||
| MediaPlayer media = new MediaPlayer(); | ||
|
|
@@ -749,6 +754,11 @@ public void Show() | |
| ((MainWindow)Application.Current.MainWindow).WindowAnimator(); | ||
|
|
||
| MainWindowOpacity = 1; | ||
| if (_explorerPath != null) | ||
|
||
| { | ||
| ChangeQueryText($"{_explorerPath}\\>"); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| public async void Hide() | ||
|
|
||
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.
What do you think about the COMREference? Is it better to use dynamic typing as what you did in the runner plugin? Somehow the dotnet cli doesn't support this feature, and the previous workaround is to copy the reference dll and directly reference that dll.
Uh oh!
There was an error while loading. Please reload this page.
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.
I honestly have no clue.
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.
I would say since you have shared a way to prevent usage of comreference, let's use that. Previously I workaround this by copying out the dll and reference that directly.
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.
Though I personally think it may be better to have strongly type?
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.
dotnet/msbuild#3986
Uh oh!
There was an error while loading. Please reload this page.
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.
Apparently one can define the COM import interfaces themselves. Like this app does https://github.com/emoacht/Monitorian/blob/c16345d1aa679ca463a14b4c1ef0917a524fe31a/Source/Monitorian.Core/Models/Monitor/LightSensor.cs , or like how the .NET framework does it https://referencesource.microsoft.com/#PresentationFramework/src/Framework/MS/Internal/AppModel/ShellProvider.cs,3ec518c827af4fd7
(Another example https://www.pinvoke.net/default.aspx/Interfaces/IShellItem.html and a quick note about how this stuff works https://stackoverflow.com/questions/9210723/do-i-need-to-free-resources-when-calling-shcreateitemfromparsingname-from-manage )
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.
yeah for sure, but I think that's pretty messy. We do have some example about that.