diff --git a/LanMountainDesktop/Assets/mining_qrcode.png b/LanMountainDesktop/Assets/mining_qrcode.png new file mode 100644 index 0000000..215ab19 Binary files /dev/null and b/LanMountainDesktop/Assets/mining_qrcode.png differ diff --git a/LanMountainDesktop/ViewModels/SuperMiningSettingsPageViewModel.cs b/LanMountainDesktop/ViewModels/SuperMiningSettingsPageViewModel.cs new file mode 100644 index 0000000..12cd798 --- /dev/null +++ b/LanMountainDesktop/ViewModels/SuperMiningSettingsPageViewModel.cs @@ -0,0 +1,130 @@ +using System.ComponentModel; +using System.Runtime.CompilerServices; +using Avalonia.Media.Imaging; +using Avalonia.Platform; +using FluentIcons.Common; + +namespace LanMountainDesktop.ViewModels; + +public sealed class SuperMiningSettingsPageViewModel : INotifyPropertyChanged +{ + private double _hashRate = 125.6; + private string _coinsMined = "0.08923"; + private int _poolConnections = 98; + private double _miningProgress; + private string _miningStatus = "正在挖矿中..."; + private bool _showAprilFoolsHint; + private Bitmap? _qrCodeImage; + + public event PropertyChangedEventHandler? PropertyChanged; + + public Symbol ActionSymbol => Symbol.ArrowDownload; + + public double HashRate + { + get => _hashRate; + set + { + if (Math.Abs(_hashRate - value) > 0.01) + { + _hashRate = value; + OnPropertyChanged(); + } + } + } + + public string CoinsMined + { + get => _coinsMined; + set + { + if (_coinsMined != value) + { + _coinsMined = value; + OnPropertyChanged(); + } + } + } + + public int PoolConnections + { + get => _poolConnections; + set + { + if (_poolConnections != value) + { + _poolConnections = value; + OnPropertyChanged(); + } + } + } + + public double MiningProgress + { + get => _miningProgress; + set + { + if (Math.Abs(_miningProgress - value) > 0.1) + { + _miningProgress = value; + OnPropertyChanged(); + } + } + } + + public string MiningStatus + { + get => _miningStatus; + set + { + if (_miningStatus != value) + { + _miningStatus = value; + OnPropertyChanged(); + } + } + } + + public bool ShowAprilFoolsHint + { + get => _showAprilFoolsHint; + set + { + if (_showAprilFoolsHint != value) + { + _showAprilFoolsHint = value; + OnPropertyChanged(); + } + } + } + + public Bitmap? QrCodeImage + { + get => _qrCodeImage; + set + { + if (_qrCodeImage != value) + { + _qrCodeImage = value; + OnPropertyChanged(); + } + } + } + + public void LoadQrCodeImage() + { + try + { + var assets = AssetLoader.Open(new System.Uri("avares://LanMountainDesktop/Assets/mining_qrcode.png")); + QrCodeImage = new Bitmap(assets); + } + catch + { + } + } + + private void OnPropertyChanged([CallerMemberName] string? propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } +} diff --git a/LanMountainDesktop/Views/SettingsPages/SuperMiningSettingsPage.axaml b/LanMountainDesktop/Views/SettingsPages/SuperMiningSettingsPage.axaml new file mode 100644 index 0000000..0aed869 --- /dev/null +++ b/LanMountainDesktop/Views/SettingsPages/SuperMiningSettingsPage.axaml @@ -0,0 +1,271 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LanMountainDesktop/Views/SettingsPages/SuperMiningSettingsPage.axaml.cs b/LanMountainDesktop/Views/SettingsPages/SuperMiningSettingsPage.axaml.cs new file mode 100644 index 0000000..422c772 --- /dev/null +++ b/LanMountainDesktop/Views/SettingsPages/SuperMiningSettingsPage.axaml.cs @@ -0,0 +1,89 @@ +using System; +using Avalonia.Threading; +using LanMountainDesktop.PluginSdk; +using LanMountainDesktop.ViewModels; + +namespace LanMountainDesktop.Views.SettingsPages; + +[SettingsPageInfo( + "super-mining", + "超级挖矿", + SettingsPageCategory.About, + IconKey = "Savings", + SortOrder = 35, + TitleLocalizationKey = "settings.supermining.title", + DescriptionLocalizationKey = "settings.supermining.description", + HidePageTitle = true)] +public partial class SuperMiningSettingsPage : SettingsPageBase +{ + private readonly DispatcherTimer _updateTimer; + private readonly Random _random = new(); + private int _tickCount; + + public SuperMiningSettingsPage() + : this(new SuperMiningSettingsPageViewModel()) + { + } + + public SuperMiningSettingsPage(SuperMiningSettingsPageViewModel viewModel) + { + ViewModel = viewModel; + DataContext = ViewModel; + InitializeComponent(); + + ViewModel.LoadQrCodeImage(); + + _updateTimer = new DispatcherTimer + { + Interval = TimeSpan.FromSeconds(1) + }; + _updateTimer.Tick += OnUpdateTimerTick; + + Unloaded += OnUnloaded; + } + + public SuperMiningSettingsPageViewModel ViewModel { get; } + + public override void OnNavigatedTo(object? parameter) + { + base.OnNavigatedTo(parameter); + _updateTimer.Start(); + } + + private void OnUnloaded(object? sender, Avalonia.Interactivity.RoutedEventArgs e) + { + _updateTimer.Stop(); + } + + private void OnUpdateTimerTick(object? sender, EventArgs e) + { + _tickCount++; + + ViewModel.HashRate = 125.6 + _random.NextDouble() * 10 - 5; + ViewModel.MiningProgress = (ViewModel.MiningProgress + 1) % 100; + + if (_tickCount % 5 == 0) + { + var baseCoins = 0.08923; + var increment = _random.NextDouble() * 0.00001; + ViewModel.CoinsMined = (baseCoins + increment).ToString("F5"); + } + + ViewModel.PoolConnections = _random.Next(95, 100); + + var statuses = new[] + { + "正在挖矿中...", + "矿池连接稳定", + "正在提交份额...", + "算力优化中...", + "收益计算中..." + }; + ViewModel.MiningStatus = statuses[_tickCount % statuses.Length]; + + if (DateTime.Now.Month == 4 && DateTime.Now.Day == 1) + { + ViewModel.ShowAprilFoolsHint = true; + } + } +} diff --git a/LanMountainDesktop/Views/SettingsWindow.axaml.cs b/LanMountainDesktop/Views/SettingsWindow.axaml.cs index 8f35357..6f6439b 100644 --- a/LanMountainDesktop/Views/SettingsWindow.axaml.cs +++ b/LanMountainDesktop/Views/SettingsWindow.axaml.cs @@ -734,6 +734,7 @@ public partial class SettingsWindow : Window, ISettingsPageHostContext "Info" => Symbol.Info, "ArrowSync" => Symbol.ArrowSync, "Hourglass" => Symbol.Hourglass, + "Savings" => Symbol.Savings, _ => Symbol.Settings }; }