Merge pull request #2216 from Odotocodot/feature/VisibilityChanged

Add Plugin API -> VisibilityChangedEventHandler
This commit is contained in:
Jeremy Wu 2023-07-10 13:04:29 +09:30 committed by GitHub
commit 0429cefa05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 2 deletions

View file

@ -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
/// <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>

View file

@ -96,7 +96,12 @@ namespace Flow.Launcher.Plugin
/// </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>

View file

@ -75,6 +75,8 @@ namespace Flow.Launcher
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()

View file

@ -578,6 +578,8 @@ namespace Flow.Launcher.ViewModel
// 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 @@ namespace Flow.Launcher.ViewModel
MainWindowOpacity = 1;
MainWindowVisibilityStatus = true;
VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = true });
});
}
@ -1048,6 +1051,7 @@ namespace Flow.Launcher.ViewModel
MainWindowVisibilityStatus = false;
MainWindowVisibility = Visibility.Collapsed;
VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = false });
}
/// <summary>