Skip to content

Commit f45df81

Browse files
committed
Improved tray icon
- Add option to enable tray icon - Add option to minimize to tray icon - Restructured tray icon menu for easier access (less sub menus) - No tray icon question on closing (handled by minimize and new option)
1 parent 05a7c71 commit f45df81

6 files changed

Lines changed: 93 additions & 61 deletions

File tree

Sources/AppConfig.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ public class SettingsRoot
8282
public bool AlwaysOnTop;
8383
public bool DarkMode;
8484
public bool CheckUpdatesOnStartup;
85+
public bool TrayIconEnable;
86+
public bool TrayIconMinimize;
8587
public int HotKeyMethod;
8688
public bool ShortcutResetEnable;
8789
public int ShortcutResetKeyCode; // Actually KeyData as it is combined with modifiers
@@ -369,6 +371,8 @@ private void LoadSettings()
369371
if (_settings.Version == 10) // Coming from version 1.21
370372
{
371373
_settings.Version = 11;
374+
_settings.TrayIconEnable = false;
375+
_settings.TrayIconMinimize = true;
372376
_settings.AllowHtml = false;
373377
_settings.StyleTableAlignment = "tblcenter";
374378

Sources/Form1.Designer.cs

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/Form1.cs

Lines changed: 41 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ public partial class Form1 : Form
3636
#endregion
3737

3838
#region ToolBar
39-
private ContextMenuStrip trayMenu = new ContextMenuStrip();
40-
private bool CloseOnTry = false;
39+
private ContextMenuStrip trayMenu;
4140

4241
private void ShowMainForm()
4342
{
@@ -48,7 +47,6 @@ private void ShowMainForm()
4847
private void CloseHCM()
4948
{
5049
notifyIconToolBar.Visible = false;
51-
CloseOnTry = true;
5250
Application.Exit();
5351
}
5452

@@ -109,66 +107,54 @@ private void Form1_Load(object sender, EventArgs e)
109107
#endregion
110108

111109
#region ToolBar
112-
trayMenu.Items.Add("Open HCM", null, (s, e) => ShowMainForm());
113-
114-
// Timer
115-
var timerMenu = new ToolStripMenuItem("Timer");
116-
timerMenu.DropDownItems.Add("StartTimer", null, (s, e) => StartStopTimer(true));
117-
timerMenu.DropDownItems.Add("StopTimer", null, (s, e) => StartStopTimer(false));
118-
trayMenu.Items.Add(timerMenu);
119-
120-
// Hit
121-
var hitMenu = new ToolStripMenuItem("Hit");
122-
123-
var wayMenu = new ToolStripMenuItem("Way");
124-
wayMenu.DropDownItems.Add("Increase", null, (s, e) => btnWayHit_Click(null,null));
125-
wayMenu.DropDownItems.Add("Decrease", null, (s, e) => btnWayHitUndo_Click(null,null));
126-
hitMenu.DropDownItems.Add(wayMenu);
127-
128-
var bossMenu = new ToolStripMenuItem("Boss");
129-
bossMenu.DropDownItems.Add("Increase", null, (s, e) => btnHit_Click(null,null));
130-
bossMenu.DropDownItems.Add("Decrease", null, (s, e) => btnHitUndo_Click(null, null));
131-
hitMenu.DropDownItems.Add(bossMenu);
132-
133-
trayMenu.Items.Add(hitMenu);
134-
135-
// Split
136-
var splitMenu = new ToolStripMenuItem("Split");
137-
splitMenu.DropDownItems.Add("Reset Run", null, (s, e) => btnReset_Click(null,null));
138-
splitMenu.DropDownItems.Add("Next Split", null, (s, e) => btnSplit_Click(null,null));
139-
splitMenu.DropDownItems.Add("Previous Split", null, (s, e) => btnSplitPrev_Click(null,null));
140-
trayMenu.Items.Add(splitMenu);
141-
142-
// Close HCM
143-
trayMenu.Items.Add("Close HCM", null, (s, e) => CloseHCM());
144-
145-
// NotifyIcon
146-
notifyIconToolBar.ContextMenuStrip = trayMenu;
147-
notifyIconToolBar.DoubleClick += (s, e) => ShowMainForm();
148-
notifyIconToolBar.Visible = true;
110+
if (_settings.TrayIconEnable)
111+
{
112+
trayMenu = new ContextMenuStrip();
113+
114+
// Split
115+
trayMenu.Items.Add("Next split", null, (s, e) => btnSplit_Click(null, null));
116+
trayMenu.Items.Add("Previous split", null, (s, e) => btnSplitPrev_Click(null, null));
117+
118+
// Hit
119+
trayMenu.Items.Add(new ToolStripSeparator());
120+
trayMenu.Items.Add("Hit increase (way)", null, (s, e) => btnWayHit_Click(null, null));
121+
trayMenu.Items.Add("Hit decrease (way)", null, (s, e) => btnWayHitUndo_Click(null, null));
122+
trayMenu.Items.Add("Hit increase (boss)", null, (s, e) => btnHit_Click(null, null));
123+
trayMenu.Items.Add("Hit decrease (boss)", null, (s, e) => btnHitUndo_Click(null, null));
124+
125+
// Timer / Run Reset
126+
trayMenu.Items.Add(new ToolStripSeparator());
127+
var runMenu = new ToolStripMenuItem("Run");
128+
runMenu.DropDownItems.Add("Timer start", null, (s, e) => StartStopTimer(true));
129+
runMenu.DropDownItems.Add("Timer stop", null, (s, e) => StartStopTimer(false));
130+
runMenu.DropDownItems.Add("Reset run", null, (s, e) => btnReset_Click(null, null));
131+
trayMenu.Items.Add(runMenu);
132+
133+
// Open / Close
134+
trayMenu.Items.Add("Open", null, (s, e) => ShowMainForm());
135+
trayMenu.Items.Add(new ToolStripSeparator()); // Spacing to not close the application by accident
136+
trayMenu.Items.Add("Close", null, (s, e) => CloseHCM());
137+
138+
// NotifyIcon
139+
notifyIconToolBar.ContextMenuStrip = trayMenu;
140+
notifyIconToolBar.DoubleClick += (s, e) => ShowMainForm();
141+
notifyIconToolBar.Visible = true;
142+
}
149143
#endregion
150144

151145
this.UpdateDarkMode();
152146
}
153147

154-
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
148+
private void Form1_Resize(object sender, EventArgs e)
155149
{
156-
if (!CloseOnTry)
150+
if (_settings.TrayIconEnable && _settings.TrayIconMinimize && (WindowState == FormWindowState.Minimized))
157151
{
158-
var resultMinimize = MessageBox.Show(
159-
"Do you want to minimize to the taskbar or close the program?\nYes = Minimize - No = Close",
160-
"Exit",
161-
MessageBoxButtons.YesNo,
162-
MessageBoxIcon.Question);
163-
164-
if (resultMinimize == DialogResult.Yes)
165-
{
166-
Hide();
167-
e.Cancel = true;
168-
return;
169-
}
170-
}
152+
Hide();
153+
}
154+
}
171155

156+
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
157+
{
172158
DialogResult result = MessageBox.Show("Do you want to save this session?", this.Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
173159
if (result == DialogResult.Yes)
174160
{

Sources/HitCounterManagerInit.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
<AlwaysOnTop>false</AlwaysOnTop>
3636
<DarkMode>false</DarkMode>
3737
<CheckUpdatesOnStartup>false</CheckUpdatesOnStartup>
38+
<TrayIconEnable>false</TrayIconEnable>
39+
<TrayIconMinimize>true</TrayIconMinimize>
3840
<HotKeyMethod>2</HotKeyMethod>
3941
<ShortcutResetEnable>false</ShortcutResetEnable>
4042
<ShortcutResetKeyCode>65655</ShortcutResetKeyCode>

Sources/Settings.Designer.cs

Lines changed: 39 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/Settings.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//MIT License
22

3-
//Copyright (c) 2016-2024 Peter Kirmeier
3+
//Copyright (c) 2016-2025 Peter Kirmeier
44

55
//Permission is hereby granted, free of charge, to any person obtaining a copy
66
//of this software and associated documentation files (the "Software"), to deal
@@ -96,6 +96,8 @@ private void Settings_Load(object sender, EventArgs e)
9696
txtFontName.Text = _settings.StyleFontName;
9797

9898
// Behavior
99+
cbEnableTrayIcon.Checked = _settings.TrayIconEnable;
100+
cbMinimizeToTrayIcon.Checked = _settings.TrayIconMinimize;
99101
cbAllowHtml.Checked = _settings.AllowHtml;
100102
cbShowAttempts.Checked = _settings.ShowAttemptsCounter;
101103
cbShowHeadline.Checked = _settings.ShowHeadline;
@@ -319,6 +321,8 @@ private void cbApCustomCss_CheckedChanged(object sender, EventArgs e)
319321
btnApApply.Enabled = cbApCustomCss.Checked;
320322
}
321323

324+
private void cbEnableTrayIcon_CheckedChanged(object sender, EventArgs e) { _settings.TrayIconEnable = cbEnableTrayIcon.Checked; }
325+
private void cbMinimizeToTrayIcon_CheckedChanged(object sender, EventArgs e) { _settings.TrayIconMinimize = cbMinimizeToTrayIcon.Checked; }
322326
private void btnGoToDownloadPage_Click(object sender, EventArgs e) { GitHubUpdate.WebOpenLatestRelease(); }
323327
private void cbCheckUpdatesOnStartup_CheckedChanged(object sender, EventArgs e) { _settings.CheckUpdatesOnStartup = cbCheckUpdatesOnStartup.Checked; }
324328

0 commit comments

Comments
 (0)