Skip to content

Commit

Permalink
Toggle task buttons depends on task in scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
ijin82 committed Oct 9, 2021
1 parent 11b0bbd commit f57b36b
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion Waller/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public partial class Form1 : Form
private string exeFilePath = "";
private string exeFileFolderPath = "";

private bool taskExists = false;

public Form1()
{
InitializeComponent();
Expand Down Expand Up @@ -55,6 +57,31 @@ public Form1()
this.toolStripStatusLabel1.Text = "Random wallpaper NOT found";
}

this.toggleTaskButtons();
}

private void toggleTaskButtons()
{
// check if task exists in scheduler
// Get the service on the local machine
using (TaskService ts = new TaskService())
{
try
{
// Remove the task if exists
Task task = ts.GetTask(this.taskName);
if (task != null)
{
this.taskExists = true;
} else {
this.taskExists = false;
}
}
catch (Exception) { }
}

this.button_task_down.Enabled = this.taskExists;
this.button_task_up.Enabled = !this.taskExists;
}

private void btn_folder_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -94,6 +121,8 @@ private void button_task_down_Click(object sender, EventArgs e)

this.toolStripStatusLabel1.Text = "Removed task, named \"" + this.taskName + "\"";
}

this.toggleTaskButtons();
}

private void button_task_up_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -143,6 +172,8 @@ private void button_task_up_Click(object sender, EventArgs e)

this.toolStripStatusLabel1.Text = "Created task, named \"" + this.taskName + "\"";
}

this.toggleTaskButtons();
}

private void SetStatus(String statusText)
Expand Down Expand Up @@ -240,7 +271,7 @@ public string setRandomWallpaper(Boolean forceSetup = false)

private void button_set_rand_Click(object sender, EventArgs e)
{
String randomWall = this.setRandomWallpaper();
String randomWall = this.setRandomWallpaper(true);

this.toolStripStatusLabel1.Text = "Wallpaper set: " + randomWall;
}
Expand Down

0 comments on commit f57b36b

Please sign in to comment.