Skip to content

Commit

Permalink
initial version, seems to work OK
Browse files Browse the repository at this point in the history
  • Loading branch information
mrosack committed Nov 5, 2020
0 parents commit 0dc0167
Show file tree
Hide file tree
Showing 14 changed files with 2,690 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.vs
bin
obj
*.user
/WatchSleepBlockers.zip
20 changes: 20 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2020 Michael Rosack ([email protected])

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
WatchSleepBlockers
==================

A simple .NET Core 3.1 WinForms application to let you know if your computer is doing something that'll prevent it from sleeping.

Emoji from https://openmoji.org/
25 changes: 25 additions & 0 deletions WatchSleepBlockers.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 Version 16
VisualStudioVersion = 16.0.30621.155
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WatchSleepBlockers", "WatchSleepBlockers\WatchSleepBlockers.csproj", "{3EEB7F63-73E5-4239-8CAA-D7FCDA7BDFFC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3EEB7F63-73E5-4239-8CAA-D7FCDA7BDFFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3EEB7F63-73E5-4239-8CAA-D7FCDA7BDFFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3EEB7F63-73E5-4239-8CAA-D7FCDA7BDFFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3EEB7F63-73E5-4239-8CAA-D7FCDA7BDFFC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AFD3F70E-CAF1-4735-9226-E885BBADA317}
EndGlobalSection
EndGlobal
79 changes: 79 additions & 0 deletions WatchSleepBlockers/MainForm.Designer.cs

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

63 changes: 63 additions & 0 deletions WatchSleepBlockers/MainForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WatchSleepBlockers
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
checkPowercfgTimer_Tick(null, null);
}

private void MainForm_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
Hide();
trayIcon.Visible = true;
}
}

private void trayIcon_MouseClick(object sender, MouseEventArgs e)
{
Show();
this.WindowState = FormWindowState.Normal;
trayIcon.Visible = false;

}

private async void checkPowercfgTimer_Tick(object sender, EventArgs e)
{
var requests = await PowercfgRequestParser.GetActiveRequests();
Icon icon;

if (requests.Length == 0)
{
blockersLabel.Text = "There is nothing preventing this computer from sleeping!";
icon = new System.Drawing.Icon("sleeping_emoji.ico");
}
else
{
blockersLabel.Text = "The following issues are preventing the computer from sleeping: " + Environment.NewLine + Environment.NewLine;
icon = new System.Drawing.Icon("angry_face_with_horns.ico");

foreach (var request in requests)
{
blockersLabel.Text += request + Environment.NewLine;
}
}

this.Icon = icon;
trayIcon.Icon = icon;
}
}
}
Loading

0 comments on commit 0dc0167

Please sign in to comment.