Skip to content

Commit

Permalink
Initial application
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Spreitzer committed Jun 19, 2019
1 parent fd7b27e commit f77836c
Show file tree
Hide file tree
Showing 18 changed files with 1,025 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/NoDoz.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.645
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoDoz", "NoDoz\NoDoz.csproj", "{D708116A-8BB6-4490-830F-651CD3F7A105}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D708116A-8BB6-4490-830F-651CD3F7A105}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D708116A-8BB6-4490-830F-651CD3F7A105}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D708116A-8BB6-4490-830F-651CD3F7A105}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D708116A-8BB6-4490-830F-651CD3F7A105}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B4D27703-D291-4085-B497-8FB7F7497910}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions src/NoDoz/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
101 changes: 101 additions & 0 deletions src/NoDoz/Form1.Designer.cs

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

115 changes: 115 additions & 0 deletions src/NoDoz/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NoDoz
{
public partial class Form1 : Form
{
private readonly System.Timers.Timer _timer = new System.Timers.Timer(1000);
private readonly Stopwatch _stopwatch = new Stopwatch();
private readonly double _totalDuration;
private readonly bool _startMinimized;

public Form1(Options args)
{
InitializeComponent();
_startMinimized = args.Minimize;

if (args.Timeout.HasValue)
{
_totalDuration = args.Timeout.Value.TotalMilliseconds;
label1.Text = args.Timeout.Value.ToString("HH:m:ss", null);

_timer.Elapsed += _timer_Elapsed;
_timer.SynchronizingObject = this;
_timer.Start();

_stopwatch.Start();
}
else
{
label1.Font = new Font(new FontFamily("Open Sans"), 12.5f);
label1.Text = "No timeout specified.";
}
}

private async void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
label1.Text = TimeRemaining().ToString(@"hh\:mm\:ss");
if (_stopwatch.ElapsedMilliseconds >= _totalDuration)
{
_timer.Stop();
Hide();
ShowBalloon("Hey dude. I'm outta here...");
await Task.Delay(5000);
Close();
}
}

private void Form1_Load(object sender, EventArgs e)
{
SystemSleep.Prevent();
}

private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
Hide();
ShowBalloon();
}
}

private void Form1_Shown(object sender, EventArgs e)
{
if (_startMinimized)
{
Hide();
ShowBalloon();
}
}

private void Form1_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Escape:
Hide();
ShowBalloon();
return;
case Keys.X:
Close();
return;
case Keys.H:
Process.Start(@"https://github.com/refactorsaurusrex/NoDoz/wiki");
return;
}
}

private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Show();
WindowState = FormWindowState.Normal;
}
}

private TimeSpan TimeRemaining() => TimeSpan.FromMilliseconds(_totalDuration - _stopwatch.ElapsedMilliseconds);

private void ShowBalloon(string message = null)
{
var r = TimeRemaining();
var text = message ?? (_timer.Enabled ? $"{r.Hours} hours, {r.Minutes} minutes, {r.Seconds} seconds remaining..." : "NoDoz is running indefinitely...");
notifyIcon1.ShowBalloonTip(3000, "NoDoz", text, ToolTipIcon.None);
}

private void linkLabel1_Click(object sender, EventArgs e)
{
Process.Start(@"https://github.com/refactorsaurusrex/NoDoz/wiki");
}
}
}
Loading

0 comments on commit f77836c

Please sign in to comment.