Skip to content

Commit 28ac929

Browse files
committed
Add forceShown param to ShowMsg and refactor notifications
Added forceShown to ShowMsg in IPublicAPI and updated PublicAPIInstance to support forced notifications. Error messages now always show regardless of user settings. Simplified ShowMsgWithButton to always display. Changed _saveSettingsLock to Lock type and made minor formatting improvements.
1 parent 468d52a commit 28ac929

2 files changed

Lines changed: 22 additions & 16 deletions

File tree

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ public interface IPublicAPI
136136
/// <param name="useMainWindowAsOwner">when true will use main windows as the owner</param>
137137
void ShowMsg(string title, string subTitle, string iconPath, bool useMainWindowAsOwner = true);
138138

139+
/// <summary>
140+
/// Show message box
141+
/// </summary>
142+
/// <param name="title">Message title</param>
143+
/// <param name="subTitle">Message subtitle</param>
144+
/// <param name="iconPath">Message icon path (relative path to your plugin folder)</param>
145+
/// <param name="useMainWindowAsOwner">when true will use main windows as the owner</param>
146+
/// <param name="forceShown">when true will force the message to be shown regardless of user settings of `Show more notifications`</param>
147+
void ShowMsg(string title, string subTitle, string iconPath, bool useMainWindowAsOwner = true, bool forceShown = false);
148+
139149
/// <summary>
140150
/// Show message box with button
141151
/// </summary>
@@ -162,7 +172,6 @@ public interface IPublicAPI
162172
/// </summary>
163173
void OpenSettingDialog();
164174

165-
166175
/// <summary>
167176
/// Open plugin setting window for a specific plugin.
168177
/// Reuses the existing window when that plugin's settings window is already open.

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Collections.Specialized;
@@ -53,7 +53,7 @@ public class PublicAPIInstance : IPublicAPI, IRemovable
5353
private Updater _updater;
5454
private Updater Updater => _updater ??= Ioc.Default.GetRequiredService<Updater>();
5555

56-
private readonly object _saveSettingsLock = new();
56+
private readonly Lock _saveSettingsLock = new();
5757

5858
#region Constructor
5959

@@ -119,17 +119,20 @@ public void SaveAppAllSettings()
119119
public Task ReloadAllPluginData() => PluginManager.ReloadDataAsync();
120120

121121
public void ShowMsgError(string title, string subTitle = "") =>
122-
ShowMsg(title, subTitle, Constant.ErrorIcon, true);
122+
ShowMsg(title, subTitle, Constant.ErrorIcon, forceShown:true);
123123

124124
public void ShowMsgErrorWithButton(string title, string buttonText, Action buttonAction, string subTitle = "") =>
125-
ShowMsgWithButton(title, buttonText, buttonAction, subTitle, Constant.ErrorIcon, true);
125+
ShowMsgWithButton(title, buttonText, buttonAction, subTitle, Constant.ErrorIcon);
126126

127127
public void ShowMsg(string title, string subTitle = "", string iconPath = "") =>
128-
ShowMsg(title, subTitle, iconPath, true);
128+
ShowMsg(title, subTitle, iconPath);
129129

130-
public void ShowMsg(string title, string subTitle, string iconPath, bool useMainWindowAsOwner = true)
130+
public void ShowMsg(string title, string subTitle, string iconPath, bool useMainWindowAsOwner = true) =>
131+
ShowMsg(title, subTitle, iconPath, useMainWindowAsOwner:useMainWindowAsOwner);
132+
133+
public void ShowMsg(string title, string subTitle, string iconPath, bool useMainWindowAsOwner = true, bool forceShown = false)
131134
{
132-
if (!_settings.EnableSuccessNotification &&
135+
if (!forceShown && !_settings.EnableSuccessNotification &&
133136
!string.Equals(iconPath, Constant.ErrorIcon, StringComparison.OrdinalIgnoreCase))
134137
{
135138
return;
@@ -139,16 +142,10 @@ public void ShowMsg(string title, string subTitle, string iconPath, bool useMain
139142
}
140143

141144
public void ShowMsgWithButton(string title, string buttonText, Action buttonAction, string subTitle = "", string iconPath = "") =>
142-
ShowMsgWithButton(title, buttonText, buttonAction, subTitle, iconPath, true);
145+
ShowMsgWithButton(title, buttonText, buttonAction, subTitle, iconPath);
143146

144147
public void ShowMsgWithButton(string title, string buttonText, Action buttonAction, string subTitle, string iconPath, bool useMainWindowAsOwner = true)
145-
{
146-
if (!_settings.EnableSuccessNotification &&
147-
!string.Equals(iconPath, Constant.ErrorIcon, StringComparison.OrdinalIgnoreCase))
148-
{
149-
return;
150-
}
151-
148+
{
152149
Notification.ShowWithButton(title, buttonText, buttonAction, subTitle, iconPath);
153150
}
154151

0 commit comments

Comments
 (0)