Skip to content

Commit bfde057

Browse files
committed
fix: Show dialogs as non-dismissable popups
1 parent fa6a46d commit bfde057

3 files changed

Lines changed: 20 additions & 18 deletions

File tree

PostCodeSerialMonitor/ViewModels/ConfigurationDialogViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ await _configurationService.UpdateConfigurationAsync(config =>
8282
await MessageBoxManager
8383
.GetMessageBoxStandard(Assets.Resources.RestartRequired, string.Format(Assets.Resources.LanguageChangedPleaseRestart),
8484
ButtonEnum.Ok)
85-
.ShowAsync();
85+
.ShowAsPopupAsync(GetParentWindow());
8686
}
8787
}
8888

PostCodeSerialMonitor/ViewModels/MainWindowViewModel.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public async void OnLoaded()
199199
ButtonEnum.YesNo
200200
);
201201

202-
var result = await box.ShowAsync();
202+
var result = await box.ShowAsPopupAsync(GetParentWindow());
203203

204204
if (result.HasFlag(ButtonResult.Yes))
205205
{
@@ -212,7 +212,7 @@ public async void OnLoaded()
212212
_logger.LogError(ex, Assets.Resources.FailedUpdateMetadata);
213213
await MessageBoxManager
214214
.GetMessageBoxStandard(Assets.Resources.Error, string.Format(Assets.Resources.FailedUpdateMetadataMessageBoxError, ex.Message), ButtonEnum.Ok)
215-
.ShowAsync();
215+
.ShowAsPopupAsync(GetParentWindow());
216216
}
217217
}
218218
}
@@ -228,7 +228,7 @@ await MessageBoxManager
228228
.GetMessageBoxStandard(Assets.Resources.Warning, Assets.Resources.FailedLoadLocalMetadataMessageBoxWarning,
229229
ButtonEnum.Ok);
230230

231-
await box.ShowAsync();
231+
await box.ShowAsPopupAsync(GetParentWindow());
232232
}
233233

234234
try
@@ -241,7 +241,7 @@ await MessageBoxManager
241241
await MessageBoxManager
242242
.GetMessageBoxStandard(Assets.Resources.Error, string.Format(Assets.Resources.FailedLoadLocalMetadataMessageBoxError, ex.Message),
243243
ButtonEnum.Ok)
244-
.ShowAsync();
244+
.ShowAsPopupAsync(GetParentWindow());
245245
}
246246

247247
if (_configurationService.Config.CheckForAppUpdates)
@@ -255,7 +255,7 @@ await MessageBoxManager
255255
Assets.Resources.NewAppReleaseAvailable,
256256
"https://github.com/xboxoneresearch/XboxPostcodeMonitor/releases"
257257
));
258-
await box.ShowAsync();
258+
await box.ShowAsPopupAsync(GetParentWindow());
259259
}
260260
}
261261
}
@@ -328,7 +328,7 @@ private async Task SaveLogAsync()
328328
await MessageBoxManager
329329
.GetMessageBoxStandard(Assets.Resources.Error, string.Format(Assets.Resources.ErrorSavingLogFileMessageBoxError, ex.Message),
330330
ButtonEnum.Ok)
331-
.ShowAsync();
331+
.ShowAsPopupAsync(GetParentWindow());
332332
}
333333
}
334334

@@ -370,7 +370,7 @@ private async Task ToggleConnectionAsync()
370370
await MessageBoxManager
371371
.GetMessageBoxStandard(Assets.Resources.Error, string.Format(Assets.Resources.ErrorConectionMessageBoxError, ex.Message),
372372
ButtonEnum.Ok)
373-
.ShowAsync();
373+
.ShowAsPopupAsync(GetParentWindow());
374374
}
375375

376376
if (IsConnected && _configurationService.Config.CheckForFwUpdates)
@@ -384,7 +384,7 @@ await MessageBoxManager
384384
Assets.Resources.NewFirmwareReleaseAvailable,
385385
"https://github.com/xboxoneresearch/PicoDurangoPOST/releases"
386386
));
387-
await box.ShowAsync();
387+
await box.ShowAsPopupAsync(GetParentWindow());
388388
}
389389
}
390390
}
@@ -441,12 +441,4 @@ private async Task ShowConfigurationAsync()
441441

442442
await dialog.ShowDialog(GetParentWindow());
443443
}
444-
445-
private Window GetParentWindow()
446-
{
447-
if (Avalonia.Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
448-
return desktop?.MainWindow ?? throw new Exception(Assets.Resources.FailedGetMainWindow);
449-
else
450-
throw new Exception(Assets.Resources.FailedGetApplicationLifetime);
451-
}
452444
}
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
using CommunityToolkit.Mvvm.ComponentModel;
1+
using System;
2+
using Avalonia.Controls;
3+
using Avalonia.Controls.ApplicationLifetimes;
4+
using CommunityToolkit.Mvvm.ComponentModel;
25

36
namespace PostCodeSerialMonitor.ViewModels;
47

58
public class ViewModelBase : ObservableObject
69
{
10+
internal Window GetParentWindow()
11+
{
12+
if (Avalonia.Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
13+
return desktop?.MainWindow ?? throw new Exception(Assets.Resources.FailedGetMainWindow);
14+
else
15+
throw new Exception(Assets.Resources.FailedGetApplicationLifetime);
16+
}
717
}

0 commit comments

Comments
 (0)