Skip to content

Commit 0429cef

Browse files
authored
Merge pull request #2216 from Odotocodot/feature/VisibilityChanged
Add Plugin API -> VisibilityChangedEventHandler
2 parents 4758ea2 + 4eb20e2 commit 0429cef

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

Flow.Launcher.Plugin/EventHandler.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Windows;
1+
using System;
2+
using System.Windows;
23
using System.Windows.Input;
34

45
namespace Flow.Launcher.Plugin
@@ -32,6 +33,24 @@ namespace Flow.Launcher.Plugin
3233
/// <returns>return true to continue handling, return false to intercept system handling</returns>
3334
public delegate bool FlowLauncherGlobalKeyboardEventHandler(int keyevent, int vkcode, SpecialKeyState state);
3435

36+
/// <summary>
37+
/// A delegate for when the visibility is changed
38+
/// </summary>
39+
/// <param name="sender"></param>
40+
/// <param name="args"></param>
41+
public delegate void VisibilityChangedEventHandler(object sender, VisibilityChangedEventArgs args);
42+
43+
/// <summary>
44+
/// The event args for <see cref="VisibilityChangedEventHandler"/>
45+
/// </summary>
46+
public class VisibilityChangedEventArgs : EventArgs
47+
{
48+
/// <summary>
49+
/// <see langword="true"/> if the main window has become visible
50+
/// </summary>
51+
public bool IsVisible { get; init; }
52+
}
53+
3554
/// <summary>
3655
/// Arguments container for the Key Down event
3756
/// </summary>

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ public interface IPublicAPI
9696
/// </summary>
9797
/// <returns></returns>
9898
bool IsMainWindowVisible();
99-
99+
100+
/// <summary>
101+
/// Invoked when the visibility of the main window has changed. Currently, the plugin will continue to be subscribed even if it is turned off.
102+
/// </summary>
103+
event VisibilityChangedEventHandler VisibilityChanged;
104+
100105
/// <summary>
101106
/// Show message box
102107
/// </summary>

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public void RestartApp()
7575

7676
public bool IsMainWindowVisible() => _mainVM.MainWindowVisibilityStatus;
7777

78+
public event VisibilityChangedEventHandler VisibilityChanged { add => _mainVM.VisibilityChanged += value; remove => _mainVM.VisibilityChanged -= value; }
79+
7880
public void CheckForNewUpdate() => _settingsVM.UpdateApp();
7981

8082
public void SaveAppAllSettings()

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,8 @@ private ResultsViewModel SelectedResults
578578
// because it is more accurate and reliable representation than using Visibility as a condition check
579579
public bool MainWindowVisibilityStatus { get; set; } = true;
580580

581+
public event VisibilityChangedEventHandler VisibilityChanged;
582+
581583
public Visibility SearchIconVisibility { get; set; }
582584

583585
public double MainWindowWidth
@@ -1014,6 +1016,7 @@ public void Show()
10141016
MainWindowOpacity = 1;
10151017

10161018
MainWindowVisibilityStatus = true;
1019+
VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = true });
10171020
});
10181021
}
10191022

@@ -1048,6 +1051,7 @@ public async void Hide()
10481051

10491052
MainWindowVisibilityStatus = false;
10501053
MainWindowVisibility = Visibility.Collapsed;
1054+
VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = false });
10511055
}
10521056

10531057
/// <summary>

0 commit comments

Comments
 (0)