Skip to content

Commit fe0153b

Browse files
committed
Initial commit
1 parent df97be7 commit fe0153b

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed

Flow.Launcher/Flow.Launcher.csproj

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@
7777
<SubType>Designer</SubType>
7878
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7979
</Content>
80+
<COMReference Include="SHDocVw">
81+
<VersionMinor>1</VersionMinor>
82+
<VersionMajor>1</VersionMajor>
83+
<Guid>eab22ac0-30c1-11cf-a7eb-0000c05bae0b</Guid>
84+
<Lcid>0</Lcid>
85+
<WrapperTool>tlbimp</WrapperTool>
86+
<Isolated>false</Isolated>
87+
<EmbedInteropTypes>true</EmbedInteropTypes>
88+
</COMReference>
89+
<COMReference Include="Shell32">
90+
<VersionMinor>0</VersionMinor>
91+
<VersionMajor>1</VersionMajor>
92+
<Guid>50a7e9b0-70ef-11d1-b75a-00a0c90564fe</Guid>
93+
<Lcid>0</Lcid>
94+
<WrapperTool>tlbimp</WrapperTool>
95+
<Isolated>false</Isolated>
96+
<EmbedInteropTypes>true</EmbedInteropTypes>
97+
</COMReference>
8098
<Content Include="Resources\Segoe Fluent Icons.ttf">
8199
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
82100
</Content>
@@ -110,6 +128,21 @@
110128
</Content>
111129
</ItemGroup>
112130

131+
<ItemGroup>
132+
<Compile Update="Properties\Settings.Designer.cs">
133+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
134+
<AutoGen>True</AutoGen>
135+
<DependentUpon>Settings.settings</DependentUpon>
136+
</Compile>
137+
</ItemGroup>
138+
139+
<ItemGroup>
140+
<None Update="Properties\Settings.settings">
141+
<Generator>SettingsSingleFileGenerator</Generator>
142+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
143+
</None>
144+
</ItemGroup>
145+
113146
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
114147
<Exec Command="taskkill /f /fi &quot;IMAGENAME eq Flow.Launcher.exe&quot;" />
115148
</Target>

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
using Microsoft.VisualStudio.Threading;
2121
using System.Threading.Channels;
2222
using ISavable = Flow.Launcher.Plugin.ISavable;
23-
23+
using System.Runtime.InteropServices;
24+
using System.Text;
25+
using SHDocVw;
2426

2527
namespace Flow.Launcher.ViewModel
2628
{
@@ -720,6 +722,62 @@ private void SetOpenResultModifiers()
720722
OpenResultCommandModifiers = _settings.OpenResultModifiers ?? DefaultOpenResultModifiers;
721723
}
722724

725+
private static string GetActiveExplorerPath()
726+
{
727+
// get the active window
728+
IntPtr handle = GetForegroundWindow();
729+
730+
// Required ref: SHDocVw (Microsoft Internet Controls COM Object) - C:\Windows\system32\ShDocVw.dll
731+
ShellWindows shellWindows = new SHDocVw.ShellWindows();
732+
733+
// loop through all windows
734+
foreach (InternetExplorer window in shellWindows)
735+
{
736+
// match active window
737+
if (window.HWND == (int)handle)
738+
{
739+
// Required ref: Shell32 - C:\Windows\system32\Shell32.dll
740+
var shellWindow = window.Document as Shell32.IShellFolderViewDual2;
741+
742+
// will be null if you are in Internet Explorer for example
743+
if (shellWindow != null)
744+
{
745+
// Item without an index returns the current object
746+
var currentFolder = shellWindow.Folder.Items().Item();
747+
748+
// special folder - use window title
749+
// for some reason on "Desktop" gives null
750+
if (currentFolder == null || currentFolder.Path.StartsWith("::"))
751+
{
752+
// Get window title instead
753+
const int nChars = 256;
754+
StringBuilder Buff = new StringBuilder(nChars);
755+
if (GetWindowText(handle, Buff, nChars) > 0)
756+
{
757+
return Buff.ToString();
758+
}
759+
}
760+
else
761+
{
762+
return currentFolder.Path;
763+
}
764+
}
765+
766+
break;
767+
}
768+
}
769+
770+
return null;
771+
}
772+
773+
// COM Imports
774+
775+
[DllImport("user32.dll")]
776+
private static extern IntPtr GetForegroundWindow();
777+
778+
[DllImport("user32.dll")]
779+
static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
780+
723781
public void ToggleFlowLauncher()
724782
{
725783
if (!MainWindowVisibilityStatus)
@@ -734,6 +792,9 @@ public void ToggleFlowLauncher()
734792

735793
public void Show()
736794
{
795+
string _explorerPath = GetActiveExplorerPath();
796+
797+
ChangeQueryText($"{_explorerPath}\\>");
737798
if (_settings.UseSound)
738799
{
739800
MediaPlayer media = new MediaPlayer();
@@ -749,6 +810,8 @@ public void Show()
749810
((MainWindow)Application.Current.MainWindow).WindowAnimator();
750811

751812
MainWindowOpacity = 1;
813+
814+
752815
}
753816

754817
public async void Hide()

0 commit comments

Comments
 (0)