Skip to content

Commit 3fcae23

Browse files
committed
move plugin install/uninstall/update calls from View to ViewModel
1 parent 8dd24de commit 3fcae23

File tree

2 files changed

+33
-37
lines changed

2 files changed

+33
-37
lines changed

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,32 @@ private void OnExternalPluginInstallClick(object sender, RoutedEventArgs e)
312312
{
313313
if (sender is Button { DataContext: PluginStoreItemViewModel plugin })
314314
{
315-
var pluginsManagerPlugin = PluginManager.GetPluginForId("9f8f9b14-2518-4907-b211-35ab6290dee7");
316-
var actionKeyword = pluginsManagerPlugin.Metadata.ActionKeywords.Count == 0 ? "" : pluginsManagerPlugin.Metadata.ActionKeywords[0];
317-
API.ChangeQuery($"{actionKeyword} install {plugin.Name}");
318-
API.ShowMainWindow();
315+
viewModel.DisplayPluginQuery($"install {plugin.Name}", PluginManager.GetPluginForId("9f8f9b14-2518-4907-b211-35ab6290dee7"));
319316
}
320317
}
321318

319+
private void OnExternalPluginUninstallClick(object sender, MouseButtonEventArgs e)
320+
{
321+
if (e.ChangedButton == MouseButton.Left)
322+
{
323+
var name = viewModel.SelectedPlugin.PluginPair.Metadata.Name;
324+
viewModel.DisplayPluginQuery($"uninstall {name}", PluginManager.GetPluginForId("9f8f9b14-2518-4907-b211-35ab6290dee7"));
325+
}
326+
327+
}
328+
329+
private void OnExternalPluginUninstallClick(object sender, RoutedEventArgs e)
330+
{
331+
if (sender is Button { DataContext: PluginStoreItemViewModel plugin })
332+
viewModel.DisplayPluginQuery($"uninstall {plugin.Name}", PluginManager.GetPluginForId("9f8f9b14-2518-4907-b211-35ab6290dee7"));
333+
}
334+
335+
private void OnExternalPluginUpdateClick(object sender, RoutedEventArgs e)
336+
{
337+
if (sender is Button { DataContext: PluginStoreItemViewModel plugin })
338+
viewModel.DisplayPluginQuery($"update {plugin.Name}", PluginManager.GetPluginForId("9f8f9b14-2518-4907-b211-35ab6290dee7"));
339+
}
340+
322341
private void window_MouseDown(object sender, MouseButtonEventArgs e) /* for close hotkey popup */
323342
{
324343
if (Keyboard.FocusedElement is not TextBox textBox)
@@ -477,39 +496,6 @@ public double WindowTop()
477496
var top = (dip2.Y - this.ActualHeight) / 2 + dip1.Y - 20;
478497
return top;
479498
}
480-
private void OnExternalPluginUninstallClick(object sender, MouseButtonEventArgs e)
481-
{
482-
if (e.ChangedButton == MouseButton.Left)
483-
{
484-
var id = viewModel.SelectedPlugin.PluginPair.Metadata.Name;
485-
var pluginsManagerPlugin = PluginManager.GetPluginForId("9f8f9b14-2518-4907-b211-35ab6290dee7");
486-
var actionKeyword = pluginsManagerPlugin.Metadata.ActionKeywords.Count == 0 ? "" : pluginsManagerPlugin.Metadata.ActionKeywords[0];
487-
API.ChangeQuery($"{actionKeyword} uninstall {id}");
488-
API.ShowMainWindow();
489-
}
490-
491-
}
492-
493-
private void OnExternalPluginUninstallClick(object sender, RoutedEventArgs e)
494-
{
495-
if (sender is Button { DataContext: PluginStoreItemViewModel plugin })
496-
{
497-
var pluginsManagerPlugin = PluginManager.GetPluginForId("9f8f9b14-2518-4907-b211-35ab6290dee7");
498-
var actionKeyword = pluginsManagerPlugin.Metadata.ActionKeywords.Count == 0 ? "" : pluginsManagerPlugin.Metadata.ActionKeywords[0];
499-
API.ChangeQuery($"{actionKeyword} uninstall {plugin.Name}");
500-
API.ShowMainWindow();
501-
}
502-
}
503499

504-
private void OnExternalPluginUpdateClick(object sender, RoutedEventArgs e)
505-
{
506-
if (sender is Button { DataContext: PluginStoreItemViewModel plugin })
507-
{
508-
var pluginsManagerPlugin = PluginManager.GetPluginForId("9f8f9b14-2518-4907-b211-35ab6290dee7");
509-
var actionKeyword = pluginsManagerPlugin.Metadata.ActionKeywords.Count == 0 ? "" : pluginsManagerPlugin.Metadata.ActionKeywords[0];
510-
API.ChangeQuery($"{actionKeyword} update {plugin.Name}");
511-
API.ShowMainWindow();
512-
}
513-
}
514500
}
515501
}

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,16 @@ public async Task RefreshExternalPluginsAsync()
321321
OnPropertyChanged(nameof(ExternalPlugins));
322322
}
323323

324+
internal void DisplayPluginQuery(string queryToDisplay, PluginPair plugin, int actionKeywordPosition = 0)
325+
{
326+
var actionKeyword = plugin.Metadata.ActionKeywords.Count == 0
327+
? string.Empty
328+
: plugin.Metadata.ActionKeywords[actionKeywordPosition];
329+
330+
App.API.ChangeQuery($"{actionKeyword} {queryToDisplay}");
331+
App.API.ShowMainWindow();
332+
}
333+
324334

325335
#endregion
326336

0 commit comments

Comments
 (0)