Skip to content

Commit

Permalink
Merge pull request #2216 from Odotocodot/feature/VisibilityChanged
Browse files Browse the repository at this point in the history
Add Plugin API -> VisibilityChangedEventHandler
  • Loading branch information
jjw24 authored Jul 10, 2023
2 parents 4758ea2 + 4eb20e2 commit 0429cef
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
21 changes: 20 additions & 1 deletion Flow.Launcher.Plugin/EventHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using System;
using System.Windows;
using System.Windows.Input;

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

/// <summary>
/// A delegate for when the visibility is changed
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
public delegate void VisibilityChangedEventHandler(object sender, VisibilityChangedEventArgs args);

/// <summary>
/// The event args for <see cref="VisibilityChangedEventHandler"/>
/// </summary>
public class VisibilityChangedEventArgs : EventArgs
{
/// <summary>
/// <see langword="true"/> if the main window has become visible
/// </summary>
public bool IsVisible { get; init; }
}

/// <summary>
/// Arguments container for the Key Down event
/// </summary>
Expand Down
7 changes: 6 additions & 1 deletion Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ public interface IPublicAPI
/// </summary>
/// <returns></returns>
bool IsMainWindowVisible();


/// <summary>
/// Invoked when the visibility of the main window has changed. Currently, the plugin will continue to be subscribed even if it is turned off.
/// </summary>
event VisibilityChangedEventHandler VisibilityChanged;

/// <summary>
/// Show message box
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions Flow.Launcher/PublicAPIInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1014,6 +1016,7 @@ public void Show()
MainWindowOpacity = 1;
MainWindowVisibilityStatus = true;
VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = true });
});
}

Expand Down Expand Up @@ -1048,6 +1051,7 @@ public async void Hide()

MainWindowVisibilityStatus = false;
MainWindowVisibility = Visibility.Collapsed;
VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = false });
}

/// <summary>
Expand Down

0 comments on commit 0429cef

Please sign in to comment.