Skip to content

Commit f0a17ea

Browse files
committed
feat: added visuals for disabled sign out link
1 parent be72f80 commit f0a17ea

File tree

2 files changed

+66
-19
lines changed

2 files changed

+66
-19
lines changed

App/ViewModels/TrayWindowViewModel.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
using CommunityToolkit.Mvvm.Input;
1515
using Google.Protobuf;
1616
using Microsoft.Extensions.DependencyInjection;
17+
using Microsoft.UI;
1718
using Microsoft.UI.Dispatching;
1819
using Microsoft.UI.Xaml;
1920
using Microsoft.UI.Xaml.Controls;
21+
using Microsoft.UI.Xaml.Media;
22+
using Windows.UI;
23+
using Exception = System.Exception;
2024

2125
namespace Coder.Desktop.App.ViewModels;
2226

@@ -56,6 +60,8 @@ public partial class TrayWindowViewModel : ObservableObject, IAgentExpanderHost
5660
[NotifyPropertyChangedFor(nameof(ShowWorkspacesHeader))]
5761
[NotifyPropertyChangedFor(nameof(ShowNoAgentsSection))]
5862
[NotifyPropertyChangedFor(nameof(ShowAgentsSection))]
63+
[NotifyPropertyChangedFor(nameof(SignOutButtonForeground))]
64+
[NotifyPropertyChangedFor(nameof(SignOutButtonTooltip))]
5965
public partial VpnLifecycle VpnLifecycle { get; set; } = VpnLifecycle.Unknown;
6066

6167
// This is a separate property because we need the switch to be 2-way.
@@ -92,6 +98,41 @@ public partial class TrayWindowViewModel : ObservableObject, IAgentExpanderHost
9298

9399
[ObservableProperty] public partial string DashboardUrl { get; set; } = DefaultDashboardUrl;
94100

101+
public string SignOutButtonTooltip
102+
{
103+
get
104+
{
105+
return VpnLifecycle switch
106+
{
107+
VpnLifecycle.Stopped or VpnLifecycle.Unknown => "Sign out",
108+
_ => "Sign out (VPN must be stopped first)",
109+
};
110+
}
111+
}
112+
113+
private Brush? _enabledForegroud;
114+
private Brush? _disabledForeground;
115+
116+
public Brush SignOutButtonForeground
117+
{
118+
get {
119+
return VpnLifecycle switch
120+
{
121+
VpnLifecycle.Stopped or VpnLifecycle.Unknown => _enabledForegroud ?? new SolidColorBrush(Colors.White),
122+
_ => _disabledForeground ?? new SolidColorBrush(Color.FromArgb(153, 255, 255, 255)),
123+
};
124+
}
125+
}
126+
public static Brush? FindBrushByName(string brushName)
127+
{
128+
if (Application.Current.Resources.TryGetValue(brushName, out var resource) && resource is Brush brush)
129+
{
130+
return brush;
131+
}
132+
133+
return null; // Return null if the brush is not found
134+
}
135+
95136
public TrayWindowViewModel(IServiceProvider services, IRpcController rpcController,
96137
ICredentialManager credentialManager, IAgentViewModelFactory agentViewModelFactory, IHostnameSuffixGetter hostnameSuffixGetter)
97138
{
@@ -100,6 +141,10 @@ public TrayWindowViewModel(IServiceProvider services, IRpcController rpcControll
100141
_credentialManager = credentialManager;
101142
_agentViewModelFactory = agentViewModelFactory;
102143
_hostnameSuffixGetter = hostnameSuffixGetter;
144+
_disabledForeground = FindBrushByName("SystemControlForegroundBaseMediumBrush");
145+
_enabledForegroud = FindBrushByName("DefaultTextForegroundThemeBrush");
146+
147+
103148

104149
// Since the property value itself never changes, we add event
105150
// listeners for the underlying collection changing instead.

App/Views/Pages/TrayWindowMainPage.xaml

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -330,24 +330,26 @@
330330
</HyperlinkButton>
331331

332332
<controls:HorizontalRule />
333-
334-
<HyperlinkButton
335-
Command="{x:Bind ViewModel.SignOutCommand, Mode=OneWay}"
336-
IsEnabled="{x:Bind ViewModel.VpnLifecycle, Converter={StaticResource StoppedBoolConverter}, Mode=OneWay}"
337-
Margin="-12,0"
338-
HorizontalAlignment="Stretch"
339-
HorizontalContentAlignment="Left">
340-
341-
<TextBlock Text="Sign out" Foreground="{ThemeResource DefaultTextForegroundThemeBrush}" />
342-
</HyperlinkButton>
343-
344-
<HyperlinkButton
345-
Command="{x:Bind ViewModel.ExitCommand, Mode=OneWay}"
346-
Margin="-12,-8,-12,-5"
347-
HorizontalAlignment="Stretch"
348-
HorizontalContentAlignment="Left">
349-
350-
<TextBlock Text="Exit" Foreground="{ThemeResource DefaultTextForegroundThemeBrush}" />
351-
</HyperlinkButton>
333+
334+
<Grid ToolTipService.ToolTip="{x:Bind ViewModel.SignOutButtonTooltip, Mode=OneWay}">
335+
<HyperlinkButton
336+
Command="{x:Bind ViewModel.SignOutCommand, Mode=OneWay}"
337+
IsEnabled="{x:Bind ViewModel.VpnLifecycle, Converter={StaticResource StoppedBoolConverter}, Mode=OneWay}"
338+
Margin="-12,0"
339+
HorizontalAlignment="Stretch"
340+
HorizontalContentAlignment="Left">
341+
342+
<TextBlock Text="Sign out" Foreground="{ThemeResource DefaultTextForegroundThemeBrush}" />
343+
</HyperlinkButton>
344+
345+
<HyperlinkButton
346+
Command="{x:Bind ViewModel.ExitCommand, Mode=OneWay}"
347+
Margin="-12,-8,-12,-5"
348+
HorizontalAlignment="Stretch"
349+
HorizontalContentAlignment="Left">
350+
351+
<TextBlock Text="Exit" Foreground="{ThemeResource DefaultTextForegroundThemeBrush}" />
352+
</HyperlinkButton>
353+
</Grid>
352354
</StackPanel>
353355
</Page>

0 commit comments

Comments
 (0)