Skip to content

Commit 88386ce

Browse files
committed
Code styles.
1 parent 42a2ca5 commit 88386ce

1 file changed

Lines changed: 29 additions & 32 deletions

File tree

Program.cs

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ public AppContext() {
6262
monitor.Start();
6363
}
6464

65-
notifyIcon = new(components);
66-
67-
// tooltip
68-
notifyIcon.Text = "Caffeinated";
69-
notifyIcon.Visible = true;
65+
notifyIcon = new(components) {
66+
// tooltip
67+
Text = "Caffeinated",
68+
Visible = true
69+
};
7070

7171
// Handle the DoubleClick event to activate the form.
7272
notifyIcon.MouseClick += new MouseEventHandler(notifyIcon1_Click);
@@ -88,18 +88,20 @@ public AppContext() {
8888

8989
private void SetIsLightTheme(object? sender = null, EventArgs? e = null) {
9090
try {
91-
using (RegistryKey? key = Registry.CurrentUser.OpenSubKey(themeKeyPath)) {
92-
if (key != null) {
93-
Object? o = key.GetValue("SystemUsesLightTheme");
94-
if (o != null) {
95-
if (o.ToString() == "1") {
96-
isLightTheme = true;
97-
}
98-
else {
99-
isLightTheme = false;
100-
}
101-
}
102-
}
91+
using RegistryKey? key = Registry.CurrentUser.OpenSubKey(themeKeyPath);
92+
if (key is null) {
93+
return;
94+
}
95+
Object? o = key.GetValue("SystemUsesLightTheme");
96+
if (o is null) {
97+
return;
98+
}
99+
100+
if (o.ToString() == "1") {
101+
isLightTheme = true;
102+
}
103+
else {
104+
isLightTheme = false;
103105
}
104106
}
105107
catch (Exception) {
@@ -109,14 +111,11 @@ private void SetIsLightTheme(object? sender = null, EventArgs? e = null) {
109111
setIcons();
110112
setContextMenu();
111113

112-
if (notifyIcon != null)
113-
{
114-
if (isActivated)
115-
{
114+
if (notifyIcon != null) {
115+
if (isActivated) {
116116
notifyIcon.Icon = onIcon;
117117
}
118-
else
119-
{
118+
else {
120119
notifyIcon.Icon = offIcon;
121120
}
122121
}
@@ -252,8 +251,10 @@ public void setContextMenu() {
252251
contextMenu.Items.Add(new ToolStripSeparator());
253252

254253
foreach (int time in sortedTimes) {
255-
ToolStripMenuItem? item = new(Duration.ToDescription(time));
256-
item.Tag = time;
254+
ToolStripMenuItem? item = new(Duration.ToDescription(time))
255+
{
256+
Tag = time
257+
};
257258
item.Click += new(item_Click);
258259
contextMenu.Items.Add(item);
259260
}
@@ -326,7 +327,7 @@ private void notifyIcon1_Click(object? sender, MouseEventArgs e) {
326327
}
327328
}
328329

329-
private void ShowError() {
330+
private static void ShowError() {
330331
MessageBox.Show(
331332
"Call to SetThreadExecutionState failed.",
332333
"Caffeinated",
@@ -364,9 +365,7 @@ private void activate(int duration) {
364365
}
365366

366367
private void deactivate() {
367-
if (timer != null) {
368-
timer.Stop();
369-
}
368+
timer?.Stop();
370369

371370
uint result = NativeMethods.SetThreadExecutionState(NativeMethods.ES_CONTINUOUS);
372371
if (result == 0) {
@@ -382,9 +381,7 @@ private void deactivate() {
382381

383382
private void exitItem_Click(object? Sender, EventArgs e) {
384383
deactivate();
385-
if (notifyIcon != null) {
386-
notifyIcon.Dispose();
387-
}
384+
notifyIcon?.Dispose();
388385

389386
ExitThread();
390387
}

0 commit comments

Comments
 (0)