diff --git a/Flow.Launcher.Plugin/EventHandler.cs b/Flow.Launcher.Plugin/EventHandler.cs
index 009e1721c42..893b0ba8047 100644
--- a/Flow.Launcher.Plugin/EventHandler.cs
+++ b/Flow.Launcher.Plugin/EventHandler.cs
@@ -1,4 +1,5 @@
-using System.Windows;
+using System;
+using System.Windows;
using System.Windows.Input;
namespace Flow.Launcher.Plugin
@@ -32,6 +33,24 @@ namespace Flow.Launcher.Plugin
/// return true to continue handling, return false to intercept system handling
public delegate bool FlowLauncherGlobalKeyboardEventHandler(int keyevent, int vkcode, SpecialKeyState state);
+ ///
+ /// A delegate for when the visibility is changed
+ ///
+ ///
+ ///
+ public delegate void VisibilityChangedEventHandler(object sender, VisibilityChangedEventArgs args);
+
+ ///
+ /// The event args for
+ ///
+ public class VisibilityChangedEventArgs : EventArgs
+ {
+ ///
+ /// if the main window has become visible
+ ///
+ public bool IsVisible { get; init; }
+ }
+
///
/// Arguments container for the Key Down event
///
diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
index 9b9a9525d5c..474ad6f0a5d 100644
--- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
+++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
@@ -96,7 +96,12 @@ public interface IPublicAPI
///
///
bool IsMainWindowVisible();
-
+
+ ///
+ /// Invoked when the visibility of the main window has changed. Currently, the plugin will continue to be subscribed even if it is turned off.
+ ///
+ event VisibilityChangedEventHandler VisibilityChanged;
+
///
/// Show message box
///
diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs
index 4312df3c386..def54e04bc9 100644
--- a/Flow.Launcher/PublicAPIInstance.cs
+++ b/Flow.Launcher/PublicAPIInstance.cs
@@ -75,6 +75,8 @@ public void RestartApp()
public bool IsMainWindowVisible() => _mainVM.MainWindowVisibilityStatus;
+ public event VisibilityChangedEventHandler VisibilityChanged { add => _mainVM.VisibilityChanged += value; remove => _mainVM.VisibilityChanged -= value; }
+
public void CheckForNewUpdate() => _settingsVM.UpdateApp();
public void SaveAppAllSettings()
diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs
index 0110a11d775..c832c258d28 100644
--- a/Flow.Launcher/ViewModel/MainViewModel.cs
+++ b/Flow.Launcher/ViewModel/MainViewModel.cs
@@ -578,6 +578,8 @@ private ResultsViewModel SelectedResults
// because it is more accurate and reliable representation than using Visibility as a condition check
public bool MainWindowVisibilityStatus { get; set; } = true;
+ public event VisibilityChangedEventHandler VisibilityChanged;
+
public Visibility SearchIconVisibility { get; set; }
public double MainWindowWidth
@@ -1014,6 +1016,7 @@ public void Show()
MainWindowOpacity = 1;
MainWindowVisibilityStatus = true;
+ VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = true });
});
}
@@ -1048,6 +1051,7 @@ public async void Hide()
MainWindowVisibilityStatus = false;
MainWindowVisibility = Visibility.Collapsed;
+ VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = false });
}
///