Skip to content

Commit 21545d0

Browse files
committed
Add Sleep Timer
1 parent 6906aef commit 21545d0

16 files changed

+123
-12
lines changed

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ You can also use a **keyboard shortcut** to put your screens to sleep. Configure
1919

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

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

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

ScreenSleep/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<setting name="SleepShortcut" serializeAs="String">
1717
<value>Ctrl+Shift+M</value>
1818
</setting>
19+
<setting name="SleepTimer" serializeAs="String">
20+
<value>1</value>
21+
</setting>
1922
</ScreenSleep.Properties.Settings>
2023
</userSettings>
2124
</configuration>

ScreenSleep/MainWindow.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Threading.Tasks;
23
using System.Windows;
34
using System.Windows.Interop;
45

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

5354
return IntPtr.Zero;

ScreenSleep/Properties/Settings.Designer.cs

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ScreenSleep/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
<Setting Name="SleepShortcut" Type="System.String" Scope="User">
99
<Value Profile="(Default)">Ctrl+Shift+M</Value>
1010
</Setting>
11+
<Setting Name="SleepTimer" Type="System.Int32" Scope="User">
12+
<Value Profile="(Default)">1</Value>
13+
</Setting>
1114
</Settings>
1215
</SettingsFile>

ScreenSleep/Settings.xaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,18 @@
2121

2222
<TextBlock>Turn Off Screen SleepShortcut</TextBlock>
2323
<TextBox Name="ShortcutTextBox" PreviewKeyDown="ShortcutTextBox_PreviewKeyDown" Height="26"></TextBox>
24-
<Separator Margin="0,0,0,5"></Separator>
24+
25+
<TextBlock>Turn Off Timer</TextBlock>
26+
<Grid HorizontalAlignment="Stretch">
27+
<Grid.ColumnDefinitions>
28+
<ColumnDefinition Width="*"></ColumnDefinition>
29+
<ColumnDefinition Width="50"></ColumnDefinition>
30+
</Grid.ColumnDefinitions>
31+
<TextBox DockPanel.Dock="Left" Name="TimerTextBox" PreviewKeyDown="TimerTextBox_PreviewKeyDown" Height="26" Margin="0,0,10,0" PreviewTextInput="TimerTextBox_PreviewTextInput"></TextBox>
32+
<TextBlock Grid.Column="1" DockPanel.Dock="Right" TextAlignment="Left" Margin="0,4,0,0">seconds</TextBlock>
33+
</Grid>
34+
35+
<Separator Margin="0,10,0,10"></Separator>
2536
<CheckBox Name="RunCheckbox" Unchecked="RunCheckbox_OnChecked" Checked="RunCheckbox_OnChecked">Run ScreenSleep At Startup</CheckBox>
2637

2738
</StackPanel>

ScreenSleep/Settings.xaml.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public Settings()
3030
_helper = ((MainWindow) Application.Current.MainWindow).Helper;
3131

3232
ShortcutTextBox.Text = Properties.Settings.Default.SleepShortcut;
33+
TimerTextBox.Text = Properties.Settings.Default.SleepTimer.ToString();
3334
RunCheckbox.IsChecked = Properties.Settings.Default.RunOnStartup;
3435
}
3536

@@ -139,5 +140,27 @@ private void RunCheckbox_OnChecked(object sender, RoutedEventArgs e)
139140
Properties.Settings.Default.Save();
140141
SetupStartup();
141142
}
143+
144+
private void TimerTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
145+
{
146+
var timerText = TimerTextBox.Text;
147+
int timer;
148+
149+
var isNumeric = int.TryParse(timerText, out timer);
150+
151+
if (!isNumeric) {
152+
Properties.Settings.Default.SleepTimer = 1;
153+
} else {
154+
Properties.Settings.Default.SleepTimer = timer;
155+
}
156+
157+
Properties.Settings.Default.Save();
158+
}
159+
160+
private void TimerTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
161+
{
162+
var isNumeric = int.TryParse(e.Text, out _);
163+
e.Handled = isNumeric;
164+
}
142165
}
143166
}
55 KB
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// <autogenerated />
2+
using System;
3+
using System.Reflection;
4+
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")]

0 commit comments

Comments
 (0)