Skip to content

Commit

Permalink
Improvements in logging and keepalive feature
Browse files Browse the repository at this point in the history
  • Loading branch information
nefares committed Dec 18, 2023
1 parent eeebf07 commit 892da69
Show file tree
Hide file tree
Showing 5 changed files with 541 additions and 413 deletions.
4 changes: 3 additions & 1 deletion WinBGMute/ForegroundProcessManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ UInt32 dwmsEventTime

if (!m_JobStack.IsEmpty)
{
//LoggingEngine.LogLine("[!] discrading previous foreground processes ");
LoggingEngine.LogLine("[*] discrading previous foreground processes ");
}
m_JobStack.Clear();

Expand All @@ -109,11 +109,13 @@ UInt32 dwmsEventTime
TODO: in the future, remove the whole WinEventProc (and the related stack) and replace them with the following piece of code which does the same job more reliably */
int poll_fpid = PollForegroundProcessId();

/* there was a change in the foreground process */
if (m_lastForegroundId != poll_fpid)
{
success = true;
m_lastForegroundId = poll_fpid;
}
/* no change */
else
{
success = false;
Expand Down
17 changes: 16 additions & 1 deletion WinBGMute/LoggingEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using System.Diagnostics;
using System.Runtime.InteropServices;

namespace WinBGMuter
Expand All @@ -33,6 +34,8 @@ public enum LOG_LEVEL_TYPE {LOG_NONE, LOG_ERROR, LOG_WARNING, LOG_INFO, LOG_DEBU

public static LOG_LEVEL_TYPE LogLevel { get; set; }

public static bool HasDateTime { get; set; }

[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole();
Expand Down Expand Up @@ -80,6 +83,15 @@ public static void SetEngine(_LogFunction logfn, _LogLineFunction loglinefn)
m_logLineFunction = loglinefn;
}

private static string FormatInput(object input, LOG_LEVEL_TYPE loglevel = LOG_LEVEL_TYPE.LOG_DEBUG)
{
string output = "";
output += HasDateTime ? DateTime.Now.ToString("dd/MM/yyyy H:mm:ss:fff") : "";
output += " > ";
output += input;

return output;
}
public static void Log(object input, object? color = null, object? font = null, LOG_LEVEL_TYPE loglevel = LOG_LEVEL_TYPE.LOG_DEBUG)
{
if (!Enabled)
Expand All @@ -90,6 +102,8 @@ public static void Log(object input, object? color = null, object? font = null,
{
return;
}


m_logFunction(input, color, font);
}

Expand All @@ -102,7 +116,8 @@ public static void LogLine(object input, object? color = null, object? font = nu
{
return;
}
m_logLineFunction(input, color, font);

m_logLineFunction(FormatInput(input), color, font);
}

}
Expand Down
Loading

0 comments on commit 892da69

Please sign in to comment.