Skip to content

Commit

Permalink
Added greetings with your username!
Browse files Browse the repository at this point in the history
  • Loading branch information
ignYoqzii authored Sep 9, 2024
1 parent cab5998 commit 55eb1d1
Show file tree
Hide file tree
Showing 6 changed files with 453 additions and 360 deletions.
95 changes: 95 additions & 0 deletions StarZ Launcher/StarZLauncher/Classes/Loader.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.DirectoryServices.AccountManagement;
using System.Windows.Media.Animation;
using static StarZLauncher.Classes.MusicPlayer;
using static StarZLauncher.Windows.MainWindow;
using System.Windows.Media;

namespace StarZLauncher.Classes
{
Expand Down Expand Up @@ -86,6 +90,15 @@ public static void Load()
{
LogManager.Log($"Error retrieving local IP address: {ex.Message}", logFileName);
}
try
{
Task.Run(() => LoadUserProfileInfo());
LogManager.Log("Loaded Windows account username.", logFileName);
}
catch (Exception ex)
{
LogManager.Log($"Error retrieving Windows account username: {ex.Message}", logFileName);
}

bool debug = ConfigManager.GetOfflineMode();
if (!debug)
Expand Down Expand Up @@ -149,5 +162,87 @@ private static void CheckForItemsCount()
MusicPlayerInformationTextBlock!.Visibility = Visibility.Collapsed;
}
}

public static async Task LoadUserProfileInfo()
{
// Get the current greeting based on the time of day
string greeting = GetGreetingBasedOnTime();

// Set the initial text to "Greeting" and configure opacity
await Application.Current.Dispatcher.InvokeAsync(() =>
{
WelcomeBack!.Text = greeting;
WelcomeBack.Opacity = 0; // Start with invisible text

// Create a fade-in animation for the initial text
DoubleAnimation fadeInWelcomeAnimation = new()
{
From = 0, // Start from invisible
To = 1, // Fade in to fully visible
Duration = new Duration(TimeSpan.FromSeconds(0.5)) // Half a second fade-in
};

// Apply the animation to the Opacity property
WelcomeBack!.BeginAnimation(UIElement.OpacityProperty, fadeInWelcomeAnimation);
});

// Load the user display name asynchronously
string displayName = Environment.UserName; // Default to Environment.UserName
try
{
UserPrincipal userPrincipal = await Task.Run(() => UserPrincipal.Current);
displayName = userPrincipal.DisplayName;
}
catch
{
throw new Exception("No username found.");
}

// Check if displayName is null or empty
if (string.IsNullOrWhiteSpace(displayName))
{
// Stop execution and do not update the username textblock if displayName is empty or null
return;
}

// Update the text and apply fade-in animation for the complete text
await Application.Current.Dispatcher.InvokeAsync(() =>
{
// Update the text to include the username
WelcomeUsername!.Text = $", {displayName} !";

// Create a fade-in animation for the updated text
DoubleAnimation fadeInUsernameAnimation = new()
{
From = 0, // Start from invisible
To = 1, // Fade in to fully visible
Duration = new Duration(TimeSpan.FromSeconds(0.5)) // Half a second fade-in
};

// Apply the animation to the Opacity property
WelcomeUsername.BeginAnimation(UIElement.OpacityProperty, fadeInUsernameAnimation);
});
}

public static string GetGreetingBasedOnTime()
{
// Get the current hour
int currentHour = DateTime.Now.Hour;

// Determine the greeting based on the time of day
if (currentHour >= 5 && currentHour < 12)
{
return "Good morning";
}
else if (currentHour >= 12 && currentHour < 17)
{
return "Good afternoon";
}
else
{
return "Good evening";
}
}

}
}
Loading

0 comments on commit 55eb1d1

Please sign in to comment.