Skip to content

Commit

Permalink
Enhanced logging, UI, and AFK functionality
Browse files Browse the repository at this point in the history
- App.xaml.cs: Improved exception logging to include message and stack trace.
- OSCController.cs: Refined progress bar time display and customization, fixed a method termination issue.
- UpdateApp.cs: Streamlined application restart process by using the current path for file and directory.
- AfkModule.cs: Optimized AFK detection by removing unused code, refining AFK mode transitions, and updating idle time tracking. Simplified duration formatting and removed the GetIdleTime method for potential refactoring.
  • Loading branch information
BoiHanny committed Jun 19, 2024
2 parents 7f71314 + dd1e0ff commit 2912fd0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 35 deletions.
2 changes: 1 addition & 1 deletion vrcosc-magicchatbox/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected override async void OnStartup(StartupEventArgs e)
// Handle first-chance exceptions (before they are thrown)
private void CurrentDomain_FirstChanceException(object? sender, FirstChanceExceptionEventArgs e)
{

Logging.WriteInfo(e.Exception.Message + Environment.NewLine + e.Exception.StackTrace);
}

Expand Down
22 changes: 11 additions & 11 deletions vrcosc-magicchatbox/Classes/DataAndSecurity/OSCController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,7 @@ private static string CreateProgressBar(double percentage, MediaSessionInfo medi
return string.Empty;
}

int totalBlocks = style.ProgressBarLength;

string currentTime = style.DisplayTime && style.ShowTimeInSuperscript
string currentTime = includeTime && ViewModel.Instance.MediaLinkShowTimeInSuperscript
? DataController.TransformToSuperscript(FormatTimeSpan(mediaSession.CurrentTime))
: FormatTimeSpan(mediaSession.CurrentTime);

Expand All @@ -251,20 +249,21 @@ private static string CreateProgressBar(double percentage, MediaSessionInfo medi
{
int timeStringLength = currentTime.Length + fullTime.Length + 1;

if (totalBlocks > timeStringLength)
if (timeStringLength > 8)
{
totalBlocks -= timeStringLength;
int blocksToRemove = (timeStringLength - 8 + 3) / 4;
totalBlocks = Math.Max(totalBlocks - blocksToRemove, 0);
}
}

int filledBlocks = (int)(percentage / (100.0 / totalBlocks));
char filledChar = style.FilledCharacter[0];
char middleChar = style.MiddleCharacter[0];
char nonFilledChar = style.NonFilledCharacter[0];
char filledChar = ViewModel.Instance.MediaLinkFilledCharacter.ToCharArray()[0];
char middleChar = ViewModel.Instance.MediaLinkMiddleCharacter.ToCharArray()[0];
char nonFilledChar = ViewModel.Instance.MediaLinkNonFilledCharacter.ToCharArray()[0];

string filledBar = new string(filledChar, filledBlocks);
string emptyBar = new string(nonFilledChar, totalBlocks - filledBlocks);
string progressBar = filledBar + middleChar + emptyBar;
string filledBar = string.Concat(Enumerable.Repeat(filledString, filledBlocks));
string emptyBar = string.Concat(Enumerable.Repeat(nonFilledString, totalBlocks - filledBlocks));
string progressBar = filledBar + middleString + emptyBar;

if (style.TimePreSuffixOnTheInside)
{
Expand All @@ -290,6 +289,7 @@ private static string CreateProgressBar(double percentage, MediaSessionInfo medi
}
}

}



Expand Down
9 changes: 5 additions & 4 deletions vrcosc-magicchatbox/Classes/DataAndSecurity/UpdateApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,17 @@ private void CopyContentsFromUnzipPath(DirectoryInfo currentAppDirectory)

private void StartNewApplication()
{
ProcessStartInfo startInfoNoArgs = new ProcessStartInfo
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = Path.Combine(unzipPath, "MagicChatbox.exe"),
FileName = Path.Combine(currentAppPath, "MagicChatbox.exe"),
UseShellExecute = true,
WorkingDirectory = unzipPath
WorkingDirectory = currentAppPath
};
Process.Start(startInfoNoArgs);
Process.Start(startInfo);
Environment.Exit(0);
}


private void ExtractCustomZip(string zipPath)
{
try
Expand Down
24 changes: 5 additions & 19 deletions vrcosc-magicchatbox/Classes/Modules/AfkModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ partial void OnEnableAfkDetectionChanged(bool value)
OnSettingsChanged();
}


partial void OnAfkTimeoutChanged(int value)
{
OnSettingsChanged();
Expand Down Expand Up @@ -134,7 +133,6 @@ private void ViewModel_PropertyChanged(object sender, System.ComponentModel.Prop
}
}


private void Settings_SettingsChanged(object sender, EventArgs e)
{
OnPropertyChanged(nameof(FriendlyTimeoutTime));
Expand All @@ -159,8 +157,6 @@ private void HandleAfkDetectionToggle()
}
}



public string GenerateAFKString()
{
string afkString = "";
Expand All @@ -182,7 +178,6 @@ public string GenerateAFKString()
return afkString;
}


private void InitializeAfkDetection()
{
if (Settings.EnableAfkDetection)
Expand All @@ -200,8 +195,6 @@ public void OnApplicationClosing()

private void AfkTimer_Tick(object sender, EventArgs e)
{


// Update the visibility of the override button
OverrideButtonVisible = Settings.OverrideAfk || !IsAfk;

Expand All @@ -210,7 +203,7 @@ private void AfkTimer_Tick(object sender, EventArgs e)
{
VRModeLabelActive = true; // Indicate VR mode is active, but AFK is not activated in VR

if(!Settings.OverrideAfk)
if (!Settings.OverrideAfk)
{
if (IsAfk) // If AFK mode is currently active, exit it since VR mode doesn't allow it
{
Expand Down Expand Up @@ -250,6 +243,8 @@ private void AfkTimer_Tick(object sender, EventArgs e)

if (idleTime >= Settings.AfkTimeout && !IsAfk)
{
// Update last action time based on idleTime
lastActionTime = DateTime.Now - TimeSpan.FromSeconds(idleTime);
EnterAfkMode(false, false); // Enter AFK due to inactivity, do not reset time
}
else if (idleTime < Settings.AfkTimeout && IsAfk)
Expand All @@ -269,17 +264,10 @@ private void AfkTimer_Tick(object sender, EventArgs e)
}
}








private void EnterAfkMode(bool isOverride, bool resetTime)
{
IsAfk = true;
if (resetTime)
if (resetTime || isOverride)
{
lastActionTime = DateTime.Now;
}
Expand All @@ -288,12 +276,12 @@ private void EnterAfkMode(bool isOverride, bool resetTime)
AfkDetected?.Invoke(this, EventArgs.Empty);
}


private void ExitAfkMode()
{
IsAfk = false;
lastActionTime = DateTime.Now;
TimeCurrentlyAFK = string.Empty;
overrideAfkStarted = false;
RemainingTimeUntilAFK = FormatDuration(TimeSpan.FromSeconds(Settings.AfkTimeout));
OverrideButtonVisible = true;
}
Expand All @@ -312,7 +300,6 @@ private static string FormatDuration(TimeSpan duration)
parts.Add($"{duration.Minutes}m");
}


if (duration.Seconds > 0 || (duration.Hours == 0 && duration.Minutes == 0))
{
parts.Add($"{duration.Seconds}s");
Expand All @@ -321,7 +308,6 @@ private static string FormatDuration(TimeSpan duration)
return string.Join(" ", parts);
}


private static uint GetIdleTime()
{
LASTINPUTINFO lastInputInfo = new LASTINPUTINFO { cbSize = (uint)Marshal.SizeOf(typeof(LASTINPUTINFO)) };
Expand Down

0 comments on commit 2912fd0

Please sign in to comment.