Skip to content

Commit 11e0f8c

Browse files
authored
Merge pull request #4273 from onesounds/20250220_SkipConfirm
Add option to skip confirmation for power actions (Sys Plugin)
2 parents 886cd75 + a99b839 commit 11e0f8c

4 files changed

Lines changed: 56 additions & 24 deletions

File tree

Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:system="clr-namespace:System;assembly=mscorlib">
55

6+
<!-- Setting -->
7+
<system:String x:Key="flowlauncher_plugin_sys_skip_confirm">Skip confirmation when Shutting down, Restarting, or Logging off</system:String>
8+
69
<!-- Command List -->
710
<system:String x:Key="flowlauncher_plugin_sys_name">Name</system:String>
811
<system:String x:Key="flowlauncher_plugin_sys_desc">Description</system:String>

Plugins/Flow.Launcher.Plugin.Sys/Main.cs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private static unsafe bool EnableShutdownPrivilege()
193193
}
194194
}
195195

196-
private static List<Result> Commands(Query query)
196+
private List<Result> Commands(Query query)
197197
{
198198
var results = new List<Result>();
199199
var recycleBinFolder = "shell:RecycleBinFolder";
@@ -206,15 +206,16 @@ private static List<Result> Commands(Query query)
206206
IcoPath = "Images\\shutdown.png",
207207
Action = c =>
208208
{
209-
var result = Context.API.ShowMsgBox(
210-
Localize.flowlauncher_plugin_sys_dlgtext_shutdown_computer(),
211-
Localize.flowlauncher_plugin_sys_shutdown_computer(),
212-
MessageBoxButton.YesNo, MessageBoxImage.Warning);
209+
var result = _settings.SkipPowerActionConfirmation
210+
? MessageBoxResult.Yes
211+
: Context.API.ShowMsgBox(
212+
Localize.flowlauncher_plugin_sys_dlgtext_shutdown_computer(),
213+
Localize.flowlauncher_plugin_sys_shutdown_computer(),
214+
MessageBoxButton.YesNo, MessageBoxImage.Warning);
215+
213216
if (result == MessageBoxResult.Yes)
214217
{
215-
// Save settings before shutdown to avoid data loss
216218
Context.API.SaveAppAllSettings();
217-
218219
if (EnableShutdownPrivilege())
219220
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_SHUTDOWN | EXIT_WINDOWS_FLAGS.EWX_POWEROFF, REASON);
220221
else
@@ -230,15 +231,16 @@ private static List<Result> Commands(Query query)
230231
IcoPath = "Images\\restart.png",
231232
Action = c =>
232233
{
233-
var result = Context.API.ShowMsgBox(
234-
Localize.flowlauncher_plugin_sys_dlgtext_restart_computer(),
235-
Localize.flowlauncher_plugin_sys_restart_computer(),
236-
MessageBoxButton.YesNo, MessageBoxImage.Warning);
234+
var result = _settings.SkipPowerActionConfirmation
235+
? MessageBoxResult.Yes
236+
: Context.API.ShowMsgBox(
237+
Localize.flowlauncher_plugin_sys_dlgtext_restart_computer(),
238+
Localize.flowlauncher_plugin_sys_restart_computer(),
239+
MessageBoxButton.YesNo, MessageBoxImage.Warning);
240+
237241
if (result == MessageBoxResult.Yes)
238242
{
239-
// Save settings before restart to avoid data loss
240243
Context.API.SaveAppAllSettings();
241-
242244
if (EnableShutdownPrivilege())
243245
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_REBOOT, REASON);
244246
else
@@ -254,10 +256,13 @@ private static List<Result> Commands(Query query)
254256
IcoPath = "Images\\restart_advanced.png",
255257
Action = c =>
256258
{
257-
var result = Context.API.ShowMsgBox(
258-
Localize.flowlauncher_plugin_sys_dlgtext_restart_computer_advanced(),
259-
Localize.flowlauncher_plugin_sys_restart_computer(),
260-
MessageBoxButton.YesNo, MessageBoxImage.Warning);
259+
var result = _settings.SkipPowerActionConfirmation
260+
? MessageBoxResult.Yes
261+
: Context.API.ShowMsgBox(
262+
Localize.flowlauncher_plugin_sys_dlgtext_restart_computer_advanced(),
263+
Localize.flowlauncher_plugin_sys_restart_computer(),
264+
MessageBoxButton.YesNo, MessageBoxImage.Warning);
265+
261266
if (result == MessageBoxResult.Yes)
262267
{
263268
// Save settings before advanced restart to avoid data loss
@@ -278,10 +283,13 @@ private static List<Result> Commands(Query query)
278283
IcoPath = "Images\\logoff.png",
279284
Action = c =>
280285
{
281-
var result = Context.API.ShowMsgBox(
282-
Localize.flowlauncher_plugin_sys_dlgtext_logoff_computer(),
283-
Localize.flowlauncher_plugin_sys_log_off(),
284-
MessageBoxButton.YesNo, MessageBoxImage.Warning);
286+
var result = _settings.SkipPowerActionConfirmation
287+
? MessageBoxResult.Yes
288+
: Context.API.ShowMsgBox(
289+
Localize.flowlauncher_plugin_sys_dlgtext_logoff_computer(),
290+
Localize.flowlauncher_plugin_sys_log_off(),
291+
MessageBoxButton.YesNo, MessageBoxImage.Warning);
292+
285293
if (result == MessageBoxResult.Yes)
286294
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_LOGOFF, REASON);
287295
return true;

Plugins/Flow.Launcher.Plugin.Sys/Settings.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,18 @@ public Settings()
124124

125125
[JsonIgnore]
126126
public Command SelectedCommand { get; set; }
127+
private bool _skipPowerActionConfirmation;
128+
public bool SkipPowerActionConfirmation
129+
{
130+
get => _skipPowerActionConfirmation;
131+
set
132+
{
133+
if (_skipPowerActionConfirmation == value)
134+
{
135+
return;
136+
}
137+
_skipPowerActionConfirmation = value;
138+
OnPropertyChanged();
139+
}
140+
}
127141
}

Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@
1212

1313
<Grid Margin="{StaticResource SettingPanelMargin}">
1414
<Grid.RowDefinitions>
15+
<RowDefinition Height="Auto" />
1516
<RowDefinition />
1617
<RowDefinition Height="Auto" />
1718
</Grid.RowDefinitions>
18-
19+
<StackPanel
20+
Grid.Row="0"
21+
Margin="0 0 0 6"
22+
HorizontalAlignment="Left"
23+
Orientation="Horizontal">
24+
<CheckBox Content="{DynamicResource flowlauncher_plugin_sys_skip_confirm}" IsChecked="{Binding Settings.SkipPowerActionConfirmation}" />
25+
</StackPanel>
1926
<ListView
2027
x:Name="lbxCommands"
21-
Grid.Row="0"
28+
Grid.Row="1"
2229
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
2330
BorderBrush="DarkGray"
2431
BorderThickness="1"
@@ -57,7 +64,7 @@
5764
</ListView>
5865

5966
<StackPanel
60-
Grid.Row="1"
67+
Grid.Row="2"
6168
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
6269
HorizontalAlignment="Right"
6370
Orientation="Horizontal">

0 commit comments

Comments
 (0)