Skip to content

Commit 69bb382

Browse files
committed
feat: added visuals for disabled sign out link
1 parent 9e4ebf2 commit 69bb382

File tree

2 files changed

+63
-19
lines changed

2 files changed

+63
-19
lines changed

App/ViewModels/TrayWindowViewModel.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
using CommunityToolkit.Mvvm.Input;
1111
using Google.Protobuf;
1212
using Microsoft.Extensions.DependencyInjection;
13+
using Microsoft.UI;
1314
using Microsoft.UI.Dispatching;
1415
using Microsoft.UI.Xaml;
1516
using Microsoft.UI.Xaml.Controls;
17+
using Microsoft.UI.Xaml.Media;
18+
using Windows.UI;
1619
using Exception = System.Exception;
1720

1821
namespace Coder.Desktop.App.ViewModels;
@@ -35,6 +38,8 @@ public partial class TrayWindowViewModel : ObservableObject
3538
[NotifyPropertyChangedFor(nameof(ShowWorkspacesHeader))]
3639
[NotifyPropertyChangedFor(nameof(ShowNoAgentsSection))]
3740
[NotifyPropertyChangedFor(nameof(ShowAgentsSection))]
41+
[NotifyPropertyChangedFor(nameof(SignOutButtonForeground))]
42+
[NotifyPropertyChangedFor(nameof(SignOutButtonTooltip))]
3843
public partial VpnLifecycle VpnLifecycle { get; set; } = VpnLifecycle.Unknown;
3944

4045
// This is a separate property because we need the switch to be 2-way.
@@ -78,12 +83,49 @@ public partial class TrayWindowViewModel : ObservableObject
7883

7984
[ObservableProperty] public partial string DashboardUrl { get; set; } = "https://coder.com";
8085

86+
public string SignOutButtonTooltip
87+
{
88+
get
89+
{
90+
return VpnLifecycle switch
91+
{
92+
VpnLifecycle.Stopped or VpnLifecycle.Unknown => "Sign out",
93+
_ => "Sign out (VPN must be stopped first)",
94+
};
95+
}
96+
}
97+
98+
private Brush? _enabledForegroud;
99+
private Brush? _disabledForeground;
100+
101+
public Brush SignOutButtonForeground
102+
{
103+
get {
104+
return VpnLifecycle switch
105+
{
106+
VpnLifecycle.Stopped or VpnLifecycle.Unknown => _enabledForegroud ?? new SolidColorBrush(Colors.White),
107+
_ => _disabledForeground ?? new SolidColorBrush(Color.FromArgb(153, 255, 255, 255)),
108+
};
109+
}
110+
}
111+
public static Brush? FindBrushByName(string brushName)
112+
{
113+
if (Application.Current.Resources.TryGetValue(brushName, out var resource) && resource is Brush brush)
114+
{
115+
return brush;
116+
}
117+
118+
return null; // Return null if the brush is not found
119+
}
120+
81121
public TrayWindowViewModel(IServiceProvider services, IRpcController rpcController,
82122
ICredentialManager credentialManager)
83123
{
84124
_services = services;
85125
_rpcController = rpcController;
86126
_credentialManager = credentialManager;
127+
_disabledForeground = FindBrushByName("SystemControlForegroundBaseMediumBrush");
128+
_enabledForegroud = FindBrushByName("DefaultTextForegroundThemeBrush");
87129
}
88130

89131
public void Initialize(DispatcherQueue dispatcherQueue)

App/Views/Pages/TrayWindowMainPage.xaml

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -239,24 +239,26 @@
239239
</HyperlinkButton>
240240

241241
<controls:HorizontalRule />
242-
243-
<HyperlinkButton
244-
Command="{x:Bind ViewModel.SignOutCommand, Mode=OneWay}"
245-
IsEnabled="{x:Bind ViewModel.VpnLifecycle, Converter={StaticResource StoppedBoolConverter}, Mode=OneWay}"
246-
Margin="-12,0"
247-
HorizontalAlignment="Stretch"
248-
HorizontalContentAlignment="Left">
249-
250-
<TextBlock Text="Sign out" Foreground="{ThemeResource DefaultTextForegroundThemeBrush}" />
251-
</HyperlinkButton>
252-
253-
<HyperlinkButton
254-
Command="{x:Bind ViewModel.ExitCommand, Mode=OneWay}"
255-
Margin="-12,-8,-12,-5"
256-
HorizontalAlignment="Stretch"
257-
HorizontalContentAlignment="Left">
258-
259-
<TextBlock Text="Exit" Foreground="{ThemeResource DefaultTextForegroundThemeBrush}" />
260-
</HyperlinkButton>
242+
243+
<Grid ToolTipService.ToolTip="{x:Bind ViewModel.SignOutButtonTooltip, Mode=OneWay}">
244+
<HyperlinkButton
245+
Command="{x:Bind ViewModel.SignOutCommand, Mode=OneWay}"
246+
IsEnabled="{x:Bind ViewModel.VpnLifecycle, Converter={StaticResource StoppedBoolConverter}, Mode=OneWay}"
247+
Margin="-12,0"
248+
HorizontalAlignment="Stretch"
249+
HorizontalContentAlignment="Left">
250+
251+
<TextBlock Text="Sign out" Foreground="{ThemeResource DefaultTextForegroundThemeBrush}" />
252+
</HyperlinkButton>
253+
254+
<HyperlinkButton
255+
Command="{x:Bind ViewModel.ExitCommand, Mode=OneWay}"
256+
Margin="-12,-8,-12,-5"
257+
HorizontalAlignment="Stretch"
258+
HorizontalContentAlignment="Left">
259+
260+
<TextBlock Text="Exit" Foreground="{ThemeResource DefaultTextForegroundThemeBrush}" />
261+
</HyperlinkButton>
262+
</Grid>
261263
</StackPanel>
262264
</Page>

0 commit comments

Comments
 (0)