Introduction of tags

This commit is contained in:
2025-10-10 12:06:35 +08:00
parent f16525e6eb
commit bab6cf7b75
14 changed files with 520 additions and 38 deletions

View File

@@ -1,24 +1,33 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Microsoft.Win32;
using System.IO;
using System.Windows.Threading;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Threading;
using Hardcodet.Wpf.TaskbarNotification;
using LD_SysInfo.Models;
using LD_SysInfo.Services;
using MaterialDesignColors;
using MaterialDesignThemes.Wpf;
using Microsoft.Win32;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Windows.Media.Animation;
using LD_SysInfo.Models;
using MaterialDesignColors;
using MaterialDesignThemes.Wpf;
using System.Windows.Input;
using Application = System.Windows.Application;
using System.Windows.Media;
@@ -34,6 +43,7 @@ namespace LD_SysInfo
private readonly DispatcherTimer messageClearTimer;
private readonly DispatcherTimer postTimer;
private readonly DispatcherTimer keepAliveTimer;
private readonly DispatcherTimer tokenRefreshTimer;
private readonly Uri LightThemeUri = new Uri("pack://application:,,,/Themes/LightTheme.xaml", UriKind.Absolute);
private readonly Uri DarkThemeUri = new Uri("pack://application:,,,/Themes/DarkTheme.xaml", UriKind.Absolute);
private bool isDarkTheme = false;
@@ -47,6 +57,8 @@ namespace LD_SysInfo
System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
InitializeComponent();
var fvi = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
VersionTextBlock.Text = $"v{fvi.ProductVersion}";
LoadConfig();
DisplaySystemInfo();
AutoLogin();
@@ -74,7 +86,12 @@ namespace LD_SysInfo
keepAliveTimer.Tick += KeepAliveTimer_Tick;
keepAliveTimer.Start();
// 🔄 Initialize the Token Refresh timer to refresh token proactively before expiration
// Tokens expire in 60 minutes, so refresh at 50 minutes to be safe
tokenRefreshTimer = new DispatcherTimer();
tokenRefreshTimer.Interval = TimeSpan.FromMinutes(50);
tokenRefreshTimer.Tick += TokenRefreshTimer_Tick;
tokenRefreshTimer.Start();
}
@@ -252,6 +269,41 @@ namespace LD_SysInfo
});
}
var formattedUserApplications = new List<object>();
foreach (var app in sysInfo.UserInstalledApplications)
{
formattedUserApplications.Add(new
{
app_name = app.Name,
app_version = app.Version,
publisher = app.Publisher
});
}
var formattedWindowsUpdates = new List<object>();
foreach (var update in sysInfo.WindowsUpdates)
{
formattedWindowsUpdates.Add(new
{
hotFixID = update.HotFixID,
description = update.Description,
installedOn = update.InstalledOn,
installedBy = update.InstalledBy
});
}
var formattedAppXPackages = new List<object>();
foreach (var pkg in sysInfo.AppXPackages)
{
formattedAppXPackages.Add(new
{
name = pkg.Name,
version = pkg.Version,
publisher = pkg.Publisher,
packageFullName = pkg.PackageFullName
});
}
var payload = new
{
clientIdentifier = _config.ClientIdentifier,
@@ -268,7 +320,10 @@ namespace LD_SysInfo
ipAddresses = sysInfo.IpAddresses,
lastBootTime = sysInfo.LastBootTime,
drives = sysInfo.Drives,
installedApplications = formattedApplications
installedApplications = formattedApplications,
userInstalledApplications = formattedUserApplications,
windowsUpdates = formattedWindowsUpdates,
appXPackages = formattedAppXPackages
};
@@ -519,6 +574,41 @@ namespace LD_SysInfo
});
}
var formattedUserApplications = new List<object>();
foreach (var app in sysInfo.UserInstalledApplications)
{
formattedUserApplications.Add(new
{
app_name = app.Name,
app_version = app.Version,
publisher = app.Publisher
});
}
var formattedWindowsUpdates = new List<object>();
foreach (var update in sysInfo.WindowsUpdates)
{
formattedWindowsUpdates.Add(new
{
hotFixID = update.HotFixID,
description = update.Description,
installedOn = update.InstalledOn,
installedBy = update.InstalledBy
});
}
var formattedAppXPackages = new List<object>();
foreach (var pkg in sysInfo.AppXPackages)
{
formattedAppXPackages.Add(new
{
name = pkg.Name,
version = pkg.Version,
publisher = pkg.Publisher,
packageFullName = pkg.PackageFullName
});
}
var payload = new
{
clientIdentifier = _config.ClientIdentifier,
@@ -535,7 +625,10 @@ namespace LD_SysInfo
ipAddresses = sysInfo.IpAddresses,
lastBootTime = sysInfo.LastBootTime,
drives = sysInfo.Drives,
installedApplications = formattedApplications
installedApplications = formattedApplications,
userInstalledApplications = formattedUserApplications,
windowsUpdates = formattedWindowsUpdates,
appXPackages = formattedAppXPackages
};
@@ -590,6 +683,27 @@ namespace LD_SysInfo
FadeOutStatusMessage(); // Trigger the fade-out effect
}
private async void TokenRefreshTimer_Tick(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(ApiClient.GetJwtToken()))
{
Console.WriteLine("⚠️ No token to refresh - skipping proactive refresh.");
return;
}
var apiClient = new ApiClient(_config);
bool refreshed = await apiClient.RefreshTokenAsync();
if (refreshed)
{
Console.WriteLine("✅ Proactive token refresh successful.");
}
else
{
Console.WriteLine("⚠️ Proactive token refresh failed - will retry on next request.");
}
}
private void TrayIcon_DoubleClick(object sender, RoutedEventArgs e)
{
ShowWindow();