From fe0153be088d8f82877d7ea06b46364a556c68f5 Mon Sep 17 00:00:00 2001
From: Garulf <535299+Garulf@users.noreply.github.com>
Date: Wed, 15 Dec 2021 05:21:40 -0500
Subject: [PATCH 1/5] Initial commit
---
Flow.Launcher/Flow.Launcher.csproj | 33 ++++++++++++
Flow.Launcher/ViewModel/MainViewModel.cs | 65 +++++++++++++++++++++++-
2 files changed, 97 insertions(+), 1 deletion(-)
diff --git a/Flow.Launcher/Flow.Launcher.csproj b/Flow.Launcher/Flow.Launcher.csproj
index f431504c2e4..117dececf5a 100644
--- a/Flow.Launcher/Flow.Launcher.csproj
+++ b/Flow.Launcher/Flow.Launcher.csproj
@@ -77,6 +77,24 @@
Designer
PreserveNewest
+
+ 1
+ 1
+ eab22ac0-30c1-11cf-a7eb-0000c05bae0b
+ 0
+ tlbimp
+ false
+ true
+
+
+ 0
+ 1
+ 50a7e9b0-70ef-11d1-b75a-00a0c90564fe
+ 0
+ tlbimp
+ false
+ true
+
PreserveNewest
@@ -110,6 +128,21 @@
+
+
+ True
+ True
+ Settings.settings
+
+
+
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
+
diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs
index abf3a1d14ea..cbe35e0f587 100644
--- a/Flow.Launcher/ViewModel/MainViewModel.cs
+++ b/Flow.Launcher/ViewModel/MainViewModel.cs
@@ -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
{
@@ -720,6 +722,62 @@ private void SetOpenResultModifiers()
OpenResultCommandModifiers = _settings.OpenResultModifiers ?? DefaultOpenResultModifiers;
}
+ private static string GetActiveExplorerPath()
+ {
+ // get the active window
+ IntPtr handle = GetForegroundWindow();
+
+ // Required ref: SHDocVw (Microsoft Internet Controls COM Object) - C:\Windows\system32\ShDocVw.dll
+ ShellWindows shellWindows = new SHDocVw.ShellWindows();
+
+ // loop through all windows
+ foreach (InternetExplorer window in shellWindows)
+ {
+ // match active window
+ if (window.HWND == (int)handle)
+ {
+ // Required ref: Shell32 - C:\Windows\system32\Shell32.dll
+ var shellWindow = window.Document as Shell32.IShellFolderViewDual2;
+
+ // will be null if you are in Internet Explorer for example
+ if (shellWindow != null)
+ {
+ // Item without an index returns the current object
+ var currentFolder = shellWindow.Folder.Items().Item();
+
+ // special folder - use window title
+ // for some reason on "Desktop" gives null
+ if (currentFolder == null || currentFolder.Path.StartsWith("::"))
+ {
+ // Get window title instead
+ const int nChars = 256;
+ StringBuilder Buff = new StringBuilder(nChars);
+ if (GetWindowText(handle, Buff, nChars) > 0)
+ {
+ return Buff.ToString();
+ }
+ }
+ else
+ {
+ return currentFolder.Path;
+ }
+ }
+
+ break;
+ }
+ }
+
+ 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);
+
public void ToggleFlowLauncher()
{
if (!MainWindowVisibilityStatus)
@@ -734,6 +792,9 @@ public void ToggleFlowLauncher()
public void Show()
{
+ string _explorerPath = GetActiveExplorerPath();
+
+ ChangeQueryText($"{_explorerPath}\\>");
if (_settings.UseSound)
{
MediaPlayer media = new MediaPlayer();
@@ -749,6 +810,8 @@ public void Show()
((MainWindow)Application.Current.MainWindow).WindowAnimator();
MainWindowOpacity = 1;
+
+
}
public async void Hide()
From 79a6fda289dfa641e011588f500d98b22425b3d2 Mon Sep 17 00:00:00 2001
From: Garulf <535299+Garulf@users.noreply.github.com>
Date: Wed, 15 Dec 2021 05:24:31 -0500
Subject: [PATCH 2/5] Only insert when explorer is active
---
Flow.Launcher/ViewModel/MainViewModel.cs | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs
index cbe35e0f587..7a48d159fca 100644
--- a/Flow.Launcher/ViewModel/MainViewModel.cs
+++ b/Flow.Launcher/ViewModel/MainViewModel.cs
@@ -793,8 +793,11 @@ public void ToggleFlowLauncher()
public void Show()
{
string _explorerPath = GetActiveExplorerPath();
-
- ChangeQueryText($"{_explorerPath}\\>");
+ if (_explorerPath != null)
+ {
+ ChangeQueryText($"{_explorerPath}\\>");
+ }
+
if (_settings.UseSound)
{
MediaPlayer media = new MediaPlayer();
From 1fdaec2648f14994b9b15fc86c732629796f6f13 Mon Sep 17 00:00:00 2001
From: Garulf <535299+Garulf@users.noreply.github.com>
Date: Wed, 15 Dec 2021 06:15:05 -0500
Subject: [PATCH 3/5] ChangeQuery after window is visible
---
Flow.Launcher/ViewModel/MainViewModel.cs | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs
index 7a48d159fca..b525ac34222 100644
--- a/Flow.Launcher/ViewModel/MainViewModel.cs
+++ b/Flow.Launcher/ViewModel/MainViewModel.cs
@@ -731,7 +731,7 @@ private static string GetActiveExplorerPath()
ShellWindows shellWindows = new SHDocVw.ShellWindows();
// loop through all windows
- foreach (InternetExplorer window in shellWindows)
+ foreach (SHDocVw.InternetExplorer window in shellWindows)
{
// match active window
if (window.HWND == (int)handle)
@@ -793,10 +793,7 @@ public void ToggleFlowLauncher()
public void Show()
{
string _explorerPath = GetActiveExplorerPath();
- if (_explorerPath != null)
- {
- ChangeQueryText($"{_explorerPath}\\>");
- }
+
if (_settings.UseSound)
{
@@ -813,7 +810,10 @@ public void Show()
((MainWindow)Application.Current.MainWindow).WindowAnimator();
MainWindowOpacity = 1;
-
+ if (_explorerPath != null && _explorerPath != "File Explorer")
+ {
+ ChangeQueryText($"{_explorerPath}\\>");
+ }
}
From 1109f9887e78ddcfda62f0e775893f6161344ec2 Mon Sep 17 00:00:00 2001
From: Garulf <535299+Garulf@users.noreply.github.com>
Date: Thu, 16 Dec 2021 02:03:22 -0500
Subject: [PATCH 4/5] Remove unnecessary changes
---
Flow.Launcher/Flow.Launcher.csproj | 15 ---------------
1 file changed, 15 deletions(-)
diff --git a/Flow.Launcher/Flow.Launcher.csproj b/Flow.Launcher/Flow.Launcher.csproj
index 117dececf5a..9d40427005a 100644
--- a/Flow.Launcher/Flow.Launcher.csproj
+++ b/Flow.Launcher/Flow.Launcher.csproj
@@ -128,21 +128,6 @@
-
-
- True
- True
- Settings.settings
-
-
-
-
-
- SettingsSingleFileGenerator
- Settings.Designer.cs
-
-
-
From aa5ca76b180b94680ee4f1f677581eb35bbf7424 Mon Sep 17 00:00:00 2001
From: Garulf <535299+Garulf@users.noreply.github.com>
Date: Mon, 20 Dec 2021 03:34:41 -0500
Subject: [PATCH 5/5] Check window is InternetExplorer type
---
Flow.Launcher/ViewModel/MainViewModel.cs | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs
index b525ac34222..412af09fdfd 100644
--- a/Flow.Launcher/ViewModel/MainViewModel.cs
+++ b/Flow.Launcher/ViewModel/MainViewModel.cs
@@ -731,13 +731,19 @@ private static string GetActiveExplorerPath()
ShellWindows shellWindows = new SHDocVw.ShellWindows();
// loop through all windows
- foreach (SHDocVw.InternetExplorer window in shellWindows)
+ foreach (var window in shellWindows)
{
+ if (window is not SHDocVw.InternetExplorer)
+ {
+ continue;
+ }
+
+ var explorerWindow = (SHDocVw.InternetExplorer)window;
// match active window
- if (window.HWND == (int)handle)
+ if (explorerWindow.HWND == (int)handle)
{
// Required ref: Shell32 - C:\Windows\system32\Shell32.dll
- var shellWindow = window.Document as Shell32.IShellFolderViewDual2;
+ var shellWindow = explorerWindow.Document as Shell32.IShellFolderViewDual2;
// will be null if you are in Internet Explorer for example
if (shellWindow != null)