Skip to content

Commit 4ff58ab

Browse files
Add Refresh buttons, fix missing auth consent, remove custom title bar causing TitleBar crash on wasdk1.7, and fix MSAL Auth exception (#157)
* Add refresh button and deterministic sort * Add AuthService consent to avoid admins from manually adding permissions * fix copilot warnings * add try catch for error messages regarding auth * this removes the custom override title bar as it is causing the app to crash when dragged. * add more error catching
1 parent c32b648 commit 4ff58ab

22 files changed

Lines changed: 258 additions & 111 deletions

src/uno/AzureKeyVaultStudio.slnx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@
66
<File Path="Directory.Packages.props" />
77
<File Path="global.json" />
88
</Folder>
9-
<Project Path="../../../AzureKeyVaultStudio/AzureKeyVaultStudio/AzureKeyVaultStudio.csproj">
10-
<Deploy />
11-
</Project>
9+
<Project Path="AzureKeyVaultStudio/AzureKeyVaultStudio/AzureKeyVaultStudio.csproj" />
1210
</Solution>

src/uno/AzureKeyVaultStudio/AzureKeyVaultStudio/App.xaml.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public App()
3838

3939
public Window? MainWindow { get; private set; }
4040
public IHost? Host { get; private set; }
41+
public string AppTitle { get; init; } = "Key Vault Explorer";
4142

4243
protected override async void OnLaunched(LaunchActivatedEventArgs args)
4344
{
@@ -154,10 +155,10 @@ protected override async void OnLaunched(LaunchActivatedEventArgs args)
154155
services.AddSingleton<AzureSearchService>();
155156
services.AddSingleton<KeyVaultTreeViewModel>();
156157
services.AddTransient<ItemPropertiesViewModel>();
157-
})
158-
.UseNavigation(RegisterRoutes)
159-
);
158+
}).UseNavigation(RegisterRoutes));
159+
160160
MainWindow = builder.Window;
161+
MainWindow.Title = AppTitle;
161162
EnsureEarlyWindow(MainWindow);
162163
//builder.Build();
163164
#if DEBUG
@@ -200,7 +201,6 @@ private static void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
200201
new ("Main", View: views.FindByViewModel<MainViewModel>(), IsDefault:true),
201202
new ("SettingsPage", View: views.FindByViewModel<SettingsViewModel>()),
202203
new ("SubscriptionsPage", View: views.FindByViewModel<SubscriptionViewModel>()),
203-
//new ("Second", View: views.FindByViewModel<SecondViewModel>()),
204204
]
205205
)
206206
);
@@ -209,18 +209,22 @@ private static void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
209209
private static void EnsureEarlyWindow(Window window)
210210
{
211211
#if WINDOWS && !HAS_UNO
212-
window.AppWindow.Resize(new SizeInt32 { Width = 1000, Height = 600 });
213-
window.AppWindow.Move(new PointInt32 { X = 150, Y = 150 });
214-
215-
window.ExtendsContentIntoTitleBar = true;
216-
var theme = window.GetThemeService();
212+
window.AppWindow.Resize(new SizeInt32 { Width = 1100, Height = 640 });
213+
window.AppWindow.Move(new PointInt32 { X = 250, Y = 250 });
214+
window.AppWindow.TitleBar.PreferredTheme = TitleBarTheme.UseDefaultAppMode;
215+
//if (Microsoft.UI.Windowing.AppWindowTitleBar.IsCustomizationSupported())
216+
//{
217+
//}
218+
//window.ExtendsContentIntoTitleBar = true;
219+
//var theme = window.GetThemeService();
220+
//window.AppWindow.TitleBar.PreferredTheme = TitleBarTheme.UseDefaultAppMode;
221+
//window.AppWindow.TitleBar.PreferredTheme = theme.Theme switch
222+
//{
223+
// AppTheme.Light => TitleBarTheme.Light,
224+
// AppTheme.Dark => TitleBarTheme.Dark,
225+
// _ => TitleBarTheme.UseDefaultAppMode,
226+
//};
217227

218-
window.AppWindow.TitleBar.PreferredTheme = theme.Theme switch
219-
{
220-
AppTheme.Light => TitleBarTheme.Light,
221-
AppTheme.Dark => TitleBarTheme.Light,
222-
_ => TitleBarTheme.UseDefaultAppMode,
223-
};
224228

225229
//window.AppWindow.TitleBar.ButtonBackgroundColor = Microsoft.UI.Colors.Transparent;
226230

src/uno/AzureKeyVaultStudio/AzureKeyVaultStudio/Models/KeyVaultValuesAmalgamation.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ public static KeyVaultItemProperties FromSecretProperties(SecretProperties prope
5353
properties.Enabled,
5454
properties.RecoverableDays,
5555
properties.RecoveryLevel,
56-
properties.Managed);
56+
KeyVaultItemType.Secret,
57+
properties.Managed
58+
);
5759

5860
public static IReadOnlyList<KeyVaultItemProperties> FromSecretProperties(IEnumerable<SecretProperties>? properties)
59-
=> properties is null ? Array.Empty<KeyVaultItemProperties>() : [.. properties.Select(FromSecretProperties)];
61+
=> properties is null ? [] : [.. properties.Select(FromSecretProperties)];
6062

6163
public static KeyVaultItemProperties FromKeyProperties(KeyProperties properties)
6264
=> Create(
@@ -73,10 +75,11 @@ public static KeyVaultItemProperties FromKeyProperties(KeyProperties properties)
7375
properties.Enabled,
7476
properties.RecoverableDays,
7577
properties.RecoveryLevel,
78+
KeyVaultItemType.Key,
7679
properties.Managed);
7780

7881
public static IReadOnlyList<KeyVaultItemProperties> FromKeyProperties(IEnumerable<KeyProperties>? properties)
79-
=> properties is null ? Array.Empty<KeyVaultItemProperties>() : [.. properties.Select(FromKeyProperties)];
82+
=> properties is null ? [] : [.. properties.Select(FromKeyProperties)];
8083

8184
public static KeyVaultItemProperties FromCertificateProperties(CertificateProperties properties)
8285
=> Create(
@@ -92,10 +95,11 @@ public static KeyVaultItemProperties FromCertificateProperties(CertificateProper
9295
properties.NotBefore,
9396
properties.Enabled,
9497
properties.RecoverableDays,
95-
properties.RecoveryLevel);
98+
properties.RecoveryLevel,
99+
KeyVaultItemType.Certificate);
96100

97101
public static IReadOnlyList<KeyVaultItemProperties> FromCertificateProperties(IEnumerable<CertificateProperties>? properties)
98-
=> properties is null ? Array.Empty<KeyVaultItemProperties>() : [.. properties.Select(FromCertificateProperties)];
102+
=> properties is null ? [] : [.. properties.Select(FromCertificateProperties)];
99103

100104
public SecretProperties ToSecretProperties()
101105
{
@@ -134,12 +138,10 @@ public KeyProperties ToKeyProperties()
134138
return properties;
135139
}
136140

137-
138141
public CertificateProperties ToCertificateProperties()
139142
{
140143
var properties = new CertificateProperties(Id);
141144
properties.Enabled = Enabled;
142-
143145
if (Tags != null && Tags.Count > 0)
144146
{
145147
foreach (var tag in Tags)
@@ -165,7 +167,9 @@ private static KeyVaultItemProperties Create(
165167
bool? enabled,
166168
int? recoverableDays,
167169
string? recoveryLevel,
168-
bool? managed = null)
170+
KeyVaultItemType type,
171+
bool? managed = null
172+
)
169173
{
170174
return new KeyVaultItemProperties
171175
{
@@ -183,7 +187,8 @@ private static KeyVaultItemProperties Create(
183187
RecoverableDays = recoverableDays,
184188
RecoveryLevel = recoveryLevel,
185189
Managed = managed,
186-
Tags = tags is null ? new Dictionary<string, string>() : new Dictionary<string, string>(tags)
190+
Tags = tags is null ? new Dictionary<string, string>() : new Dictionary<string, string>(tags),
191+
Type = type
187192
};
188193
}
189194

src/uno/AzureKeyVaultStudio/AzureKeyVaultStudio/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
xmlns:uap18="http://schemas.microsoft.com/appx/manifest/uap/windows10/18"
77
IgnorableNamespaces="uap rescap uap18">
88

9-
<Identity Version="2.0.0.0" Publisher="CN=FE9032D7-9FA7-4DED-9087-469BC45B4D99" Name="ArthurThomasIV.AzureKeyVaultExplorer-forAzure"/>
9+
<Identity Version="2.0.1.0" Publisher="CN=FE9032D7-9FA7-4DED-9087-469BC45B4D99" Name="ArthurThomasIV.AzureKeyVaultExplorer-forAzure"/>
1010
<Properties>
1111
<DisplayName>Key Vault Explorer</DisplayName>
1212
<PublisherDisplayName>Arthur Thomas IV</PublisherDisplayName>

src/uno/AzureKeyVaultStudio/AzureKeyVaultStudio/Presentation/LoginPage.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515

1616
<Grid>
1717
<Grid.RowDefinitions>
18-
<RowDefinition Height="Auto" />
18+
<!--<RowDefinition Height="Auto" />-->
1919
<RowDefinition />
2020
</Grid.RowDefinitions>
21-
<uc:OverrideTitlebar Grid.Row="0" />
21+
<!--<uc:OverrideTitlebar Grid.Row="0" />-->
2222

23-
<ScrollViewer Grid.Row="1">
23+
<ScrollViewer Grid.Row="0">
2424
<StackPanel
2525
Margin="50"
2626
HorizontalAlignment="Left"

src/uno/AzureKeyVaultStudio/AzureKeyVaultStudio/Presentation/MainPage.xaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@
1717
<!-- Background="" -->
1818
<Grid>
1919
<Grid.RowDefinitions>
20-
<win:RowDefinition Height="32" />
21-
<skia:RowDefinition Height="0" />
20+
<!--<win:RowDefinition Height="32" />
21+
<skia:RowDefinition Height="0" />-->
2222
<RowDefinition Height="*" />
2323
<RowDefinition Height="Auto" />
2424
</Grid.RowDefinitions>
2525

26-
<uc:OverrideTitlebar
26+
<!--<uc:OverrideTitlebar
2727
x:Name="DefaultOverrideTitleBar"
2828
Grid.Row="0"
29-
skia:Visibility="Collapsed" />
29+
skia:Visibility="Collapsed" />-->
3030

3131
<SplitView
3232
x:Name="MainSplitView"
33-
Grid.Row="1"
33+
Grid.Row="0"
3434
DisplayMode="{x:Bind ViewModel.SplitViewDisplay, Mode=TwoWay}"
3535
IsPaneOpen="{x:Bind ViewModel.IsPaneOpen, Mode=TwoWay}"
3636
OpenPaneLength="{x:Bind ViewModel.SplitViewWidth, Mode=TwoWay}"
@@ -132,7 +132,7 @@
132132

133133
</SplitView>
134134

135-
<uc:StatusBarControl Grid.Row="2" />
135+
<uc:StatusBarControl Grid.Row="1" />
136136
</Grid>
137137

138138
</Page>

src/uno/AzureKeyVaultStudio/AzureKeyVaultStudio/Presentation/MainPage.xaml.cs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public sealed partial class MainPage : Page
1414
public MainPage()
1515
{
1616
this.InitializeComponent();
17-
Loaded += MainPage_Loaded;
17+
//Loaded += MainPage_Loaded;
1818
_appWindow = (Application.Current as App)?.MainWindow?.AppWindow;
1919
if (_appWindow is not null)
2020
_appWindow.Closing += _appWindow_Closing;
@@ -28,24 +28,26 @@ private void _appWindow_Closing(AppWindow sender, AppWindowClosingEventArgs args
2828
}
2929
}
3030

31-
private void MainPage_Loaded(object sender, RoutedEventArgs e)
32-
{
33-
#if !MACCATALYST && !HAS_UNO
34-
var currentWindow = (Application.Current as App)?.MainWindow;
35-
if (currentWindow is null)
36-
return;
37-
38-
try
39-
{
40-
currentWindow.SetTitleBar(DefaultOverrideTitleBar);
41-
}
42-
catch (Exception ex)
43-
{
44-
Debug.WriteLine($"Failed to set title bar: {ex.Message}");
45-
}
46-
47-
#endif
48-
}
31+
// private void MainPage_Loaded(object sender, RoutedEventArgs e)
32+
// {
33+
//#if !MACCATALYST && !HAS_UNO
34+
// var currentWindow = (Application.Current as App)?.MainWindow;
35+
// if (currentWindow is null)
36+
// return;
37+
38+
// try
39+
// {
40+
// //currentWindow.SetTitleBar(DefaultOverrideTitleBar);
41+
// currentWindow.SetTitleBar(DefaultOverrideTitleBar.TitleBarElement);
42+
43+
// }
44+
// catch (Exception ex)
45+
// {
46+
// Debug.WriteLine($"Failed to set title bar: {ex.Message}");
47+
// }
48+
49+
//#endif
50+
// }
4951

5052

5153

src/uno/AzureKeyVaultStudio/AzureKeyVaultStudio/Presentation/ViewModels/TabsControlViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public partial class TabsControlViewModel : ObservableRecipient
2222

2323

2424
[ObservableProperty]
25-
public partial bool IsTeachingTipOpen { get; set; } = true;
25+
public partial bool IsTeachingTipOpen { get; set; } = false;
2626

2727
[ObservableProperty]
2828
public partial VaultViewModel? CurrentVaultViewModel { get; set; }

src/uno/AzureKeyVaultStudio/AzureKeyVaultStudio/Presentation/ViewModels/VaultViewModel.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,19 @@ private void NewSecret()
221221

222222
async partial void OnSelectedIndexChanged(int value)
223223
{
224-
await FilterAndLoadVaultValueTypeCommand.ExecuteAsync(new CancellationToken());
224+
try
225+
{
226+
await FilterAndLoadVaultValueTypeCommand.ExecuteAsync(new CancellationToken());
227+
}
228+
catch (Exception ex)
229+
{
230+
Debug.WriteLine($"Failed to load selected vault tab: {ex}");
231+
TryEnqueueOnDispatcher(() =>
232+
{
233+
HasAuthorizationError = true;
234+
AuthorizationMessage = ex.Message;
235+
});
236+
}
225237
}
226238

227239
public void Initialize(KeyVaultData keyVaultData)
@@ -388,6 +400,14 @@ await ExecuteOnDispatcherAsync(() =>
388400
Debug.WriteLine("Loading canceled.");
389401
return;
390402
}
403+
catch (AuthenticationRequiredException ex)
404+
{
405+
TryEnqueueOnDispatcher(() =>
406+
{
407+
HasAuthorizationError = true;
408+
AuthorizationMessage = ex.Message;
409+
});
410+
}
391411
catch (Exception ex) when (ex.Message.Contains("403", StringComparison.OrdinalIgnoreCase))
392412
{
393413
// we only show error when not on "All" tab, partial success is acceptable for "All"
@@ -400,6 +420,15 @@ await ExecuteOnDispatcherAsync(() =>
400420
});
401421
}
402422
}
423+
catch (Exception ex)
424+
{
425+
Debug.WriteLine($"Unhandled vault loading error: {ex}");
426+
TryEnqueueOnDispatcher(() =>
427+
{
428+
HasAuthorizationError = true;
429+
AuthorizationMessage = ex.Message;
430+
});
431+
}
403432
finally
404433
{
405434
await ExecuteOnDispatcherAsync(() =>
@@ -722,7 +751,7 @@ await ExecuteOnDispatcherAsync(() =>
722751
}
723752

724753
[RelayCommand]
725-
private async void OpenInAzure(KeyVaultItemProperties keyVaultItem)
754+
private async Task OpenInAzure(KeyVaultItemProperties keyVaultItem)
726755
{
727756
if (keyVaultItem is null) return;
728757

0 commit comments

Comments
 (0)