Merge branch 'dev' into search_delay

This commit is contained in:
Jack Ye 2025-03-18 07:38:04 +08:00 committed by GitHub
commit 35617e9be9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 670 additions and 227 deletions

View file

@ -58,9 +58,9 @@
</Button>
</Grid>
</StackPanel>
<StackPanel Margin="26,0,26,0">
<StackPanel Margin="26 0 26 0">
<TextBlock
Margin="0,0,0,12"
Margin="0 0 0 12"
FontSize="20"
FontWeight="SemiBold"
Text="{DynamicResource customeQueryHotkeyTitle}"
@ -72,10 +72,10 @@
TextWrapping="WrapWithOverflow" />
<Image
Width="478"
Margin="0,20,0,0"
Margin="0 20 0 0"
Source="/Images/illustration_01.png" />
<Grid Width="478" Margin="0,20,0,0">
<Grid Width="478" Margin="0 20 0 0">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
@ -99,11 +99,12 @@
Grid.Row="0"
Grid.Column="1"
Grid.ColumnSpan="2"
Margin="10,0,10,0"
Margin="10 0 10 0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
HorizontalContentAlignment="Left"
DefaultHotkey="" />
DefaultHotkey=""
Type="CustomQueryHotkey" />
<TextBlock
Grid.Row="1"
Grid.Column="0"
@ -123,8 +124,8 @@
x:Name="btnTestActionKeyword"
Grid.Row="1"
Grid.Column="2"
Margin="0,0,10,0"
Padding="10,5,10,5"
Margin="0 0 10 0"
Padding="10 5 10 5"
Click="BtnTestActionKeyword_OnClick"
Content="{DynamicResource preview}" />
</Grid>
@ -132,21 +133,21 @@
</StackPanel>
<Border
Grid.Row="1"
Margin="0,14,0,0"
Margin="0 14 0 0"
Background="{DynamicResource PopupButtonAreaBGColor}"
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}"
BorderThickness="0,1,0,0">
BorderThickness="0 1 0 0">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<Button
x:Name="btnCancel"
MinWidth="140"
Margin="10,0,5,0"
Margin="10 0 5 0"
Click="BtnCancel_OnClick"
Content="{DynamicResource cancel}" />
<Button
x:Name="btnAdd"
MinWidth="140"
Margin="5,0,10,0"
Margin="5 0 10 0"
Click="btnAdd_OnClick"
Style="{StaticResource AccentButtonStyle}">
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" />

View file

@ -84,7 +84,7 @@ namespace Flow.Launcher
nameof(Type),
typeof(HotkeyType),
typeof(HotkeyControl),
new FrameworkPropertyMetadata(HotkeyType.Hotkey, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnHotkeyChanged)
new FrameworkPropertyMetadata(HotkeyType.None, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnHotkeyChanged)
);
public HotkeyType Type
@ -95,6 +95,10 @@ namespace Flow.Launcher
public enum HotkeyType
{
None,
// Custom query hotkeys
CustomQueryHotkey,
// Settings hotkeys
Hotkey,
PreviewHotkey,
OpenContextMenuHotkey,
@ -115,12 +119,16 @@ namespace Flow.Launcher
// and it will not construct settings instances twice
private static readonly Settings _settings = Ioc.Default.GetRequiredService<Settings>();
private string hotkey = string.Empty;
public string Hotkey
{
get
{
return Type switch
{
// Custom query hotkeys
HotkeyType.CustomQueryHotkey => hotkey,
// Settings hotkeys
HotkeyType.Hotkey => _settings.Hotkey,
HotkeyType.PreviewHotkey => _settings.PreviewHotkey,
HotkeyType.OpenContextMenuHotkey => _settings.OpenContextMenuHotkey,
@ -135,13 +143,20 @@ namespace Flow.Launcher
HotkeyType.SelectPrevItemHotkey2 => _settings.SelectPrevItemHotkey2,
HotkeyType.SelectNextItemHotkey => _settings.SelectNextItemHotkey,
HotkeyType.SelectNextItemHotkey2 => _settings.SelectNextItemHotkey2,
_ => string.Empty
_ => throw new System.NotImplementedException("Hotkey type not set")
};
}
set
{
switch (Type)
{
// Custom query hotkeys
case HotkeyType.CustomQueryHotkey:
// We just need to store it in a local field
// because we will save to settings in other place
hotkey = value;
break;
// Settings hotkeys
case HotkeyType.Hotkey:
_settings.Hotkey = value;
break;
@ -185,7 +200,7 @@ namespace Flow.Launcher
_settings.SelectNextItemHotkey2 = value;
break;
default:
return;
throw new System.NotImplementedException("Hotkey type not set");
}
// After setting the hotkey, we need to refresh the interface

View file

@ -331,7 +331,6 @@
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
StrokeThickness="2"
Style="{DynamicResource PendingLineStyle}"
Visibility="{Binding ProgressBarVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
X1="-100"
X2="0"
@ -377,8 +376,8 @@
HorizontalAlignment="Stretch"
Style="{DynamicResource SeparatorStyle}" />
</ContentControl>
</Grid>
<Border Style="{DynamicResource WindowRadius}">
<Border.Clip>
<MultiBinding Converter="{StaticResource BorderClipConverter}">

View file

@ -27,6 +27,7 @@ using System.Windows.Media;
using System.Windows.Interop;
using Windows.Win32;
using System.Reactive.Linq;
using System.Windows.Shapes;
namespace Flow.Launcher
{
@ -34,8 +35,6 @@ namespace Flow.Launcher
{
#region Private Fields
private readonly Storyboard _progressBarStoryboard = new Storyboard();
private bool isProgressBarStoryboardPaused;
private Settings _settings;
private NotifyIcon _notifyIcon;
private ContextMenu contextMenu = new ContextMenu();
@ -63,7 +62,7 @@ namespace Flow.Launcher
DataObject.AddPastingHandler(QueryTextBox, OnPaste);
this.Loaded += (_, _) =>
Loaded += (_, _) =>
{
var handle = new WindowInteropHelper(this).Handle;
var win = HwndSource.FromHwnd(handle);
@ -71,13 +70,6 @@ namespace Flow.Launcher
};
}
DispatcherTimer timer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 500), IsEnabled = false };
public MainWindow()
{
InitializeComponent();
}
private int _initialWidth;
private int _initialHeight;
@ -242,27 +234,13 @@ namespace Flow.Launcher
_progressBarStoryboard.Stop(ProgressBar);
isProgressBarStoryboardPaused = true;
}
});
break;
}
case nameof(MainViewModel.ProgressBarVisibility):
{
Dispatcher.Invoke(() =>
{
if (_viewModel.ProgressBarVisibility == Visibility.Hidden && !isProgressBarStoryboardPaused)
{
_progressBarStoryboard.Stop(ProgressBar);
isProgressBarStoryboardPaused = true;
}
else if (_viewModel.MainWindowVisibilityStatus &&
isProgressBarStoryboardPaused)
{
_progressBarStoryboard.Begin(ProgressBar, true);
isProgressBarStoryboardPaused = false;
}
});
break;
}
if (_settings.UseAnimation)
WindowAnimator();
}
});
break;
}
case nameof(MainViewModel.QueryTextCursorMovedToEnd):
if (_viewModel.QueryTextCursorMovedToEnd)
{
@ -370,7 +348,6 @@ namespace Flow.Launcher
Icon = Constant.Version == "1.0.0" ? Properties.Resources.dev : Properties.Resources.app,
Visible = !_settings.HideNotifyIcon
};
var openIcon = new FontIcon { Glyph = "\ue71e" };
var open = new MenuItem
{
@ -381,7 +358,8 @@ namespace Flow.Launcher
var gamemodeIcon = new FontIcon { Glyph = "\ue7fc" };
var gamemode = new MenuItem
{
Header = InternationalizationManager.Instance.GetTranslation("GameMode"), Icon = gamemodeIcon
Header = InternationalizationManager.Instance.GetTranslation("GameMode"),
Icon = gamemodeIcon
};
var positionresetIcon = new FontIcon { Glyph = "\ue73f" };
var positionreset = new MenuItem
@ -398,7 +376,8 @@ namespace Flow.Launcher
var exitIcon = new FontIcon { Glyph = "\ue7e8" };
var exit = new MenuItem
{
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"), Icon = exitIcon
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"),
Icon = exitIcon
};
open.Click += (o, e) => _viewModel.ToggleFlowLauncher();
@ -465,17 +444,49 @@ namespace Flow.Launcher
private void InitProgressbarAnimation()
{
var progressBarStoryBoard = new Storyboard();
var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100,
new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth + 0,
new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
_progressBarStoryboard.Children.Add(da);
_progressBarStoryboard.Children.Add(da1);
_progressBarStoryboard.RepeatBehavior = RepeatBehavior.Forever;
progressBarStoryBoard.Children.Add(da);
progressBarStoryBoard.Children.Add(da1);
progressBarStoryBoard.RepeatBehavior = RepeatBehavior.Forever;
da.Freeze();
da1.Freeze();
const string progressBarAnimationName = "ProgressBarAnimation";
var beginStoryboard = new BeginStoryboard
{
Name = progressBarAnimationName, Storyboard = progressBarStoryBoard
};
var stopStoryboard = new StopStoryboard()
{
BeginStoryboardName = progressBarAnimationName
};
var trigger = new Trigger
{
Property = VisibilityProperty, Value = Visibility.Visible
};
trigger.EnterActions.Add(beginStoryboard);
trigger.ExitActions.Add(stopStoryboard);
var progressStyle = new Style(typeof(Line))
{
BasedOn = FindResource("PendingLineStyle") as Style
};
progressStyle.RegisterName(progressBarAnimationName, beginStoryboard);
progressStyle.Triggers.Add(trigger);
ProgressBar.Style = progressStyle;
_viewModel.ProgressBarVisibility = Visibility.Hidden;
isProgressBarStoryboardPaused = true;
}
public void WindowAnimator()

View file

@ -1,6 +1,8 @@
using System;
using System.Windows.Navigation;
using System.Windows.Navigation;
using Flow.Launcher.Core;
using Flow.Launcher.SettingPages.ViewModels;
using Flow.Launcher.Infrastructure.UserSettings;
using CommunityToolkit.Mvvm.DependencyInjection;
namespace Flow.Launcher.SettingPages.Views;
@ -12,8 +14,8 @@ public partial class SettingsPaneAbout
{
if (!IsInitialized)
{
if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings, Updater: { } updater })
throw new ArgumentException("Settings are required for SettingsPaneAbout.");
var settings = Ioc.Default.GetRequiredService<Settings>();
var updater = Ioc.Default.GetRequiredService<Updater>();
_viewModel = new SettingsPaneAboutViewModel(settings, updater);
DataContext = _viewModel;
InitializeComponent();

View file

@ -1,5 +1,7 @@
using System;
using System.Windows.Navigation;
using System.Windows.Navigation;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Core;
using Flow.Launcher.Core.Configuration;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.SettingPages.ViewModels;
@ -13,8 +15,9 @@ public partial class SettingsPaneGeneral
{
if (!IsInitialized)
{
if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings, Updater: {} updater, Portable: {} portable })
throw new ArgumentException("Settings, Updater and Portable are required for SettingsPaneGeneral.");
var settings = Ioc.Default.GetRequiredService<Settings>();
var updater = Ioc.Default.GetRequiredService<Updater>();
var portable = Ioc.Default.GetRequiredService<Portable>();
_viewModel = new SettingsPaneGeneralViewModel(settings, updater, portable);
DataContext = _viewModel;
InitializeComponent();

View file

@ -1,6 +1,7 @@
using System;
using System.Windows.Navigation;
using System.Windows.Navigation;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.SettingPages.ViewModels;
using Flow.Launcher.Infrastructure.UserSettings;
namespace Flow.Launcher.SettingPages.Views;
@ -12,8 +13,7 @@ public partial class SettingsPaneHotkey
{
if (!IsInitialized)
{
if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings })
throw new ArgumentException("Settings are required for SettingsPaneHotkey.");
var settings = Ioc.Default.GetRequiredService<Settings>();
_viewModel = new SettingsPaneHotkeyViewModel(settings);
DataContext = _viewModel;
InitializeComponent();

View file

@ -1,10 +1,11 @@
using System;
using System.ComponentModel;
using System.ComponentModel;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Navigation;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.SettingPages.ViewModels;
using Flow.Launcher.ViewModel;
using Flow.Launcher.Infrastructure.UserSettings;
namespace Flow.Launcher.SettingPages.Views;
@ -16,8 +17,7 @@ public partial class SettingsPanePluginStore
{
if (!IsInitialized)
{
if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings })
throw new ArgumentException($"Settings are required for {nameof(SettingsPanePluginStore)}.");
var settings = Ioc.Default.GetRequiredService<Settings>();
_viewModel = new SettingsPanePluginStoreViewModel();
DataContext = _viewModel;
InitializeComponent();

View file

@ -1,7 +1,8 @@
using System;
using System.Windows.Input;
using System.Windows.Input;
using System.Windows.Navigation;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.SettingPages.ViewModels;
using Flow.Launcher.Infrastructure.UserSettings;
namespace Flow.Launcher.SettingPages.Views;
@ -13,8 +14,7 @@ public partial class SettingsPanePlugins
{
if (!IsInitialized)
{
if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings })
throw new ArgumentException("Settings are required for SettingsPaneHotkey.");
var settings = Ioc.Default.GetRequiredService<Settings>();
_viewModel = new SettingsPanePluginsViewModel(settings);
DataContext = _viewModel;
InitializeComponent();

View file

@ -1,6 +1,8 @@
using System;
using System.Windows.Navigation;
using System.Windows.Navigation;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Core;
using Flow.Launcher.SettingPages.ViewModels;
using Flow.Launcher.Infrastructure.UserSettings;
namespace Flow.Launcher.SettingPages.Views;
@ -12,8 +14,8 @@ public partial class SettingsPaneProxy
{
if (!IsInitialized)
{
if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings, Updater: { } updater })
throw new ArgumentException($"Settings are required for {nameof(SettingsPaneProxy)}.");
var settings = Ioc.Default.GetRequiredService<Settings>();
var updater = Ioc.Default.GetRequiredService<Updater>();
_viewModel = new SettingsPaneProxyViewModel(settings, updater);
DataContext = _viewModel;
InitializeComponent();

View file

@ -1,10 +1,9 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows.Navigation;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.SettingPages.ViewModels;
using Page = ModernWpf.Controls.Page;
using Flow.Launcher.Infrastructure.UserSettings;
namespace Flow.Launcher.SettingPages.Views;
@ -16,8 +15,7 @@ public partial class SettingsPaneTheme : Page
{
if (!IsInitialized)
{
if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings })
throw new ArgumentException($"Settings are required for {nameof(SettingsPaneTheme)}.");
var settings = Ioc.Default.GetRequiredService<Settings>();
_viewModel = new SettingsPaneThemeViewModel(settings);
DataContext = _viewModel;
InitializeComponent();

View file

@ -4,8 +4,6 @@ using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Interop;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Core;
using Flow.Launcher.Core.Configuration;
using Flow.Launcher.Helper;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
@ -18,8 +16,6 @@ namespace Flow.Launcher;
public partial class SettingWindow
{
private readonly Updater _updater;
private readonly IPortable _portable;
private readonly IPublicAPI _api;
private readonly Settings _settings;
private readonly SettingWindowViewModel _viewModel;
@ -30,8 +26,6 @@ public partial class SettingWindow
_settings = Ioc.Default.GetRequiredService<Settings>();
DataContext = viewModel;
_viewModel = viewModel;
_updater = Ioc.Default.GetRequiredService<Updater>();
_portable = Ioc.Default.GetRequiredService<Portable>();
_api = Ioc.Default.GetRequiredService<IPublicAPI>();
InitializePosition();
InitializeComponent();
@ -166,10 +160,9 @@ public partial class SettingWindow
private void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
var paneData = new PaneData(_settings, _updater, _portable);
if (args.IsSettingsSelected)
{
ContentFrame.Navigate(typeof(SettingsPaneGeneral), paneData);
ContentFrame.Navigate(typeof(SettingsPaneGeneral));
}
else
{
@ -191,7 +184,7 @@ public partial class SettingWindow
nameof(About) => typeof(SettingsPaneAbout),
_ => typeof(SettingsPaneGeneral)
};
ContentFrame.Navigate(pageType, paneData);
ContentFrame.Navigate(pageType);
}
}
@ -211,6 +204,4 @@ public partial class SettingWindow
{
NavView.SelectedItem ??= NavView.MenuItems[0]; /* Set First Page */
}
public record PaneData(Settings Settings, Updater Updater, IPortable Portable);
}

View file

@ -0,0 +1,44 @@
using System.Text.Json.Serialization;
namespace Flow.Launcher.Plugin.Sys
{
public class Command : BaseModel
{
public string Key { get; set; }
private string name;
[JsonIgnore]
public string Name
{
get => name;
set
{
name = value;
OnPropertyChanged();
}
}
private string description;
[JsonIgnore]
public string Description
{
get => description;
set
{
description = value;
OnPropertyChanged();
}
}
private string keyword;
public string Keyword
{
get => keyword;
set
{
keyword = value;
OnPropertyChanged();
}
}
}
}

View file

@ -0,0 +1,121 @@
<Window
x:Class="Flow.Launcher.Plugin.Sys.CommandKeywordSettingWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="{DynamicResource lowlauncher_plugin_sys_command_keyword_setting_window_title}"
Width="550"
Background="{DynamicResource PopupBGColor}"
Foreground="{DynamicResource PopupTextColor}"
ResizeMode="NoResize"
SizeToContent="Height"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="32" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
</WindowChrome.WindowChrome>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="80" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button
Grid.Column="1"
Click="OnCancelButtonClick"
Style="{StaticResource TitleBarCloseButtonStyle}">
<Path
Width="46"
Height="32"
Data="M 18,11 27,20 M 18,20 27,11"
Stroke="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}"
StrokeThickness="1">
<Path.Style>
<Style TargetType="Path">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Value="False">
<Setter Property="Opacity" Value="0.5" />
</DataTrigger>
</Style.Triggers>
</Style>
</Path.Style>
</Path>
</Button>
</Grid>
</StackPanel>
<StackPanel Margin="26 12 26 0">
<StackPanel Margin="0 0 0 12">
<TextBlock
Grid.Column="0"
Margin="0 0 0 0"
FontSize="20"
FontWeight="SemiBold"
Text="{DynamicResource flowlauncher_plugin_sys_custom_command_keyword}"
TextAlignment="Left" />
</StackPanel>
<StackPanel>
<TextBlock
x:Name="CommandKeywordTips"
FontSize="14"
TextAlignment="Left"
TextWrapping="WrapWithOverflow" />
</StackPanel>
<Grid Margin="0 24 0 24">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Column="0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource flowlauncher_plugin_sys_command_keyword}" />
<TextBox
x:Name="CommandKeyword"
Grid.Column="1"
Margin="10"
HorizontalAlignment="Stretch" />
<Button
x:Name="btnTestActionKeyword"
Grid.Row="1"
Grid.Column="2"
Margin="0 0 10 0"
Padding="10 5 10 5"
Click="OnResetButtonClick"
Content="{DynamicResource flowlauncher_plugin_sys_reset}" />
</Grid>
</StackPanel>
</StackPanel>
<Border
Grid.Row="1"
Background="{DynamicResource PopupButtonAreaBGColor}"
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}"
BorderThickness="0 1 0 0">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<Button
MinWidth="140"
Margin="10 0 5 0"
Click="OnCancelButtonClick"
Content="{DynamicResource flowlauncher_plugin_sys_cancel}" />
<Button
MinWidth="140"
Margin="5 0 10 0"
Click="OnConfirmButtonClick"
Content="{DynamicResource flowlauncher_plugin_sys_confirm}"
Style="{DynamicResource AccentButtonStyle}" />
</StackPanel>
</Border>
</Grid>
</Window>

View file

@ -0,0 +1,45 @@
using System.Windows;
namespace Flow.Launcher.Plugin.Sys
{
public partial class CommandKeywordSettingWindow
{
private readonly Command _oldSearchSource;
private readonly PluginInitContext _context;
public CommandKeywordSettingWindow(PluginInitContext context, Command old)
{
_context = context;
_oldSearchSource = old;
InitializeComponent();
CommandKeyword.Text = old.Keyword;
CommandKeywordTips.Text = string.Format(_context.API.GetTranslation("flowlauncher_plugin_sys_custom_command_keyword_tip"), old.Name);
}
private void OnCancelButtonClick(object sender, RoutedEventArgs e)
{
Close();
}
private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
{
var keyword = CommandKeyword.Text;
if (string.IsNullOrEmpty(keyword))
{
var warning = _context.API.GetTranslation("flowlauncher_plugin_sys_input_command_keyword");
_context.API.ShowMsgBox(warning);
}
else
{
_oldSearchSource.Keyword = keyword;
Close();
}
}
private void OnResetButtonClick(object sender, RoutedEventArgs e)
{
// Key is the default value of this command
CommandKeyword.Text = _oldSearchSource.Key;
}
}
}

View file

@ -4,8 +4,9 @@
xmlns:system="clr-namespace:System;assembly=mscorlib">
<!-- Command List -->
<system:String x:Key="flowlauncher_plugin_sys_command">Command</system:String>
<system:String x:Key="flowlauncher_plugin_sys_name">Name</system:String>
<system:String x:Key="flowlauncher_plugin_sys_desc">Description</system:String>
<system:String x:Key="flowlauncher_plugin_sys_command">Command</system:String>
<system:String x:Key="flowlauncher_plugin_sys_shutdown_computer_cmd">Shutdown</system:String>
<system:String x:Key="flowlauncher_plugin_sys_restart_computer_cmd">Restart</system:String>
@ -29,6 +30,8 @@
<system:String x:Key="flowlauncher_plugin_sys_toggle_game_mode_cmd">Toggle Game Mode</system:String>
<system:String x:Key="flowlauncher_plugin_sys_theme_selector_cmd">Set the Flow Launcher Theme</system:String>
<system:String x:Key="flowlauncher_plugin_sys_edit">Edit</system:String>
<!-- Command Descriptions -->
<system:String x:Key="flowlauncher_plugin_sys_shutdown_computer">Shutdown Computer</system:String>
<system:String x:Key="flowlauncher_plugin_sys_restart_computer">Restart Computer</system:String>
@ -61,6 +64,15 @@
<system:String x:Key="flowlauncher_plugin_sys_dlgtext_restart_computer_advanced">Are you sure you want to restart the computer with Advanced Boot Options?</system:String>
<system:String x:Key="flowlauncher_plugin_sys_dlgtext_logoff_computer">Are you sure you want to log off?</system:String>
<system:String x:Key="flowlauncher_plugin_sys_command_keyword_setting_window_title">Command Keyword Setting</system:String>
<system:String x:Key="flowlauncher_plugin_sys_custom_command_keyword">Custom Command Keyword</system:String>
<system:String x:Key="flowlauncher_plugin_sys_custom_command_keyword_tip">Enter a keyword to search for command: {0}. This keyword is used to match your query.</system:String>
<system:String x:Key="flowlauncher_plugin_sys_command_keyword">Command Keyword</system:String>
<system:String x:Key="flowlauncher_plugin_sys_reset">Reset</system:String>
<system:String x:Key="flowlauncher_plugin_sys_confirm">Confirm</system:String>
<system:String x:Key="flowlauncher_plugin_sys_cancel">Cancel</system:String>
<system:String x:Key="flowlauncher_plugin_sys_input_command_keyword">Please enter a non-empty command keyword</system:String>
<system:String x:Key="flowlauncher_plugin_sys_plugin_name">System Commands</system:String>
<system:String x:Key="flowlauncher_plugin_sys_plugin_description">Provides System related commands. e.g. shutdown, lock, settings etc.</system:String>

View file

@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows;
using Flow.Launcher.Infrastructure;
@ -18,43 +20,81 @@ namespace Flow.Launcher.Plugin.Sys
{
public class Main : IPlugin, ISettingProvider, IPluginI18n
{
private PluginInitContext context;
private ThemeSelector themeSelector;
private Dictionary<string, string> KeywordTitleMappings = new Dictionary<string, string>();
private readonly Dictionary<string, string> KeywordTitleMappings = new()
{
{"Shutdown", "flowlauncher_plugin_sys_shutdown_computer_cmd"},
{"Restart", "flowlauncher_plugin_sys_restart_computer_cmd"},
{"Restart With Advanced Boot Options", "flowlauncher_plugin_sys_restart_advanced_cmd"},
{"Log Off/Sign Out", "flowlauncher_plugin_sys_log_off_cmd"},
{"Lock", "flowlauncher_plugin_sys_lock_cmd"},
{"Sleep", "flowlauncher_plugin_sys_sleep_cmd"},
{"Hibernate", "flowlauncher_plugin_sys_hibernate_cmd"},
{"Index Option", "flowlauncher_plugin_sys_indexoption_cmd"},
{"Empty Recycle Bin", "flowlauncher_plugin_sys_emptyrecyclebin_cmd"},
{"Open Recycle Bin", "flowlauncher_plugin_sys_openrecyclebin_cmd"},
{"Exit", "flowlauncher_plugin_sys_exit_cmd"},
{"Save Settings", "flowlauncher_plugin_sys_save_all_settings_cmd"},
{"Restart Flow Launcher", "flowlauncher_plugin_sys_restart_cmd"},
{"Settings", "flowlauncher_plugin_sys_setting_cmd"},
{"Reload Plugin Data", "flowlauncher_plugin_sys_reload_plugin_data_cmd"},
{"Check For Update", "flowlauncher_plugin_sys_check_for_update_cmd"},
{"Open Log Location", "flowlauncher_plugin_sys_open_log_location_cmd"},
{"Flow Launcher Tips", "flowlauncher_plugin_sys_open_docs_tips_cmd"},
{"Flow Launcher UserData Folder", "flowlauncher_plugin_sys_open_userdata_location_cmd"},
{"Toggle Game Mode", "flowlauncher_plugin_sys_toggle_game_mode_cmd"},
{"Set Flow Launcher Theme", "flowlauncher_plugin_sys_theme_selector_cmd"}
};
private readonly Dictionary<string, string> KeywordDescriptionMappings = new();
// SHTDN_REASON_MAJOR_OTHER indicates a generic shutdown reason that isn't categorized under hardware failure, software updates, or other predefined reasons.
// SHTDN_REASON_MAJOR_OTHER indicates a generic shutdown reason that isn't categorized under hardware failure,
// software updates, or other predefined reasons.
// SHTDN_REASON_FLAG_PLANNED marks the shutdown as planned rather than an unexpected shutdown or failure
private const SHUTDOWN_REASON REASON = SHUTDOWN_REASON.SHTDN_REASON_MAJOR_OTHER | SHUTDOWN_REASON.SHTDN_REASON_FLAG_PLANNED;
private const SHUTDOWN_REASON REASON = SHUTDOWN_REASON.SHTDN_REASON_MAJOR_OTHER |
SHUTDOWN_REASON.SHTDN_REASON_FLAG_PLANNED;
private PluginInitContext _context;
private Settings _settings;
private ThemeSelector _themeSelector;
private SettingsViewModel _viewModel;
public Control CreateSettingPanel()
{
var results = Commands();
return new SysSettings(results);
UpdateLocalizedNameDescription(false);
return new SysSettings(_context, _viewModel);
}
public List<Result> Query(Query query)
{
if(query.Search.StartsWith(ThemeSelector.Keyword))
{
return themeSelector.Query(query);
return _themeSelector.Query(query);
}
var commands = Commands();
var results = new List<Result>();
foreach (var c in commands)
{
c.Title = GetDynamicTitle(query, c);
var command = _settings.Commands.First(x => x.Key == c.Title);
c.Title = command.Name;
c.SubTitle = command.Description;
var titleMatch = StringMatcher.FuzzySearch(query.Search, c.Title);
var subTitleMatch = StringMatcher.FuzzySearch(query.Search, c.SubTitle);
// Match from localized title & localized subtitle & keyword
var titleMatch = _context.API.FuzzySearch(query.Search, c.Title);
var subTitleMatch = _context.API.FuzzySearch(query.Search, c.SubTitle);
var keywordMatch = _context.API.FuzzySearch(query.Search, command.Keyword);
// Get the largest score from them
var score = Math.Max(titleMatch.Score, subTitleMatch.Score);
if (score > 0)
var finalScore = Math.Max(score, keywordMatch.Score);
if (finalScore > 0)
{
c.Score = score;
c.Score = finalScore;
if (score == titleMatch.Score)
// If title match has the highest score, highlight title
if (finalScore == titleMatch.Score)
{
c.TitleHighlightData = titleMatch.MatchData;
}
results.Add(c);
}
@ -63,54 +103,51 @@ namespace Flow.Launcher.Plugin.Sys
return results;
}
private string GetDynamicTitle(Query query, Result result)
private string GetTitle(string key)
{
if (!KeywordTitleMappings.TryGetValue(result.Title, out var translationKey))
if (!KeywordTitleMappings.TryGetValue(key, out var translationKey))
{
Log.Error("Flow.Launcher.Plugin.Sys.Main", $"Dynamic Title not found for: {result.Title}");
Log.Error("Flow.Launcher.Plugin.Sys.Main", $"Title not found for: {key}");
return "Title Not Found";
}
var translatedTitle = context.API.GetTranslation(translationKey);
return _context.API.GetTranslation(translationKey);
}
if (result.Title == translatedTitle)
private string GetDescription(string key)
{
if (!KeywordDescriptionMappings.TryGetValue(key, out var translationKey))
{
return result.Title;
Log.Error("Flow.Launcher.Plugin.Sys.Main", $"Description not found for: {key}");
return "Description Not Found";
}
var englishTitleMatch = StringMatcher.FuzzySearch(query.Search, result.Title);
var translatedTitleMatch = StringMatcher.FuzzySearch(query.Search, translatedTitle);
return englishTitleMatch.Score >= translatedTitleMatch.Score ? result.Title : translatedTitle;
return _context.API.GetTranslation(translationKey);
}
public void Init(PluginInitContext context)
{
this.context = context;
themeSelector = new ThemeSelector(context);
KeywordTitleMappings = new Dictionary<string, string>{
{"Shutdown", "flowlauncher_plugin_sys_shutdown_computer_cmd"},
{"Restart", "flowlauncher_plugin_sys_restart_computer_cmd"},
{"Restart With Advanced Boot Options", "flowlauncher_plugin_sys_restart_advanced_cmd"},
{"Log Off/Sign Out", "flowlauncher_plugin_sys_log_off_cmd"},
{"Lock", "flowlauncher_plugin_sys_lock_cmd"},
{"Sleep", "flowlauncher_plugin_sys_sleep_cmd"},
{"Hibernate", "flowlauncher_plugin_sys_hibernate_cmd"},
{"Index Option", "flowlauncher_plugin_sys_indexoption_cmd"},
{"Empty Recycle Bin", "flowlauncher_plugin_sys_emptyrecyclebin_cmd"},
{"Open Recycle Bin", "flowlauncher_plugin_sys_openrecyclebin_cmd"},
{"Exit", "flowlauncher_plugin_sys_exit_cmd"},
{"Save Settings", "flowlauncher_plugin_sys_save_all_settings_cmd"},
{"Restart Flow Launcher", "flowlauncher_plugin_sys_restart_cmd"},
{"Settings", "flowlauncher_plugin_sys_setting_cmd"},
{"Reload Plugin Data", "flowlauncher_plugin_sys_reload_plugin_data_cmd"},
{"Check For Update", "flowlauncher_plugin_sys_check_for_update_cmd"},
{"Open Log Location", "flowlauncher_plugin_sys_open_log_location_cmd"},
{"Flow Launcher Tips", "flowlauncher_plugin_sys_open_docs_tips_cmd"},
{"Flow Launcher UserData Folder", "flowlauncher_plugin_sys_open_userdata_location_cmd"},
{"Toggle Game Mode", "flowlauncher_plugin_sys_toggle_game_mode_cmd"},
{"Set Flow Launcher Theme", "flowlauncher_plugin_sys_theme_selector_cmd"}
};
_context = context;
_settings = context.API.LoadSettingJsonStorage<Settings>();
_viewModel = new SettingsViewModel(_settings);
_themeSelector = new ThemeSelector(context);
foreach (string key in KeywordTitleMappings.Keys)
{
// Remove _cmd in the last of the strings
KeywordDescriptionMappings[key] = KeywordTitleMappings[key][..^4];
}
}
private void UpdateLocalizedNameDescription(bool force)
{
if (string.IsNullOrEmpty(_settings.Commands[0].Name) || force)
{
foreach (var c in _settings.Commands)
{
c.Name = GetTitle(c.Key);
c.Description = GetDescription(c.Key);
}
}
}
private static unsafe bool EnableShutdownPrivilege()
@ -162,14 +199,13 @@ namespace Flow.Launcher.Plugin.Sys
new Result
{
Title = "Shutdown",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_shutdown_computer"),
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe7e8"),
IcoPath = "Images\\shutdown.png",
Action = c =>
{
var result = context.API.ShowMsgBox(
context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_shutdown_computer"),
context.API.GetTranslation("flowlauncher_plugin_sys_shutdown_computer"),
var result = _context.API.ShowMsgBox(
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_shutdown_computer"),
_context.API.GetTranslation("flowlauncher_plugin_sys_shutdown_computer"),
MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes)
@ -184,14 +220,13 @@ namespace Flow.Launcher.Plugin.Sys
new Result
{
Title = "Restart",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"),
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe777"),
IcoPath = "Images\\restart.png",
Action = c =>
{
var result = context.API.ShowMsgBox(
context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_restart_computer"),
context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"),
var result = _context.API.ShowMsgBox(
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_restart_computer"),
_context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"),
MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes)
@ -206,14 +241,13 @@ namespace Flow.Launcher.Plugin.Sys
new Result
{
Title = "Restart With Advanced Boot Options",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_restart_advanced"),
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xecc5"),
IcoPath = "Images\\restart_advanced.png",
Action = c =>
{
var result = context.API.ShowMsgBox(
context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_restart_computer_advanced"),
context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"),
var result = _context.API.ShowMsgBox(
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_restart_computer_advanced"),
_context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"),
MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes)
@ -228,14 +262,13 @@ namespace Flow.Launcher.Plugin.Sys
new Result
{
Title = "Log Off/Sign Out",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_log_off"),
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe77b"),
IcoPath = "Images\\logoff.png",
Action = c =>
{
var result = context.API.ShowMsgBox(
context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_logoff_computer"),
context.API.GetTranslation("flowlauncher_plugin_sys_log_off"),
var result = _context.API.ShowMsgBox(
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_logoff_computer"),
_context.API.GetTranslation("flowlauncher_plugin_sys_log_off"),
MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes)
@ -247,7 +280,6 @@ namespace Flow.Launcher.Plugin.Sys
new Result
{
Title = "Lock",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_lock"),
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe72e"),
IcoPath = "Images\\lock.png",
Action = c =>
@ -259,7 +291,6 @@ namespace Flow.Launcher.Plugin.Sys
new Result
{
Title = "Sleep",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_sleep"),
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xec46"),
IcoPath = "Images\\sleep.png",
Action = c =>
@ -271,7 +302,6 @@ namespace Flow.Launcher.Plugin.Sys
new Result
{
Title = "Hibernate",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_hibernate"),
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe945"),
IcoPath = "Images\\hibernate.png",
Action= c =>
@ -283,7 +313,6 @@ namespace Flow.Launcher.Plugin.Sys
new Result
{
Title = "Index Option",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_indexoption"),
IcoPath = "Images\\indexoption.png",
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe773"),
Action = c =>
@ -295,7 +324,6 @@ namespace Flow.Launcher.Plugin.Sys
new Result
{
Title = "Empty Recycle Bin",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_emptyrecyclebin"),
IcoPath = "Images\\recyclebin.png",
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe74d"),
Action = c =>
@ -306,7 +334,7 @@ namespace Flow.Launcher.Plugin.Sys
var result = PInvoke.SHEmptyRecycleBin(new(), string.Empty, 0);
if (result != HRESULT.S_OK && result != HRESULT.E_UNEXPECTED)
{
context.API.ShowMsgBox("Failed to empty the recycle bin. This might happen if:\n" +
_context.API.ShowMsgBox("Failed to empty the recycle bin. This might happen if:\n" +
"- A file in the recycle bin is in use\n" +
"- You don't have permission to delete some items\n" +
"Please close any applications that might be using these files and try again.",
@ -320,7 +348,6 @@ namespace Flow.Launcher.Plugin.Sys
new Result
{
Title = "Open Recycle Bin",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_openrecyclebin"),
IcoPath = "Images\\openrecyclebin.png",
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe74d"),
CopyText = recycleBinFolder,
@ -333,7 +360,6 @@ namespace Flow.Launcher.Plugin.Sys
new Result
{
Title = "Exit",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_exit"),
IcoPath = "Images\\app.png",
Action = c =>
{
@ -344,52 +370,48 @@ namespace Flow.Launcher.Plugin.Sys
new Result
{
Title = "Save Settings",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_save_all_settings"),
IcoPath = "Images\\app.png",
Action = c =>
{
context.API.SaveAppAllSettings();
context.API.ShowMsg(context.API.GetTranslation("flowlauncher_plugin_sys_dlgtitle_success"),
context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_all_settings_saved"));
_context.API.SaveAppAllSettings();
_context.API.ShowMsg(_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtitle_success"),
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_all_settings_saved"));
return true;
}
},
new Result
{
Title = "Restart Flow Launcher",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_restart"),
IcoPath = "Images\\app.png",
Action = c =>
{
context.API.RestartApp();
_context.API.RestartApp();
return false;
}
},
new Result
{
Title = "Settings",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_setting"),
IcoPath = "Images\\app.png",
Action = c =>
{
context.API.OpenSettingDialog();
_context.API.OpenSettingDialog();
return true;
}
},
new Result
{
Title = "Reload Plugin Data",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_reload_plugin_data"),
IcoPath = "Images\\app.png",
Action = c =>
{
// Hide the window first then show msg after done because sometimes the reload could take a while, so not to make user think it's frozen.
context.API.HideMainWindow();
_context.API.HideMainWindow();
_ = context.API.ReloadAllPluginData().ContinueWith(_ =>
context.API.ShowMsg(
context.API.GetTranslation("flowlauncher_plugin_sys_dlgtitle_success"),
context.API.GetTranslation(
_ = _context.API.ReloadAllPluginData().ContinueWith(_ =>
_context.API.ShowMsg(
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtitle_success"),
_context.API.GetTranslation(
"flowlauncher_plugin_sys_dlgtext_all_applicableplugins_reloaded")),
System.Threading.Tasks.TaskScheduler.Current);
@ -399,75 +421,69 @@ namespace Flow.Launcher.Plugin.Sys
new Result
{
Title = "Check For Update",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_check_for_update"),
IcoPath = "Images\\checkupdate.png",
Action = c =>
{
context.API.HideMainWindow();
context.API.CheckForNewUpdate();
_context.API.HideMainWindow();
_context.API.CheckForNewUpdate();
return true;
}
},
new Result
{
Title = "Open Log Location",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_open_log_location"),
IcoPath = "Images\\app.png",
CopyText = logPath,
AutoCompleteText = logPath,
Action = c =>
{
context.API.OpenDirectory(logPath);
_context.API.OpenDirectory(logPath);
return true;
}
},
new Result
{
Title = "Flow Launcher Tips",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_open_docs_tips"),
IcoPath = "Images\\app.png",
CopyText = Constant.Documentation,
AutoCompleteText = Constant.Documentation,
Action = c =>
{
context.API.OpenUrl(Constant.Documentation);
_context.API.OpenUrl(Constant.Documentation);
return true;
}
},
new Result
{
Title = "Flow Launcher UserData Folder",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_open_userdata_location"),
IcoPath = "Images\\app.png",
CopyText = userDataPath,
AutoCompleteText = userDataPath,
Action = c =>
{
context.API.OpenDirectory(userDataPath);
_context.API.OpenDirectory(userDataPath);
return true;
}
},
new Result
{
Title = "Toggle Game Mode",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_toggle_game_mode"),
IcoPath = "Images\\app.png",
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\ue7fc"),
Action = c =>
{
context.API.ToggleGameMode();
_context.API.ToggleGameMode();
return true;
}
},
new Result
{
Title = "Set Flow Launcher Theme",
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_theme_selector"),
IcoPath = "Images\\app.png",
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\ue7fc"),
Action = c =>
{
context.API.ChangeQuery($"{ThemeSelector.Keyword} ");
_context.API.ChangeQuery($"{ThemeSelector.Keyword} ");
return false;
}
}
@ -478,12 +494,17 @@ namespace Flow.Launcher.Plugin.Sys
public string GetTranslatedPluginTitle()
{
return context.API.GetTranslation("flowlauncher_plugin_sys_plugin_name");
return _context.API.GetTranslation("flowlauncher_plugin_sys_plugin_name");
}
public string GetTranslatedPluginDescription()
{
return context.API.GetTranslation("flowlauncher_plugin_sys_plugin_description");
return _context.API.GetTranslation("flowlauncher_plugin_sys_plugin_description");
}
public void OnCultureInfoChanged(CultureInfo _)
{
UpdateLocalizedNameDescription(true);
}
}
}

View file

@ -0,0 +1,127 @@
using System.Collections.ObjectModel;
using System.Text.Json.Serialization;
namespace Flow.Launcher.Plugin.Sys;
public class Settings : BaseModel
{
public Settings()
{
if (Commands.Count > 0)
{
SelectedCommand = Commands[0];
}
}
public ObservableCollection<Command> Commands { get; set; } = new ObservableCollection<Command>
{
new()
{
Key = "Shutdown",
Keyword = "Shutdown"
},
new()
{
Key = "Restart",
Keyword = "Restart"
},
new()
{
Key = "Restart With Advanced Boot Options",
Keyword = "Restart With Advanced Boot Options"
},
new()
{
Key = "Log Off/Sign Out",
Keyword = "Log Off/Sign Out"
},
new()
{
Key = "Lock",
Keyword = "Lock"
},
new()
{
Key = "Sleep",
Keyword = "Sleep"
},
new()
{
Key = "Hibernate",
Keyword = "Hibernate"
},
new()
{
Key = "Index Option",
Keyword = "Index Option"
},
new()
{
Key = "Empty Recycle Bin",
Keyword = "Empty Recycle Bin"
},
new()
{
Key = "Open Recycle Bin",
Keyword = "Open Recycle Bin"
},
new()
{
Key = "Exit",
Keyword = "Exit"
},
new()
{
Key = "Save Settings",
Keyword = "Save Settings"
},
new()
{
Key = "Restart Flow Launcher",
Keyword = "Restart Flow Launcher"
},
new()
{
Key = "Settings",
Keyword = "Settings"
},
new()
{
Key = "Reload Plugin Data",
Keyword = "Reload Plugin Data"
},
new()
{
Key = "Check For Update",
Keyword = "Check For Update"
},
new()
{
Key = "Open Log Location",
Keyword = "Open Log Location"
},
new()
{
Key = "Flow Launcher Tips",
Keyword = "Flow Launcher Tips"
},
new()
{
Key = "Flow Launcher UserData Folder",
Keyword = "Flow Launcher UserData Folder"
},
new()
{
Key = "Toggle Game Mode",
Keyword = "Toggle Game Mode"
},
new()
{
Key = "Set Flow Launcher Theme",
Keyword = "Set Flow Launcher Theme"
}
};
[JsonIgnore]
public Command SelectedCommand { get; set; }
}

View file

@ -0,0 +1,12 @@
namespace Flow.Launcher.Plugin.Sys
{
public class SettingsViewModel
{
public SettingsViewModel(Settings settings)
{
Settings = settings;
}
public Settings Settings { get; }
}
}

View file

@ -4,36 +4,66 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:Flow.Launcher.Plugin.Sys"
d:DataContext="{d:DesignInstance vm:SettingsViewModel}"
d:DesignHeight="300"
d:DesignWidth="300"
mc:Ignorable="d">
<Grid Margin="70,18,18,18">
<Grid Margin="70 18 18 18">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListView
x:Name="lbxCommands"
Grid.Row="0"
Margin="0"
BorderBrush="DarkGray"
BorderThickness="1"
ItemsSource="{Binding Settings.Commands}"
MouseDoubleClick="MouseDoubleClickItem"
SelectedItem="{Binding Settings.SelectedCommand}"
SizeChanged="ListView_SizeChanged"
Style="{StaticResource {x:Static GridView.GridViewStyleKey}}">
<ListView.View>
<GridView>
<GridViewColumn Width="150" Header="{DynamicResource flowlauncher_plugin_sys_command}">
<GridViewColumn Width="150" Header="{DynamicResource flowlauncher_plugin_sys_name}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title}" TextTrimming="CharacterEllipsis" />
<TextBlock Text="{Binding Name}" TextTrimming="CharacterEllipsis" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="379" Header="{DynamicResource flowlauncher_plugin_sys_desc}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding SubTitle}" TextTrimming="CharacterEllipsis" />
<TextBlock Text="{Binding Description}" TextTrimming="CharacterEllipsis" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="150" Header="{DynamicResource flowlauncher_plugin_sys_command}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Keyword}" TextTrimming="CharacterEllipsis" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<StackPanel
Grid.Row="1"
HorizontalAlignment="Right"
Orientation="Horizontal">
<Button
Width="100"
Margin="10"
Click="OnEditCommandKeywordClick"
Content="{DynamicResource flowlauncher_plugin_sys_edit}" />
</StackPanel>
</Grid>
</UserControl>

View file

@ -1,28 +1,30 @@
using System.Collections.Generic;
using System.Windows;
using System.Windows;
using System.Windows.Controls;
namespace Flow.Launcher.Plugin.Sys
{
public partial class SysSettings : UserControl
{
public SysSettings(List<Result> Results)
private readonly PluginInitContext _context;
private readonly Settings _settings;
public SysSettings(PluginInitContext context, SettingsViewModel viewModel)
{
InitializeComponent();
foreach (var Result in Results)
{
lbxCommands.Items.Add(Result);
}
_context = context;
_settings = viewModel.Settings;
DataContext = viewModel;
}
private void ListView_SizeChanged(object sender, SizeChangedEventArgs e)
{
ListView listView = sender as ListView;
GridView gView = listView.View as GridView;
var workingWidth = listView.ActualWidth - SystemParameters.VerticalScrollBarWidth; // take into account vertical scrollbar
var col1 = 0.3;
var col2 = 0.7;
var col1 = 0.2;
var col2 = 0.6;
var col3 = 0.2;
if (workingWidth <= 0)
{
@ -31,6 +33,22 @@ namespace Flow.Launcher.Plugin.Sys
gView.Columns[0].Width = workingWidth * col1;
gView.Columns[1].Width = workingWidth * col2;
gView.Columns[2].Width = workingWidth * col3;
}
public void OnEditCommandKeywordClick(object sender, RoutedEventArgs e)
{
var commandKeyword = new CommandKeywordSettingWindow(_context, _settings.SelectedCommand);
commandKeyword.ShowDialog();
}
private void MouseDoubleClickItem(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (((FrameworkElement)e.OriginalSource).DataContext is Command && _settings.SelectedCommand != null)
{
var commandKeyword = new CommandKeywordSettingWindow(_context, _settings.SelectedCommand);
commandKeyword.ShowDialog();
}
}
}
}

View file

@ -2,7 +2,7 @@
using System.Linq;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Core.Resource;
using Flow.Launcher.Infrastructure.UserSettings;
using FLSettings = Flow.Launcher.Infrastructure.UserSettings.Settings;
namespace Flow.Launcher.Plugin.Sys
{
@ -10,7 +10,7 @@ namespace Flow.Launcher.Plugin.Sys
{
public const string Keyword = "fltheme";
private readonly Settings _settings;
private readonly FLSettings _settings;
private readonly Theme _theme;
private readonly PluginInitContext _context;
@ -43,7 +43,7 @@ namespace Flow.Launcher.Plugin.Sys
{
_context = context;
_theme = Ioc.Default.GetRequiredService<Theme>();
_settings = Ioc.Default.GetRequiredService<Settings>();
_settings = Ioc.Default.GetRequiredService<FLSettings>();
}
public List<Result> Query(Query query)

View file

@ -1,21 +1,12 @@
using Flow.Launcher.Infrastructure.Storage;
namespace Flow.Launcher.Plugin.WebSearch
namespace Flow.Launcher.Plugin.WebSearch
{
public class SettingsViewModel
{
private readonly PluginJsonStorage<Settings> _storage;
public SettingsViewModel(Settings settings)
{
Settings = settings;
}
public Settings Settings { get; }
public void Save()
{
_storage.Save();
}
}
}
}