|
| 1 | +using Windows.ApplicationModel.DataTransfer; |
| 2 | +using Windows.UI; |
| 3 | +using CommunityToolkit.Mvvm.ComponentModel; |
| 4 | +using CommunityToolkit.Mvvm.Input; |
| 5 | +using Microsoft.UI.Xaml; |
| 6 | +using Microsoft.UI.Xaml.Controls; |
| 7 | +using Microsoft.UI.Xaml.Controls.Primitives; |
| 8 | +using Microsoft.UI.Xaml.Media; |
| 9 | + |
| 10 | +namespace Coder.Desktop.App.Models; |
| 11 | + |
| 12 | +public enum AgentConnectionStatus |
| 13 | +{ |
| 14 | + Green, |
| 15 | + Red, |
| 16 | + Gray, |
| 17 | +} |
| 18 | + |
| 19 | +public partial class AgentModel : ObservableObject |
| 20 | +{ |
| 21 | + [ObservableProperty] |
| 22 | + [NotifyPropertyChangedFor(nameof(FullHostname))] |
| 23 | + public required partial string Hostname { get; set; } |
| 24 | + |
| 25 | + [ObservableProperty] |
| 26 | + [NotifyPropertyChangedFor(nameof(FullHostname))] |
| 27 | + public required partial string HostnameSuffix { get; set; } // including leading dot |
| 28 | + |
| 29 | + public string FullHostname => Hostname + HostnameSuffix; |
| 30 | + |
| 31 | + [ObservableProperty] |
| 32 | + [NotifyPropertyChangedFor(nameof(ConnectionStatusColor))] |
| 33 | + public required partial AgentConnectionStatus ConnectionStatus { get; set; } |
| 34 | + |
| 35 | + public Brush ConnectionStatusColor => ConnectionStatus switch |
| 36 | + { |
| 37 | + AgentConnectionStatus.Green => new SolidColorBrush(Color.FromArgb(255, 52, 199, 89)), |
| 38 | + AgentConnectionStatus.Red => new SolidColorBrush(Color.FromArgb(255, 255, 59, 48)), |
| 39 | + _ => new SolidColorBrush(Color.FromArgb(255, 142, 142, 147)), |
| 40 | + }; |
| 41 | + |
| 42 | + [ObservableProperty] |
| 43 | + public required partial string DashboardUrl { get; set; } |
| 44 | + |
| 45 | + [RelayCommand] |
| 46 | + private void CopyHostname(object parameter) |
| 47 | + { |
| 48 | + var dataPackage = new DataPackage |
| 49 | + { |
| 50 | + RequestedOperation = DataPackageOperation.Copy, |
| 51 | + }; |
| 52 | + dataPackage.SetText(FullHostname); |
| 53 | + Clipboard.SetContent(dataPackage); |
| 54 | + |
| 55 | + if (parameter is not FrameworkElement frameworkElement) return; |
| 56 | + |
| 57 | + var flyout = new Flyout |
| 58 | + { |
| 59 | + Content = new TextBlock |
| 60 | + { |
| 61 | + Text = "DNS Copied", |
| 62 | + Margin = new Thickness(4), |
| 63 | + }, |
| 64 | + }; |
| 65 | + FlyoutBase.SetAttachedFlyout(frameworkElement, flyout); |
| 66 | + FlyoutBase.ShowAttachedFlyout(frameworkElement); |
| 67 | + } |
| 68 | +} |
0 commit comments