using System; using System.Windows; using System.Windows.Threading; using ClassNotify.Shared.Models; namespace ClassNotify.Client { public partial class LicenseReminderWindow : Window { private readonly DispatcherTimer _autoCloseTimer; private readonly Action _onOpenRenew; public LicenseReminderWindow(DeviceLicenseStatusDto status, Action onOpenRenew) { InitializeComponent(); _onOpenRenew = onOpenRenew; if (status.Status == "Expired") { IconText.Text = "⚠️"; TitleText.Text = "ClassNotify 授权已到期"; TitleText.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(220, 38, 38)); MessageText.Text = status.Message ?? "当前班级试用已结束,普通通知已暂停接收。如需继续使用请续期。"; RenewButton.Content = "输入续费码"; } else if (status.Status == "OfflineRestricted") { IconText.Text = "⚠️"; TitleText.Text = "ClassNotify 离线宽限已结束"; TitleText.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(220, 38, 38)); MessageText.Text = "设备离线容灾宽限已超时,普通通知已暂停接收,请接入校园网刷新授权。"; RenewButton.Content = "连接刷新"; } else if (status.Status == "TimeUntrusted") { IconText.Text = "🕒"; TitleText.Text = "ClassNotify 系统时间异常"; TitleText.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(220, 38, 38)); MessageText.Text = "系统时间异常,授权状态暂时无法可信验证。请开启 Windows「自动设置时间」并完成联网校时。"; RenewButton.Content = "联网校时"; } else { IconText.Text = "🔔"; TitleText.Text = "ClassNotify 授权即将到期"; TitleText.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(217, 119, 6)); MessageText.Text = status.Message ?? $"当前班级授权还剩 {status.RemainingDays ?? 1} 天,请联系学校电教管理员续期。"; RenewButton.Content = "立即续期"; } // Position at bottom-right corner of primary screen WorkArea this.Loaded += (s, e) => { var workArea = SystemParameters.WorkArea; this.Left = workArea.Right - this.ActualWidth - 20; this.Top = workArea.Bottom - this.ActualHeight - 20; }; // Auto dismiss after 8 seconds _autoCloseTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(8) }; _autoCloseTimer.Tick += (s, e) => { _autoCloseTimer.Stop(); this.Close(); }; _autoCloseTimer.Start(); } private void OnDismissClick(object sender, RoutedEventArgs e) { _autoCloseTimer.Stop(); this.Close(); } private void OnRenewClick(object sender, RoutedEventArgs e) { _autoCloseTimer.Stop(); this.Close(); _onOpenRenew?.Invoke(); } } }