diff --git a/App/ViewModels/TrayWindowViewModel.cs b/App/ViewModels/TrayWindowViewModel.cs index cfa5163..97a792e 100644 --- a/App/ViewModels/TrayWindowViewModel.cs +++ b/App/ViewModels/TrayWindowViewModel.cs @@ -14,9 +14,13 @@ using CommunityToolkit.Mvvm.Input; using Google.Protobuf; using Microsoft.Extensions.DependencyInjection; +using Microsoft.UI; using Microsoft.UI.Dispatching; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media; +using Windows.UI; +using Exception = System.Exception; namespace Coder.Desktop.App.ViewModels; @@ -56,6 +60,8 @@ public partial class TrayWindowViewModel : ObservableObject, IAgentExpanderHost [NotifyPropertyChangedFor(nameof(ShowWorkspacesHeader))] [NotifyPropertyChangedFor(nameof(ShowNoAgentsSection))] [NotifyPropertyChangedFor(nameof(ShowAgentsSection))] + [NotifyPropertyChangedFor(nameof(SignOutButtonForeground))] + [NotifyPropertyChangedFor(nameof(SignOutButtonTooltip))] public partial VpnLifecycle VpnLifecycle { get; set; } = VpnLifecycle.Unknown; // This is a separate property because we need the switch to be 2-way. @@ -92,6 +98,42 @@ public partial class TrayWindowViewModel : ObservableObject, IAgentExpanderHost [ObservableProperty] public partial string DashboardUrl { get; set; } = DefaultDashboardUrl; + public string SignOutButtonTooltip + { + get + { + return VpnLifecycle switch + { + VpnLifecycle.Stopped or VpnLifecycle.Unknown => "Sign out", + _ => "Sign out (VPN must be stopped first)", + }; + } + } + + private Brush? _enabledForegroud; + private Brush? _disabledForeground; + + public Brush SignOutButtonForeground + { + get + { + return VpnLifecycle switch + { + VpnLifecycle.Stopped or VpnLifecycle.Unknown => _enabledForegroud ?? new SolidColorBrush(Colors.White), + _ => _disabledForeground ?? new SolidColorBrush(Color.FromArgb(153, 255, 255, 255)), + }; + } + } + public static Brush? FindBrushByName(string brushName) + { + if (Application.Current.Resources.TryGetValue(brushName, out var resource) && resource is Brush brush) + { + return brush; + } + + return null; + } + public TrayWindowViewModel(IServiceProvider services, IRpcController rpcController, ICredentialManager credentialManager, IAgentViewModelFactory agentViewModelFactory, IHostnameSuffixGetter hostnameSuffixGetter) { @@ -100,6 +142,10 @@ public TrayWindowViewModel(IServiceProvider services, IRpcController rpcControll _credentialManager = credentialManager; _agentViewModelFactory = agentViewModelFactory; _hostnameSuffixGetter = hostnameSuffixGetter; + _disabledForeground = FindBrushByName("SystemControlForegroundBaseMediumBrush"); + _enabledForegroud = FindBrushByName("DefaultTextForegroundThemeBrush"); + + // Since the property value itself never changes, we add event // listeners for the underlying collection changing instead. diff --git a/App/Views/Pages/TrayWindowMainPage.xaml b/App/Views/Pages/TrayWindowMainPage.xaml index f3549c2..0db062a 100644 --- a/App/Views/Pages/TrayWindowMainPage.xaml +++ b/App/Views/Pages/TrayWindowMainPage.xaml @@ -330,22 +330,25 @@ - - - - - - + + + + + + + + + HorizontalContentAlignment="Left">