Skip to content

Commit 137df7e

Browse files
committed
Allow to set custom working days
1 parent 6ea5b20 commit 137df7e

17 files changed

Lines changed: 302 additions & 12 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
/.vs/
22
/bin/
33
/obj/
4+
/packages/
5+
/WeekendOffConfigurator/obj/
6+
*.csproj.user

ProcessToKillList.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Teams
2+
Dropbox
3+
DropboxUpdate

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# WeekendOff
22
You are working from home and are bored from having to quit Teams and other work-related softs? Here is the solution!
33

4-
Weekend Off will kill these apps on the weekend only.
4+
Weekend Off will kill these apps on the weekend only (or any day you like).
55

66
Download the latest release and create a link to the executable here: %userprofile%/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup
77

Main.cs renamed to WeekendOff.cs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,54 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.IO;
5+
using System.Linq;
56
using System.Runtime.InteropServices;
67
using System.Threading;
78

89
namespace WeekendOff
910
{
1011
/// <summary>
11-
/// Kill Microsoft Teams and Hansoft or any process written in ProcessToKillList.txt (one process by line) on weekend.
12+
/// Kill Microsoft Teams or any process written in ProcessToKillList.txt (one process by line) on weekend.
1213
/// Waits for maximum 5 minutes to find the processes and kill them.
1314
/// Ends when all are killed or timed out.
1415
/// </summary>
1516
// ReSharper disable once ClassNeverInstantiated.Global
1617
internal class WeekendOff
1718
{
18-
public static readonly List<string> ProcessToKillOnWeekend = new List<string> {"Teams", "HPMClient_x64"};
19+
public static readonly List<string> ProcessToKillOnWeekend = new List<string> {"Teams"};
1920

2021
/// <summary>
21-
/// Stops trying to kill after 5 minutes.
22+
/// Stops trying to kill after 2 minutes.
2223
/// </summary>
23-
public static int Timeout = 5 * 60;
24+
public static int Timeout = 2 * 60 * 1000;
2425

2526
private static void Main()
2627
{
28+
List<DayOfWeek> workingDays = new List<DayOfWeek> { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday };
29+
List<(int, int)> workingHours = new List<(int, int)> { (0, 24), (0, 24), (0, 24), (0, 24), (0, 24) };
30+
try
31+
{
32+
var lines = File.ReadAllLines("WorkingDaysConfig.txt");
33+
workingDays.Clear();
34+
workingDays.AddRange(lines.Select(s => (DayOfWeek)Enum.Parse(typeof(DayOfWeek), s.Split(':')[0])));
35+
workingHours.Clear();
36+
workingHours.AddRange(lines.Select(s =>
37+
{
38+
var xToY = s.Split(':')[1];
39+
var xy = xToY.Split(new[] { "to" }, StringSplitOptions.None);
40+
return (int.Parse(xy[0]), int.Parse(xy[1]));
41+
}));
42+
}
43+
// ReSharper disable once EmptyGeneralCatchClause
44+
catch { }
2745
DayOfWeek day = DateTime.Now.DayOfWeek;
28-
if (day != DayOfWeek.Saturday && day != DayOfWeek.Sunday)
46+
int configDayIndex = workingDays.IndexOf(day);
47+
if (configDayIndex != -1)
2948
{
30-
return;
49+
int dayHour = DateTime.Now.Hour;
50+
var dayWorkingHours = workingHours[configDayIndex];
51+
if (dayHour >= dayWorkingHours.Item1 && dayHour <= dayWorkingHours.Item2)
52+
return;
3153
}
3254

3355
try
@@ -41,13 +63,12 @@ private static void Main()
4163

4264
List<string> toKillList = new List<string> (ProcessToKillOnWeekend);
4365

44-
Process[] processes;
4566
int timeSpent = 0;
4667
while (timeSpent < Timeout)
4768
{
4869
Thread.Sleep(5);
4970
timeSpent += 5;
50-
processes = Process.GetProcesses();
71+
var processes = Process.GetProcesses();
5172
foreach (var pToKill in ProcessToKillOnWeekend)
5273
{
5374
foreach (var process in processes)

WeekendOff.csproj

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@
4040
<ItemGroup>
4141
<Reference Include="System" />
4242
<Reference Include="System.Core" />
43+
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
44+
<HintPath>packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
45+
</Reference>
4346
</ItemGroup>
4447
<ItemGroup>
45-
<Compile Include="Main.cs" />
48+
<Compile Include="WeekendOff.cs" />
4649
<Compile Include="Properties\Resources.Designer.cs">
4750
<AutoGen>True</AutoGen>
4851
<DesignTime>True</DesignTime>
@@ -57,6 +60,7 @@
5760
<Generator>ResXFileCodeGenerator</Generator>
5861
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
5962
</EmbeddedResource>
63+
<None Include="packages.config" />
6064
<None Include="Properties\Settings.settings">
6165
<Generator>SettingsSingleFileGenerator</Generator>
6266
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -65,5 +69,15 @@
6569
<ItemGroup>
6670
<Resource Include="sunbed.ico" />
6771
</ItemGroup>
72+
<ItemGroup>
73+
<AdditionalFiles Include="ProcessToKillList.txt">
74+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
75+
</AdditionalFiles>
76+
</ItemGroup>
77+
<ItemGroup>
78+
<AdditionalFiles Include="WorkingDaysConfig.txt">
79+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
80+
</AdditionalFiles>
81+
</ItemGroup>
6882
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
6983
</Project>

WeekendOff.sln

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,46 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.31005.135
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.1.32328.378
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WeekendOff", "WeekendOff.csproj", "{48CE12C2-E19E-489A-AA0C-B7B9C37B9E6D}"
77
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WeekendOffConfigurator", "WeekendOffConfigurator\WeekendOffConfigurator.csproj", "{E6C58137-FC3D-47A0-B00E-70FCD2E7F37F}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
13+
Debug|x64 = Debug|x64
14+
Debug|x86 = Debug|x86
1115
Release|Any CPU = Release|Any CPU
16+
Release|x64 = Release|x64
17+
Release|x86 = Release|x86
1218
EndGlobalSection
1319
GlobalSection(ProjectConfigurationPlatforms) = postSolution
1420
{48CE12C2-E19E-489A-AA0C-B7B9C37B9E6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1521
{48CE12C2-E19E-489A-AA0C-B7B9C37B9E6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{48CE12C2-E19E-489A-AA0C-B7B9C37B9E6D}.Debug|x64.ActiveCfg = Debug|Any CPU
23+
{48CE12C2-E19E-489A-AA0C-B7B9C37B9E6D}.Debug|x64.Build.0 = Debug|Any CPU
24+
{48CE12C2-E19E-489A-AA0C-B7B9C37B9E6D}.Debug|x86.ActiveCfg = Debug|Any CPU
25+
{48CE12C2-E19E-489A-AA0C-B7B9C37B9E6D}.Debug|x86.Build.0 = Debug|Any CPU
1626
{48CE12C2-E19E-489A-AA0C-B7B9C37B9E6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
1727
{48CE12C2-E19E-489A-AA0C-B7B9C37B9E6D}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{48CE12C2-E19E-489A-AA0C-B7B9C37B9E6D}.Release|x64.ActiveCfg = Release|Any CPU
29+
{48CE12C2-E19E-489A-AA0C-B7B9C37B9E6D}.Release|x64.Build.0 = Release|Any CPU
30+
{48CE12C2-E19E-489A-AA0C-B7B9C37B9E6D}.Release|x86.ActiveCfg = Release|Any CPU
31+
{48CE12C2-E19E-489A-AA0C-B7B9C37B9E6D}.Release|x86.Build.0 = Release|Any CPU
32+
{E6C58137-FC3D-47A0-B00E-70FCD2E7F37F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{E6C58137-FC3D-47A0-B00E-70FCD2E7F37F}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{E6C58137-FC3D-47A0-B00E-70FCD2E7F37F}.Debug|x64.ActiveCfg = Debug|Any CPU
35+
{E6C58137-FC3D-47A0-B00E-70FCD2E7F37F}.Debug|x64.Build.0 = Debug|Any CPU
36+
{E6C58137-FC3D-47A0-B00E-70FCD2E7F37F}.Debug|x86.ActiveCfg = Debug|Any CPU
37+
{E6C58137-FC3D-47A0-B00E-70FCD2E7F37F}.Debug|x86.Build.0 = Debug|Any CPU
38+
{E6C58137-FC3D-47A0-B00E-70FCD2E7F37F}.Release|Any CPU.ActiveCfg = Release|Any CPU
39+
{E6C58137-FC3D-47A0-B00E-70FCD2E7F37F}.Release|Any CPU.Build.0 = Release|Any CPU
40+
{E6C58137-FC3D-47A0-B00E-70FCD2E7F37F}.Release|x64.ActiveCfg = Release|Any CPU
41+
{E6C58137-FC3D-47A0-B00E-70FCD2E7F37F}.Release|x64.Build.0 = Release|Any CPU
42+
{E6C58137-FC3D-47A0-B00E-70FCD2E7F37F}.Release|x86.ActiveCfg = Release|Any CPU
43+
{E6C58137-FC3D-47A0-B00E-70FCD2E7F37F}.Release|x86.Build.0 = Release|Any CPU
1844
EndGlobalSection
1945
GlobalSection(SolutionProperties) = preSolution
2046
HideSolutionNode = FALSE

WeekendOffConfigurator/App.xaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Application x:Class="WeekendOffConfigurator.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:WeekendOffConfigurator"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
10+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
11+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
12+
<!-- Theme setting -->
13+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />
14+
</ResourceDictionary.MergedDictionaries>
15+
</ResourceDictionary>
16+
</Application.Resources>
17+
</Application>

WeekendOffConfigurator/App.xaml.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace WeekendOffConfigurator
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly: ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<mah:MetroWindow x:Class="WeekendOffConfigurator.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:WeekendOffConfigurator"
7+
xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
8+
xmlns:mah1="http://metro.mahapps.com/winfx/xaml/controls"
9+
mc:Ignorable="d"
10+
TitleCharacterCasing="Normal"
11+
ResizeMode="NoResize"
12+
Title="WeekendOff Configurator" Height="350" Width="650"
13+
d:DataContext="{d:DesignInstance local:MainWindow}">
14+
<StackPanel Orientation="Horizontal">
15+
<Grid>
16+
<Grid.RowDefinitions>
17+
<RowDefinition Height="Auto"/>
18+
<RowDefinition Height="Auto"/>
19+
<RowDefinition Height="Auto"/>
20+
<RowDefinition Height="Auto"/>
21+
<RowDefinition Height="Auto"/>
22+
<RowDefinition Height="Auto"/>
23+
<RowDefinition Height="Auto"/>
24+
<RowDefinition Height="Auto"/>
25+
<RowDefinition Height="Auto"/>
26+
</Grid.RowDefinitions>
27+
<Grid.ColumnDefinitions>
28+
<ColumnDefinition Width="15"/>
29+
<ColumnDefinition Width="Auto"/>
30+
<ColumnDefinition Width="Auto"/>
31+
<ColumnDefinition Width="20"/>
32+
<ColumnDefinition Width="Auto"/>
33+
</Grid.ColumnDefinitions>
34+
35+
<TextBlock Text="Monday" Grid.Row="0" Grid.Column="1" Margin="5,6,0,0" FontSize="16" />
36+
<mah1:ToggleSwitch x:Name="CB_Monday" Grid.Row="0" Grid.Column="2" Margin="15,2,0,0"/>
37+
<TextBlock Text="Tuesday" Grid.Row="1" Grid.Column="1" Margin="5,6,0,0" FontSize="16" />
38+
<mah1:ToggleSwitch x:Name="CB_Tuesday" Grid.Row="1" Grid.Column="2" Margin="15,2,0,0"/>
39+
<TextBlock Text="Wednesday" Grid.Row="2" Grid.Column="1" Margin="5,6,0,0" FontSize="16" />
40+
<mah1:ToggleSwitch x:Name="CB_Wednesday" Grid.Row="2" Grid.Column="2" Margin="15,2,0,0"/>
41+
<TextBlock Text="Thursday" Grid.Row="3" Grid.Column="1" Margin="5,6,0,0" FontSize="16" />
42+
<mah1:ToggleSwitch x:Name="CB_Thursday" Grid.Row="3" Grid.Column="2" Margin="15,2,0,0"/>
43+
<TextBlock Text="Friday" Grid.Row="4" Grid.Column="1" Margin="5,6,0,0" FontSize="16" />
44+
<mah1:ToggleSwitch x:Name="CB_Friday" Grid.Row="4" Grid.Column="2" Margin="15,2,0,0"/>
45+
<TextBlock Text="Saturday" Grid.Row="5" Grid.Column="1" Margin="5,6,0,0" FontSize="16" />
46+
<mah1:ToggleSwitch x:Name="CB_Saturday" Grid.Row="5" Grid.Column="2" Margin="15,2,0,0"/>
47+
<TextBlock Text="Sunday" Grid.Row="6" Grid.Column="1" Margin="5,6,0,0" FontSize="16" />
48+
<mah1:ToggleSwitch x:Name="CB_Sunday" Grid.Row="6" Grid.Column="2" Margin="15,2,0,0"/>
49+
<Button Grid.Row="7" Grid.Column="1" FontSize="14" Click="SaveButtonBase_OnClick" Margin="5,20,0,0">Save</Button>
50+
</Grid>
51+
<StackPanel Orientation="Vertical">
52+
<TextBlock Text="Processes to prevent to start" Margin="5,6,0,0" FontSize="16" />
53+
<TextBox x:Name="TB_Process" Width="300" Height="200" AcceptsReturn="True"></TextBox>
54+
</StackPanel>
55+
</StackPanel>
56+
</mah:MetroWindow>

0 commit comments

Comments
 (0)