Skip to content

Commit

Permalink
Adds support for delaying the idle timer until the user has first int…
Browse files Browse the repository at this point in the history
…eracted with the session
  • Loading branch information
ryannewington committed Apr 1, 2022
1 parent ae9f6b2 commit e2d7b0a
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<string id="pol_show_warning_message">Show a warning message before logging off</string>
<string id="pol_show_warning_message_help">Shows a pop up notification informing the user of the time remaining before they are logged off.

You can optionally provide a custom message to show the user. Use {0} as a placeholder for the remaining time until logoff.
You can optionally provide a custom message to show the user. Use {0} as a placeholder for the remaining time until logoff.
</string>
<string id="string_logoff">Log off</string>
<string id="string_reboot">Reboot</string>
Expand All @@ -28,8 +28,9 @@
</presentation>
<presentation id="pol_enable_idle_logoff">
<decimalTextBox refId="txt_idle_limit" defaultValue="60">Idle timeout (minutes)</decimalTextBox>
<checkBox refId="ck_ignore_display_requested" defaultChecked="false">Ignore sleep prevention requests from applications such as media playback</checkBox>
<dropdownList refId="dd_idle_action" defaultItem ="0">Action</dropdownList>
<checkBox refId="ck_ignore_display_requested" defaultChecked="false">Ignore sleep prevention requests from applications such as media playback</checkBox>
<checkBox refId="ck_wait_for_input" defaultChecked="false">Wait for initial user interaction before starting idle timer (kiosk mode)</checkBox>
<dropdownList refId="dd_idle_action" defaultItem ="0">Action</dropdownList>
</presentation>
</presentationTable>
</resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
<decimal value="0" />
</falseValue>
</boolean>
<boolean id="ck_wait_for_input" key="Software\Policies\Lithnet\IdleLogoff" valueName="WaitForInitialInput">
<trueValue>
<decimal value="1" />
</trueValue>
<falseValue>
<decimal value="0" />
</falseValue>
</boolean>
<enum id="dd_idle_action" key="Software\Policies\Lithnet\IdleLogoff" valueName="Action">
<item displayName="$(string.string_logoff)">
<value>
Expand Down
13 changes: 11 additions & 2 deletions src/Lithnet.IdleLogoff/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Lithnet.idlelogoff
public static class Program
{
private static uint lastTicks;
private static uint startingTicks;

private static readonly int idleCheckSeconds = 15;

Expand Down Expand Up @@ -61,6 +62,7 @@ private static void InitTimer()
EventLogging.TryLogEvent($"The application has started, but is not enabled. User {Environment.UserDomainName}\\{Environment.UserName} will not be logged off automatically", EventLogging.EvtTimerstarted);
}

Program.startingTicks = NativeMethods.GetLastInputTime();
Program.eventTimer = new Timer();
Program.eventTimer.Tick += Program.EventTimer_Tick;
Program.eventTimer.Interval = (int)TimeSpan.FromSeconds(Program.idleCheckSeconds).TotalMilliseconds;
Expand Down Expand Up @@ -88,8 +90,9 @@ private static void ValidateCommandLineArgs()
}
else
{
MessageBox.Show($"An invalid command line argument was specified: {arg}");
Environment.Exit(1);
Trace.WriteLine($"An invalid command line argument was specified: {arg}");
// MessageBox.Show($"An invalid command line argument was specified: {arg}");
// Environment.Exit(1);
}
}
}
Expand Down Expand Up @@ -118,6 +121,12 @@ private static void EventTimer_Tick(object sender, EventArgs e)
Program.ResetIdleStatus(currentticks);
return;
}
else if (Settings.WaitForInitialInput && currentticks == Program.startingTicks)
{
Trace.WriteLine($"Initial input not yet received ({currentticks}=={Program.startingTicks})");
Program.ResetIdleStatus(currentticks);
return;
}
else if (Program.HasInput(currentticks))
{
Trace.WriteLine("Input received");
Expand Down
29 changes: 29 additions & 0 deletions src/Lithnet.IdleLogoff/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,35 @@ public static bool Enabled
set => Settings.SaveSetting("Enabled", Convert.ToInt32(value), RegistryValueKind.DWord);
}

public static bool WaitForInitialInput
{
get
{
object value = null;
bool status = false;

value = Settings.GetPolicyOrSetting("WaitForInitialInput");
if (value != null)
{
try
{
if ((int)value == 1)
{
status = true;
}
}
catch
{
//unable to cast
}

}
return status;
}
set => Settings.SaveSetting("WaitForInitialInput", Convert.ToInt32(value), RegistryValueKind.DWord);
}


public static bool WarningEnabled
{
get
Expand Down
86 changes: 51 additions & 35 deletions src/Lithnet.IdleLogoff/frmSettings.Designer.cs

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

14 changes: 9 additions & 5 deletions src/Lithnet.IdleLogoff/frmSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ private void RefreshUI()
this.txtWarningMessage.Enabled = !Settings.IsSettingFromPolicy(nameof(Settings.WarningMessage));
this.txtWarningMessage.Text = Settings.WarningMessage;

if (!this.udMinutes.Enabled | !this.ckEnableIdleLogoff.Enabled | !this.ckIgnoreDisplayRequested.Enabled | !this.udWarning.Enabled | !this.txtWarningMessage.Enabled | !this.ckShowWarning.Enabled)
this.ckWaitForInput.Enabled = !Settings.IsSettingFromPolicy(nameof(Settings.WaitForInitialInput));
this.ckWaitForInput.Checked = Settings.WaitForInitialInput;

if (!this.udMinutes.Enabled | !this.ckEnableIdleLogoff.Enabled | !this.ckIgnoreDisplayRequested.Enabled | !this.udWarning.Enabled | !this.txtWarningMessage.Enabled | !this.ckShowWarning.Enabled | !this.ckWaitForInput.Enabled)
{
this.lbGPControlled.Visible = true;
}
Expand Down Expand Up @@ -96,6 +99,11 @@ private void btOK_Click(object sender, EventArgs e)
Settings.WarningPeriod = (int)this.udWarning.Value;
}

if (this.ckWaitForInput.Enabled)
{
Settings.WaitForInitialInput = this.ckWaitForInput.Checked;
}

if (this.cbAction.Enabled)
{
Settings.Action = (IdleTimeoutAction)Enum.Parse(typeof(IdleTimeoutAction), (string)this.cbAction.SelectedItem, true);
Expand Down Expand Up @@ -131,9 +139,5 @@ private void btCancel_Click(object sender, EventArgs e)
Environment.Exit(0);
}

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{

}
}
}
4 changes: 1 addition & 3 deletions src/Lithnet.IdleLogoff/lithnet.idlelogoff.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>"C:\Program Files (x86)\Microsoft SDKs\ClickOnce\SignTool\signtool.exe" sign /sha1 "$(CSCERTTHUMBPRINT)" /t http://timestamp.digicert.com /fd sha256 /v "$(TargetPath)"
"C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\symstore" add /f "$(TargetDir)*.pdb" /s \\localhost\symbols /t "$(ProjectName)" /v "@(VersionNumber)"
</PostBuildEvent>
<PostBuildEvent>call %25BuildToolsPath%25\sign-ev-and-save-symbols.bat $(TargetPath) $(TargetDir) $(ProjectName)</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Loading

0 comments on commit e2d7b0a

Please sign in to comment.