Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
92 lines (76 loc) · 3 KB
/
Copy pathProgram.cs
File metadata and controls
92 lines (76 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using Timer = System.Windows.Forms.Timer;
namespace TimeBreak;
static class Program
{
static DateTime lastStart;
static Timer breakTimer;
static NotifyIcon trayIcon = new NotifyIcon();
static BlackScreenForm blackScreen = new BlackScreenForm();
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Setup timer
breakTimer = new Timer();
breakTimer.Tick += (object sender, EventArgs e) =>
StopTimerAndShowBlackScreen(SettingsData.Default.BreakMinuts);
breakTimer.Interval = SettingsData.Default.GetBreakInterval();
breakTimer.Start();
lastStart = DateTime.Now;
// Setup context menu
var timeItem = new ToolStripMenuItem();
timeItem.Enabled = false;
var breakNowItem = new ToolStripMenuItem("Break Now");
breakNowItem.Click += (object sender, EventArgs e) =>
StopTimerAndShowBlackScreen(SettingsData.Default.BreakMinuts);
var settingsItem = new ToolStripMenuItem("Settings");
settingsItem.Click += (object sender, EventArgs e) =>
MessageBox.Show("Not implemented!");
var exitItem = new ToolStripMenuItem("Exit");
exitItem.Click += (object sender, EventArgs e) =>
{
breakTimer.Stop();
blackScreen.Close();
trayIcon.Visible = false;
Application.Exit();
};
var contextMenu = new ContextMenuStrip();
contextMenu.Items.Add(timeItem);
contextMenu.Items.Add(breakNowItem);
contextMenu.Items.Add(settingsItem);
contextMenu.Items.Add(exitItem);
contextMenu.Opening += (sender, e) =>
{
var remain = SettingsData.Default.GetTimeToBreak().Add(lastStart - DateTime.Now);
if (remain < TimeSpan.Zero) remain = TimeSpan.Zero;
var remainString = string.Format("{0}:{1}:{2}", remain.Hours, remain.Minutes, remain.Seconds);
timeItem.Text = $"Break in ({remainString})";
};
// Setup tray icon
trayIcon.Icon = SystemIcons.Warning;
trayIcon.Text = "TimeBreak Screen App";
trayIcon.ContextMenuStrip = contextMenu;
trayIcon.Visible = true;
Application.Run();
}
private static void StopTimerAndShowBlackScreen(int minutes)
{
breakTimer.Stop();
if (blackScreen is null || blackScreen.IsDisposed || !blackScreen.Visible)
{
blackScreen = new BlackScreenForm();
blackScreen.FormClosed += (object sender, FormClosedEventArgs e) =>
{
breakTimer.Interval = SettingsData.Default.GetBreakInterval();
breakTimer.Start();
lastStart = DateTime.Now;
};
blackScreen.ShowForDuration(minutes);
}
}
}