Skip to content

Commit

Permalink
Add custom action feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Langrock committed Jul 15, 2022
1 parent 7312342 commit 9d205a8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/ShutdownTimer/Countdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public partial class Countdown : Form
public bool Forced { get; set; } // disables all UI controls and exit dialogs
public string Password { get; set; } // if value is not empty then a password will be required to change or disable the countdown
public bool UserLaunch { get; set; } // false if launched from CLI
public string Command { get; set; } // for executing a custom command instead of a power action

//private
private FormWindowState lastStateUIFormWindowState; // used to update UI immediately after WindowState change
Expand Down Expand Up @@ -729,6 +730,10 @@ private void ExecutePowerAction(string choosenAction)
case "Lock":
ExitWindows.Lock();
break;

case "Custom Command":
Process.Start(Command);
break;
}

if (PreventSystemSleep)
Expand Down
3 changes: 2 additions & 1 deletion src/ShutdownTimer/Menu.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion src/ShutdownTimer/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public partial class Menu : Form

private string checkResult;
private string password; // used for password protection
private string command; // used for custom command

public Menu()
{
Expand Down Expand Up @@ -94,6 +95,21 @@ private void StartButton_Click(object sender, EventArgs e)

SaveSettings();

if (actionComboBox.Text.Equals("Custom Command"))
{
ExceptionHandler.LogEvent("[Menu] Entering custom command setup");
using (var form = new InputBox())
{
form.Title = "Custom Command";
form.Message = "Please enter the command you want to have executed. If you wish to launch a file, just enter the full file path.\n\n" +
"Note: Execution will use this user's permissions.";
ExceptionHandler.LogEvent("[Menu] Requesting custom command from user...");
var result = form.ShowDialog();
ExceptionHandler.LogEvent("[Menu] Saving command");
command = form.ReturnValue;
}
}

if (SettingsProvider.Settings.PasswordProtection)
{
ExceptionHandler.LogEvent("[Menu] Enabeling password protection");
Expand Down Expand Up @@ -280,7 +296,8 @@ private void StartCountdown()
PreventSystemSleep = preventSleepCheckBox.Checked,
UI = !backgroundCheckBox.Checked,
Password = password,
UserLaunch = true
UserLaunch = true,
Command = command
})
{
countdown.Owner = this;
Expand Down

0 comments on commit 9d205a8

Please sign in to comment.