Add sendFailToast arg

This commit is contained in:
VictoriousRaptor 2023-07-11 20:08:22 +08:00
parent 7033bce433
commit 2bb398d95e
2 changed files with 25 additions and 23 deletions

View file

@ -26,37 +26,38 @@ namespace Flow.Launcher.Helper
/// Toggle QuickLook
/// </summary>
/// <param name="path">File path to preview</param>
/// <param name="sendFailToast">Send toast when fails.</param>
/// <returns></returns>
public static async Task<bool> ToggleQuickLookAsync(string path)
public static async Task<bool> ToggleQuickLookAsync(string path, bool sendFailToast = true)
{
if (string.IsNullOrEmpty(path))
return false;
bool success = await SendQuickLookPipeMsgAsync(pipeMessageToggle, path);
if (!success)
if (sendFailToast && !success)
{
ShowQuickLookUnavailableToast();
}
return success;
}
public static async Task<bool> CloseQuickLookAsync()
public static async Task<bool> CloseQuickLookAsync(bool sendFailToast = true)
{
bool success = await SendQuickLookPipeMsgAsync(pipeMessageClose);
if (!success)
if (sendFailToast && !success)
{
ShowQuickLookUnavailableToast();
}
return success;
}
public static async Task<bool> OpenQuickLookAsync(string path)
public static async Task<bool> OpenQuickLookAsync(string path, bool sendFailToast = true)
{
if (string.IsNullOrEmpty(path))
return false;
bool success = await SendQuickLookPipeMsgAsync(pipeMessageInvoke, path);
if (!success)
if (sendFailToast && !success)
{
ShowQuickLookUnavailableToast();
}
@ -69,7 +70,7 @@ namespace Flow.Launcher.Helper
/// <param name="path">File path to preview</param>
/// <param name="sendFailToast">Send notification if fail</param>
/// <returns></returns>
public static async Task<bool> SwitchQuickLookAsync(string path, bool sendFailToast = false)
public static async Task<bool> SwitchQuickLookAsync(string path, bool sendFailToast = true)
{
if (string.IsNullOrEmpty(path))
return false;

View file

@ -612,29 +612,29 @@ namespace Flow.Launcher.ViewModel
}
}
private async Task OpenExternalPreviewAsync(string path)
private async Task OpenExternalPreviewAsync(string path, bool sendFailToast = true)
{
bool success = await QuickLookHelper.OpenQuickLookAsync(path).ConfigureAwait(false);
if (success)
{
ExternalPreviewOpen = true;
}
}
private async Task CloseExternalPreviewAsync()
{
bool success = await QuickLookHelper.CloseQuickLookAsync().ConfigureAwait(false);
bool success = await QuickLookHelper.OpenQuickLookAsync(path, sendFailToast).ConfigureAwait(false);
if (success)
{
ExternalPreviewOpen = false;
}
}
private async Task SwitchExternalPreviewAsync(string path)
private async Task CloseExternalPreviewAsync(bool sendFailToast = true)
{
bool success = await QuickLookHelper.CloseQuickLookAsync(sendFailToast).ConfigureAwait(false);
if (success)
{
ExternalPreviewOpen = false;
}
}
private async Task SwitchExternalPreviewAsync(string path, bool sendFailToast = true)
{
// Switches preview content
// When external is off, do nothing
_ = QuickLookHelper.SwitchQuickLookAsync(path).ConfigureAwait(false);
_ = QuickLookHelper.SwitchQuickLookAsync(path, sendFailToast).ConfigureAwait(false);
}
private void ShowInternalPreview()
@ -672,7 +672,7 @@ namespace Flow.Launcher.ViewModel
{
if (CanExternalPreviewSelectedResult(out var path))
{
_ = SwitchExternalPreviewAsync(path);
_ = SwitchExternalPreviewAsync(path, false);
}
else
{
@ -1090,7 +1090,8 @@ namespace Flow.Launcher.ViewModel
// Trick for no delay
MainWindowOpacity = 0;
_ = CloseExternalPreviewAsync();
if (Settings.UseExternalPreview)
_ = CloseExternalPreviewAsync(false);
if (!SelectedIsFromQueryResults())
{