Skip to content

Commit

Permalink
Tweak the order of popups when the app loads
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Apr 23, 2024
1 parent 32ebf3b commit 98dee7e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 35 deletions.
56 changes: 28 additions & 28 deletions LightBulb/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,33 @@ UpdateService updateService

public DashboardViewModel Dashboard { get; } = viewModelManager.CreateDashboardViewModel();

private async Task FinalizePendingUpdateAsync()
{
var updateVersion = updateService.TryGetLastPreparedUpdate();
if (updateVersion is null)
return;

var dialog = viewModelManager.CreateMessageBoxViewModel(
"Update available",
$"""
Update to {Program.Name} v{updateVersion} has been downloaded.
Do you want to install it now?
""",
"INSTALL",
"CANCEL"
);

Application.Current?.TryFocusMainWindow();

if (await dialogManager.ShowDialogAsync(dialog) != true)
return;

updateService.FinalizeUpdate(updateVersion);

if (Application.Current?.ApplicationLifetime?.TryShutdown(2) != true)
Environment.Exit(2);
}

private async Task ShowGammaRangePromptAsync()
{
if (settingsService.IsExtendedGammaRangeUnlocked)
Expand Down Expand Up @@ -113,43 +140,16 @@ Click LEARN MORE to find ways that you can help.
ProcessEx.StartShellExecute("https://tyrrrz.me/ukraine?source=lightbulb");
}

private async Task FinalizePendingUpdateAsync()
{
var updateVersion = updateService.TryGetLastPreparedUpdate();
if (updateVersion is null)
return;

var dialog = viewModelManager.CreateMessageBoxViewModel(
"Update available",
$"""
Update to {Program.Name} v{updateVersion} has been downloaded.
Do you want to install it now?
""",
"INSTALL",
"CANCEL"
);

Application.Current?.TryFocusMainWindow();

if (await dialogManager.ShowDialogAsync(dialog) != true)
return;

updateService.FinalizeUpdate(updateVersion);

if (Application.Current?.ApplicationLifetime?.TryShutdown(2) != true)
Environment.Exit(2);
}

[RelayCommand]
private async Task InitializeAsync()
{
// Load settings
settingsService.Load();

await FinalizePendingUpdateAsync();
await ShowGammaRangePromptAsync();
await ShowFirstTimeExperienceMessageAsync();
await ShowUkraineSupportMessageAsync();
await FinalizePendingUpdateAsync();

_checkForUpdatesTimer.Start();
}
Expand Down
5 changes: 1 addition & 4 deletions LightBulb/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
</Design.DataContext>

<Border BorderBrush="{DynamicResource MaterialPrimaryLightBrush}" BorderThickness="1">
<dialogHostAvalonia:DialogHost
x:Name="DialogHost"
CloseOnClickAway="False"
Loaded="DialogHost_OnLoaded">
<dialogHostAvalonia:DialogHost CloseOnClickAway="False">
<Grid RowDefinitions="Auto,*,Auto">
<!-- Header -->
<Border
Expand Down
5 changes: 2 additions & 3 deletions LightBulb/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ private void Window_OnLoaded(object sender, RoutedEventArgs args)
{
if (StartOptions.Current.IsInitiallyHidden)
Hide();

DataContext.InitializeCommand.Execute(null);
}

private void Window_OnClosing(object sender, WindowClosingEventArgs args)
Expand All @@ -22,9 +24,6 @@ private void Window_OnClosing(object sender, WindowClosingEventArgs args)
Hide();
}

private void DialogHost_OnLoaded(object? sender, RoutedEventArgs args) =>
DataContext.InitializeCommand.Execute(null);

private void HeaderBorder_OnPointerPressed(object? sender, PointerPressedEventArgs args) =>
BeginMoveDrag(args);

Expand Down

0 comments on commit 98dee7e

Please sign in to comment.