Skip to content

Commit

Permalink
fixes tray icon behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Meliox committed Sep 29, 2024
1 parent d8938ab commit 27cac14
Show file tree
Hide file tree
Showing 3 changed files with 606 additions and 17 deletions.
6 changes: 4 additions & 2 deletions ActivityWinOff/Main.Designer.cs

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

34 changes: 21 additions & 13 deletions ActivityWinOff/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ private void BackgroundWorkerGUIUpdate(object sender, DoWorkEventArgs e)

public void StartTrigger()
{
Interface.Enabled = !Interface.Enabled;
Logger.add(2, "Starting watchdogs");
Helper.DisableScreensaver(Interface.DisableScreensaver);
SetStatusInGui();
Expand All @@ -377,8 +378,8 @@ public void StartTrigger()
var contextMenu = new ContextMenuStrip();

// Add "Start" menu item
var startItem = new ToolStripMenuItem("Start");
startItem.Click += (s, e) => { StartTrigger(); };
var startItem = new ToolStripMenuItem("Stop");
startItem.Click += (s, e) => { StopTrigger(); };
contextMenu.Items.Add(startItem);

// Add "Exit" menu item
Expand All @@ -389,13 +390,14 @@ public void StartTrigger()
// Assign the ContextMenuStrip to NotifyIcon
notifyIcon.ContextMenuStrip = contextMenu;
workerWatchdogTrigger.RunWorkerAsync();
notifyIcon.BalloonTipTitle = "ActivityWinOff";
notifyIcon.BalloonTipText = "Watchdog running";
notifyIcon.BalloonTipText = "Started";
notifyIcon.ShowBalloonTip(1000);
}

public void StopTrigger()
{
Interface.Enabled = !Interface.Enabled;

Logger.add(2, "Stopping watchdogs");
Helper.DisableScreensaver(false);
SetStatusInGui();
Expand All @@ -422,6 +424,9 @@ public void StopTrigger()
UpdateWaitForProgramNextAction("");
UpdateTimerNextAction("");

notifyIcon.BalloonTipText = "Stopped";
notifyIcon.ShowBalloonTip(1000);

// renable settings
LockSettingsInGui(false);
}
Expand All @@ -441,13 +446,13 @@ public void SetStatusInGui()
{
Statusbutton.Text = "Active";
Statusbutton.BackColor = Color.Green;
ActivateDeactivatebutton.Text = "Deactivate";
ActivateDeactivatebutton.Text = "Stop";
}
else
{
Statusbutton.Text = "Inactive";
Statusbutton.BackColor = Color.White;
ActivateDeactivatebutton.Text = "Activate";
ActivateDeactivatebutton.Text = "Start";
}
}

Expand Down Expand Up @@ -591,15 +596,16 @@ private void MinimizeToTraybutton_Click(object sender, EventArgs e)
WindowState = FormWindowState.Minimized;
ShowInTaskbar = false;
Hide();
notifyIcon.Text = "ActivityWinOff" + System.Environment.NewLine + "Running: " + Interface.Enabled;
}

private void notifyIcon_MouseClick(object sender, MouseEventArgs e)
{
ShowInTaskbar = true;
Show();
WindowState = FormWindowState.Normal;
notifyIcon.Text = "ActivityWinOff";
if (e.Button == MouseButtons.Left)
{
ShowInTaskbar = true;
Show();
WindowState = FormWindowState.Normal;
}
}

private void Condition_CheckedChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -638,11 +644,12 @@ private void ShutdownType_CheckedChanged(object sender, EventArgs e)

private void ActivateDeactivatebutton_Click(object sender, EventArgs e)
{
Interface.Enabled = !Interface.Enabled;
if (Interface.Enabled)
if (!Interface.Enabled)
StartTrigger();
else
StopTrigger();

notifyIcon.Text = "ActivityWinOff: " + (Interface.Enabled ? "Active" : "Inactive");
}

private void NetworkAveragecheckBox_CheckChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -1148,6 +1155,7 @@ private void Form1_Shown(object sender, EventArgs e)
SetStatusInGui();
}
}
notifyIcon.Text = "ActivityWinOff: " + (Interface.Enabled ? "Active" : "Inactive");
}

private void StartAddbutton_Click(object sender, EventArgs e)
Expand Down
Loading

0 comments on commit 27cac14

Please sign in to comment.