Skip to content

Commit f2f4ebf

Browse files
committed
Support home state change & Add ui
1 parent d6704ed commit f2f4ebf

File tree

7 files changed

+78
-2
lines changed

7 files changed

+78
-2
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ public static async Task InitializePluginsAsync()
221221
{
222222
API.LogException(ClassName, $"Fail to Init plugin: {pair.Metadata.Name}", e);
223223
pair.Metadata.Disabled = true;
224+
pair.Metadata.HomeDisabled = true;
224225
failedPlugins.Enqueue(pair);
225226
}
226227
}));
@@ -429,6 +430,11 @@ public static List<Result> GetContextMenusForPlugin(Result result)
429430
return results;
430431
}
431432

433+
public static bool IsHomePlugin(string id)
434+
{
435+
return _homePlugins.Any(p => p.Metadata.ID == id);
436+
}
437+
432438
public static bool ActionKeywordRegistered(string actionKeyword)
433439
{
434440
// this method is only checking for action keywords (defined as not '*') registration

Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public void UpdatePluginSettings(List<PluginMetadata> metadatas)
6767
metadata.Disabled = settings.Disabled;
6868
metadata.Priority = settings.Priority;
6969
metadata.SearchDelayTime = settings.SearchDelayTime;
70+
metadata.HomeDisabled = settings.HomeDiabled;
7071
}
7172
else
7273
{
@@ -79,6 +80,7 @@ public void UpdatePluginSettings(List<PluginMetadata> metadatas)
7980
DefaultActionKeywords = metadata.ActionKeywords, // metadata provides default values
8081
ActionKeywords = metadata.ActionKeywords, // use default value
8182
Disabled = metadata.Disabled,
83+
HomeDiabled = metadata.HomeDisabled,
8284
Priority = metadata.Priority,
8385
DefaultSearchDelayTime = metadata.SearchDelayTime, // metadata provides default values
8486
SearchDelayTime = metadata.SearchDelayTime, // use default value
@@ -128,5 +130,6 @@ public class Plugin
128130
/// Used only to save the state of the plugin in settings
129131
/// </summary>
130132
public bool Disabled { get; set; }
133+
public bool HomeDiabled { get; set; }
131134
}
132135
}

Flow.Launcher.Plugin/PluginMetadata.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public class PluginMetadata : BaseModel
5050
/// </summary>
5151
public bool Disabled { get; set; }
5252

53+
/// <summary>
54+
/// Whether plugin is disabled in home query.
55+
/// </summary>
56+
public bool HomeDisabled { get; set; }
57+
5358
/// <summary>
5459
/// Plugin execute file path.
5560
/// </summary>

Flow.Launcher/Languages/en.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
<system:String x:Key="homePageToolTip">Show home page results when query text is empty.</system:String>
131131
<system:String x:Key="historyResultsForHomePage">Show History Results in Home Page</system:String>
132132
<system:String x:Key="historyResultsCountForHomePage">Maximum History Results Shown in Home Page</system:String>
133+
<system:String x:Key="homeToggleBoxToolTip">This can only be edited if plugin supports Home feature and Home Page is enabled.</system:String>
133134

134135
<!-- Setting Plugin -->
135136
<system:String x:Key="searchplugin">Search Plugin</system:String>
@@ -152,6 +153,7 @@
152153
<system:String x:Key="DisplayModeOnOff">Enabled</system:String>
153154
<system:String x:Key="DisplayModePriority">Priority</system:String>
154155
<system:String x:Key="DisplayModeSearchDelay">Search Delay</system:String>
156+
<system:String x:Key="DisplayModeHomeOnOff">Home Page</system:String>
155157
<system:String x:Key="currentPriority">Current Priority</system:String>
156158
<system:String x:Key="newPriority">New Priority</system:String>
157159
<system:String x:Key="priority">Priority</system:String>
@@ -405,6 +407,10 @@
405407
<system:String x:Key="searchDelayTimeTitle">Search Delay Time Setting</system:String>
406408
<system:String x:Key="searchDelayTimeTips">Input the search delay time in ms you like to use for the plugin. Input empty if you don't want to specify any, and the plugin will use default search delay time.</system:String>
407409

410+
<!-- Search Delay Settings Dialog -->
411+
<system:String x:Key="homeTitle">Home Page</system:String>
412+
<system:String x:Key="homeTips">Enable the plugin home page state if you like to show the plugin results when query is empty.</system:String>
413+
408414
<!-- Custom Query Hotkey Dialog -->
409415
<system:String x:Key="customeQueryHotkeyTitle">Custom Query Hotkey</system:String>
410416
<system:String x:Key="customeQueryHotkeyTips">Press a custom hotkey to open Flow Launcher and input the specified query automatically.</system:String>

Flow.Launcher/Resources/Controls/InstalledPluginDisplay.xaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,19 @@
100100
ToolTipService.InitialShowDelay="0"
101101
ToolTipService.ShowOnDisabled="True"
102102
Value="{Binding PluginSearchDelayTime, Mode=TwoWay}" />
103-
104103
</StackPanel>
105104

106105
<!-- Put OnOffControl after PriorityControl & SearchDelayControl so that it can display correctly -->
106+
<ui:ToggleSwitch
107+
x:Name="HomeOnOffControl"
108+
Margin="0 0 8 0"
109+
IsEnabled="{Binding HomeEnabled}"
110+
IsOn="{Binding PluginHomeState}"
111+
OffContent="{DynamicResource disable}"
112+
OnContent="{DynamicResource enable}"
113+
ToolTip="{DynamicResource homeToggleBoxToolTip}"
114+
Visibility="{Binding DataContext.IsHomeOnOffSelected, RelativeSource={RelativeSource AncestorType=ListBox}, Converter={StaticResource BooleanToVisibilityConverter}}" />
115+
107116
<ui:ToggleSwitch
108117
x:Name="OnOffControl"
109118
Margin="0 0 8 0"

Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ public bool IsSearchDelaySelected
8080
}
8181
}
8282

83+
private bool _isHomeOnOffSelected;
84+
public bool IsHomeOnOffSelected
85+
{
86+
get => _isHomeOnOffSelected;
87+
set
88+
{
89+
if (_isHomeOnOffSelected != value)
90+
{
91+
_isHomeOnOffSelected = value;
92+
OnPropertyChanged();
93+
}
94+
}
95+
}
96+
8397
public SettingsPanePluginsViewModel(Settings settings)
8498
{
8599
_settings = settings;
@@ -152,6 +166,18 @@ private async Task OpenHelperAsync(Button button)
152166
{
153167
Text = (string)Application.Current.Resources["searchDelayTimeTips"],
154168
TextWrapping = TextWrapping.Wrap
169+
},
170+
new TextBlock
171+
{
172+
Text = (string)Application.Current.Resources["homeTitle"],
173+
FontSize = 18,
174+
Margin = new Thickness(0, 24, 0, 10),
175+
TextWrapping = TextWrapping.Wrap
176+
},
177+
new TextBlock
178+
{
179+
Text = (string)Application.Current.Resources["homeTips"],
180+
TextWrapping = TextWrapping.Wrap
155181
}
156182
}
157183
},
@@ -176,16 +202,25 @@ private void UpdateDisplayModeFromSelection()
176202
IsOnOffSelected = false;
177203
IsPrioritySelected = true;
178204
IsSearchDelaySelected = false;
205+
IsHomeOnOffSelected = false;
179206
break;
180207
case DisplayMode.SearchDelay:
181208
IsOnOffSelected = false;
182209
IsPrioritySelected = false;
183210
IsSearchDelaySelected = true;
211+
IsHomeOnOffSelected = false;
212+
break;
213+
case DisplayMode.HomeOnOff:
214+
IsOnOffSelected = false;
215+
IsPrioritySelected = false;
216+
IsSearchDelaySelected = false;
217+
IsHomeOnOffSelected = true;
184218
break;
185219
default:
186220
IsOnOffSelected = true;
187221
IsPrioritySelected = false;
188222
IsSearchDelaySelected = false;
223+
IsHomeOnOffSelected = false;
189224
break;
190225
}
191226
}
@@ -195,5 +230,6 @@ public enum DisplayMode
195230
{
196231
OnOff,
197232
Priority,
198-
SearchDelay
233+
SearchDelay,
234+
HomeOnOff
199235
}

Flow.Launcher/ViewModel/PluginViewModel.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ public bool PluginState
7575
}
7676
}
7777

78+
public bool PluginHomeState
79+
{
80+
get => !PluginPair.Metadata.HomeDisabled;
81+
set
82+
{
83+
PluginPair.Metadata.HomeDisabled = !value;
84+
PluginSettingsObject.HomeDiabled = !value;
85+
}
86+
}
87+
7888
public bool IsExpanded
7989
{
8090
get => _isExpanded;
@@ -154,6 +164,7 @@ public Control SettingControl
154164
public Infrastructure.UserSettings.Plugin PluginSettingsObject{ get; init; }
155165
public bool SearchDelayEnabled => Settings.SearchQueryResultsWithDelay;
156166
public string DefaultSearchDelay => Settings.SearchDelayTime.ToString();
167+
public bool HomeEnabled => Settings.ShowHomePage && PluginManager.IsHomePlugin(PluginPair.Metadata.ID);
157168

158169
public void OnActionKeywordsTextChanged()
159170
{

0 commit comments

Comments
 (0)