Skip to content

Commit

Permalink
Add Sleep Timer
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianlungu committed Jun 2, 2020
1 parent 6906aef commit 21545d0
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ You can also use a **keyboard shortcut** to put your screens to sleep. Configure

Find the latest release [here](https://github.com/AdrianLungu/ScreenSleep/releases).

Or just download version 1.0.0 from [here](https://github.com/AdrianLungu/ScreenSleep/releases/download/v1.0.0/ScreenSleep-1.0.0.7z).
Or just download version 1.0.1 from [here](https://github.com/AdrianLungu/ScreenSleep/releases/download/v1.0.1/ScreenSleep-1.0.1.7z).

Just decompress it to your favourite folder and run it as is!

Expand Down
3 changes: 3 additions & 0 deletions ScreenSleep/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<setting name="SleepShortcut" serializeAs="String">
<value>Ctrl+Shift+M</value>
</setting>
<setting name="SleepTimer" serializeAs="String">
<value>1</value>
</setting>
</ScreenSleep.Properties.Settings>
</userSettings>
</configuration>
3 changes: 2 additions & 1 deletion ScreenSleep/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;

Expand Down Expand Up @@ -47,7 +48,7 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
{
if (msg == 0x0312 && wParam.ToInt32() == Settings.HotkeyId)
{
TurnOff_OnClick(null, null);
Task.Delay(1000 * Properties.Settings.Default.SleepTimer).ContinueWith(t => TurnOff_OnClick(null, null));
}

return IntPtr.Zero;
Expand Down
14 changes: 13 additions & 1 deletion ScreenSleep/Properties/Settings.Designer.cs

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

3 changes: 3 additions & 0 deletions ScreenSleep/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
<Setting Name="SleepShortcut" Type="System.String" Scope="User">
<Value Profile="(Default)">Ctrl+Shift+M</Value>
</Setting>
<Setting Name="SleepTimer" Type="System.Int32" Scope="User">
<Value Profile="(Default)">1</Value>
</Setting>
</Settings>
</SettingsFile>
13 changes: 12 additions & 1 deletion ScreenSleep/Settings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@

<TextBlock>Turn Off Screen SleepShortcut</TextBlock>
<TextBox Name="ShortcutTextBox" PreviewKeyDown="ShortcutTextBox_PreviewKeyDown" Height="26"></TextBox>
<Separator Margin="0,0,0,5"></Separator>

<TextBlock>Turn Off Timer</TextBlock>
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBox DockPanel.Dock="Left" Name="TimerTextBox" PreviewKeyDown="TimerTextBox_PreviewKeyDown" Height="26" Margin="0,0,10,0" PreviewTextInput="TimerTextBox_PreviewTextInput"></TextBox>
<TextBlock Grid.Column="1" DockPanel.Dock="Right" TextAlignment="Left" Margin="0,4,0,0">seconds</TextBlock>
</Grid>

<Separator Margin="0,10,0,10"></Separator>
<CheckBox Name="RunCheckbox" Unchecked="RunCheckbox_OnChecked" Checked="RunCheckbox_OnChecked">Run ScreenSleep At Startup</CheckBox>

</StackPanel>
Expand Down
23 changes: 23 additions & 0 deletions ScreenSleep/Settings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public Settings()
_helper = ((MainWindow) Application.Current.MainWindow).Helper;

ShortcutTextBox.Text = Properties.Settings.Default.SleepShortcut;
TimerTextBox.Text = Properties.Settings.Default.SleepTimer.ToString();
RunCheckbox.IsChecked = Properties.Settings.Default.RunOnStartup;
}

Expand Down Expand Up @@ -139,5 +140,27 @@ private void RunCheckbox_OnChecked(object sender, RoutedEventArgs e)
Properties.Settings.Default.Save();
SetupStartup();
}

private void TimerTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
var timerText = TimerTextBox.Text;
int timer;

var isNumeric = int.TryParse(timerText, out timer);

if (!isNumeric) {
Properties.Settings.Default.SleepTimer = 1;
} else {
Properties.Settings.Default.SleepTimer = timer;
}

Properties.Settings.Default.Save();
}

private void TimerTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
var isNumeric = int.TryParse(e.Text, out _);
e.Handled = isNumeric;
}
}
}
Binary file added ScreenSleep/bin/Release/ScreenSleep-1.0.1.7z
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")]
Binary file not shown.
Binary file not shown.
Binary file not shown.
31 changes: 27 additions & 4 deletions ScreenSleep/obj/Debug/Settings.g.i.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "..\..\Settings.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "075CC3098A62CBF825A70CCCEA34E1630532BE9F51FB499C1D3B1CAE4BB613BE"
#pragma checksum "..\..\Settings.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "A2EA36D819E44D6E3093FC65E2A5CDFBC5C2041E3ADC34D18D1719982F2CF451"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
Expand Down Expand Up @@ -48,7 +48,15 @@ public partial class Settings : System.Windows.Window, System.Windows.Markup.ICo
#line hidden


#line 25 "..\..\Settings.xaml"
#line 31 "..\..\Settings.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox TimerTextBox;

#line default
#line hidden


#line 36 "..\..\Settings.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.CheckBox RunCheckbox;

Expand Down Expand Up @@ -95,15 +103,30 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object
#line hidden
return;
case 2:
this.TimerTextBox = ((System.Windows.Controls.TextBox)(target));

#line 31 "..\..\Settings.xaml"
this.TimerTextBox.PreviewKeyDown += new System.Windows.Input.KeyEventHandler(this.TimerTextBox_PreviewKeyDown);

#line default
#line hidden

#line 31 "..\..\Settings.xaml"
this.TimerTextBox.PreviewTextInput += new System.Windows.Input.TextCompositionEventHandler(this.TimerTextBox_PreviewTextInput);

#line default
#line hidden
return;
case 3:
this.RunCheckbox = ((System.Windows.Controls.CheckBox)(target));

#line 25 "..\..\Settings.xaml"
#line 36 "..\..\Settings.xaml"
this.RunCheckbox.Unchecked += new System.Windows.RoutedEventHandler(this.RunCheckbox_OnChecked);

#line default
#line hidden

#line 25 "..\..\Settings.xaml"
#line 36 "..\..\Settings.xaml"
this.RunCheckbox.Checked += new System.Windows.RoutedEventHandler(this.RunCheckbox_OnChecked);

#line default
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")]
4 changes: 4 additions & 0 deletions ScreenSleep/obj/Release/ScreenSleep_MarkupCompile.i.lref
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@


FD:\Programming Stuff\ScreenSleep\ScreenSleep\MainWindow.xaml;;

31 changes: 27 additions & 4 deletions ScreenSleep/obj/Release/Settings.g.i.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "..\..\Settings.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "075CC3098A62CBF825A70CCCEA34E1630532BE9F51FB499C1D3B1CAE4BB613BE"
#pragma checksum "..\..\Settings.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "A2EA36D819E44D6E3093FC65E2A5CDFBC5C2041E3ADC34D18D1719982F2CF451"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
Expand Down Expand Up @@ -48,7 +48,15 @@ public partial class Settings : System.Windows.Window, System.Windows.Markup.ICo
#line hidden


#line 25 "..\..\Settings.xaml"
#line 31 "..\..\Settings.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox TimerTextBox;

#line default
#line hidden


#line 36 "..\..\Settings.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.CheckBox RunCheckbox;

Expand Down Expand Up @@ -95,15 +103,30 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object
#line hidden
return;
case 2:
this.TimerTextBox = ((System.Windows.Controls.TextBox)(target));

#line 31 "..\..\Settings.xaml"
this.TimerTextBox.PreviewKeyDown += new System.Windows.Input.KeyEventHandler(this.TimerTextBox_PreviewKeyDown);

#line default
#line hidden

#line 31 "..\..\Settings.xaml"
this.TimerTextBox.PreviewTextInput += new System.Windows.Input.TextCompositionEventHandler(this.TimerTextBox_PreviewTextInput);

#line default
#line hidden
return;
case 3:
this.RunCheckbox = ((System.Windows.Controls.CheckBox)(target));

#line 25 "..\..\Settings.xaml"
#line 36 "..\..\Settings.xaml"
this.RunCheckbox.Unchecked += new System.Windows.RoutedEventHandler(this.RunCheckbox_OnChecked);

#line default
#line hidden

#line 25 "..\..\Settings.xaml"
#line 36 "..\..\Settings.xaml"
this.RunCheckbox.Checked += new System.Windows.RoutedEventHandler(this.RunCheckbox_OnChecked);

#line default
Expand Down

0 comments on commit 21545d0

Please sign in to comment.