10
10
using CommunityToolkit . Mvvm . Input ;
11
11
using Google . Protobuf ;
12
12
using Microsoft . Extensions . DependencyInjection ;
13
+ using Microsoft . UI ;
13
14
using Microsoft . UI . Dispatching ;
14
15
using Microsoft . UI . Xaml ;
15
16
using Microsoft . UI . Xaml . Controls ;
17
+ using Microsoft . UI . Xaml . Media ;
18
+ using Windows . UI ;
16
19
using Exception = System . Exception ;
17
20
18
21
namespace Coder . Desktop . App . ViewModels ;
@@ -35,6 +38,8 @@ public partial class TrayWindowViewModel : ObservableObject
35
38
[ NotifyPropertyChangedFor ( nameof ( ShowWorkspacesHeader ) ) ]
36
39
[ NotifyPropertyChangedFor ( nameof ( ShowNoAgentsSection ) ) ]
37
40
[ NotifyPropertyChangedFor ( nameof ( ShowAgentsSection ) ) ]
41
+ [ NotifyPropertyChangedFor ( nameof ( SignOutButtonForeground ) ) ]
42
+ [ NotifyPropertyChangedFor ( nameof ( SignOutButtonTooltip ) ) ]
38
43
public partial VpnLifecycle VpnLifecycle { get ; set ; } = VpnLifecycle . Unknown ;
39
44
40
45
// This is a separate property because we need the switch to be 2-way.
@@ -78,12 +83,49 @@ public partial class TrayWindowViewModel : ObservableObject
78
83
79
84
[ ObservableProperty ] public partial string DashboardUrl { get ; set ; } = "https://coder.com" ;
80
85
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
+
81
121
public TrayWindowViewModel ( IServiceProvider services , IRpcController rpcController ,
82
122
ICredentialManager credentialManager )
83
123
{
84
124
_services = services ;
85
125
_rpcController = rpcController ;
86
126
_credentialManager = credentialManager ;
127
+ _disabledForeground = FindBrushByName ( "SystemControlForegroundBaseMediumBrush" ) ;
128
+ _enabledForegroud = FindBrushByName ( "DefaultTextForegroundThemeBrush" ) ;
87
129
}
88
130
89
131
public void Initialize ( DispatcherQueue dispatcherQueue )
0 commit comments