Skip to content

Commit

Permalink
imp - brk|doc - Overhauled screensaver timeout interval
Browse files Browse the repository at this point in the history
---

We've made a breaking change to the screen timeout in order to improve the experience of setting it up. It's now easier to set it up, because we've changed from milliseconds to timespan in the format of "DDD.HH:MM:SS.NNNNNN". You can use "HH:MM:SS" as the simplest form.

---

Type: imp
Breaking: True
Doc Required: True
Part: 1/1
  • Loading branch information
AptiviCEO committed Feb 15, 2024
1 parent 2ec50df commit 7f39c23
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
29 changes: 24 additions & 5 deletions public/Nitrocid/Kernel/Configuration/Instances/KernelMainConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ public int PingTimeout
/// </summary>
public string DefaultSaverName { get; set; } = "matrixbleed";
/// <summary>
/// Whether the screen timeout is enabled or not
/// Whether the screen idling is enabled or not
/// </summary>
public bool ScreenTimeoutEnabled
{
Expand All @@ -1031,12 +1031,31 @@ public bool ScreenTimeoutEnabled
}
}
/// <summary>
/// Write when to launch screensaver after specified milliseconds. It must be numeric
/// Minimum idling interval to launch screensaver
/// </summary>
public int ScreenTimeout
public string ScreenTimeout
{
get => ScreensaverManager.scrnTimeout;
set => ScreensaverManager.scrnTimeout = value < 0 ? 300000 : value;
get => ScreensaverManager.scrnTimeout.ToString();
set
{
// First, deal with merging milliseconds from old configs
TimeSpan fallback = new(0, 5, 0);
TimeSpan span;
bool isOldFormat = int.TryParse(value, out int milliseconds);
if (isOldFormat)
{
span = TimeSpan.FromMilliseconds(milliseconds);
ScreensaverManager.scrnTimeout = span.TotalMinutes < 1.0d ? fallback : span;
return;
}

// Then, parse the timespan
bool spanParsed = TimeSpan.TryParse(value, out span);
if (!spanParsed)
ScreensaverManager.scrnTimeout = fallback;
else
ScreensaverManager.scrnTimeout = span.TotalMinutes < 1.0d ? fallback : span;
}
}
/// <summary>
/// Enables debugging for screensavers. Please note that it may quickly fill the debug log and slightly slow the screensaver down, depending on the screensaver used. Only works if kernel debugging is enabled for diagnostic purposes.
Expand Down
17 changes: 12 additions & 5 deletions public/Nitrocid/Misc/Screensaver/ScreensaverManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static class ScreensaverManager
internal static Dictionary<string, BaseScreensaver> AddonSavers = [];
internal static Dictionary<string, BaseScreensaver> CustomSavers = [];
internal static bool scrnTimeoutEnabled = true;
internal static int scrnTimeout = 300000;
internal static TimeSpan scrnTimeout = new(0, 5, 0);
internal static bool LockMode;
internal static bool inSaver;
internal static bool screenRefresh;
Expand Down Expand Up @@ -93,10 +93,17 @@ public static class ScreensaverManager
inSaver;

/// <summary>
/// Screen timeout in milliseconds
/// Screen timeout interval
/// </summary>
public static int ScreenTimeout =>
Config.MainConfig.ScreenTimeout;
public static TimeSpan ScreenTimeout
{
get
{
if (!TimeSpan.TryParse(Config.MainConfig.ScreenTimeout, out TimeSpan timeout))
return new(0, 5, 0);
return timeout;
}
}

/// <summary>
/// Default screensaver name
Expand Down Expand Up @@ -397,7 +404,7 @@ private static void HandleTimeout()
}, ScreenTimeout);

// Check to see if we're locking
bool locking = !hasMoved && stopwatch.ElapsedMilliseconds >= ScreenTimeout;
bool locking = !hasMoved && stopwatch.Elapsed >= ScreenTimeout;
stopwatch.Reset();
if (PowerManager.KernelShutdown || PowerManager.RebootRequested)
break;
Expand Down
2 changes: 1 addition & 1 deletion public/Nitrocid/Nitrocid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<NitrocidModAPIVersionMajor>3.0.25</NitrocidModAPIVersionMajor>

<!-- Increment NitrocidModAPIVersionChangeset every time there is a breaking change or an API addition in the N-KS API. -->
<NitrocidModAPIVersionChangeset>427</NitrocidModAPIVersionChangeset>
<NitrocidModAPIVersionChangeset>428</NitrocidModAPIVersionChangeset>

<!-- To be installed to the file version -->
<NitrocidModAPIVersion>$(NitrocidModAPIVersionMajor).$(NitrocidModAPIVersionChangeset)</NitrocidModAPIVersion>
Expand Down
8 changes: 4 additions & 4 deletions public/Nitrocid/Resources/Settings/SettingsEntries.json
Original file line number Diff line number Diff line change
Expand Up @@ -944,16 +944,16 @@
"Description": "Which screensaver do you want to lock your screen with?"
},
{
"Name": "Enable Screensaver Timeout",
"Name": "Enable screensaver locking when idle",
"Type": "SBoolean",
"Variable": "ScreenTimeoutEnabled",
"Description": "If enabled, the screensaver automatically launches after idling for the specified period."
},
{
"Name": "Screensaver Timeout in ms",
"Type": "SInt",
"Name": "Screensaver minimum idling interval",
"Type": "SString",
"Variable": "ScreenTimeout",
"Description": "Write when to launch screensaver after specified milliseconds. It must be numeric."
"Description": "Minimum idling interval to launch screensaver. The unit is in time span format (HH:MM:SS)."
},
{
"Name": "Enable screensaver debugging",
Expand Down

0 comments on commit 7f39c23

Please sign in to comment.