Do not launch settings dialog after installation

This commit is contained in:
Mbucari 2023-03-27 13:17:48 -06:00
parent a71ccbac6e
commit cdf1a01457
17 changed files with 144 additions and 120 deletions

View File

@ -39,18 +39,15 @@ namespace LibationAvalonia
}
public static Task<List<DataLayer.LibraryBook>> LibraryTask;
public static bool SetupRequired;
public override void OnFrameworkInitializationCompleted()
{
LoadStyles();
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
if (SetupRequired)
{
var config = Configuration.Instance;
var config = Configuration.Instance;
if (!config.LibationSettingsAreValid)
{
var defaultLibationFilesDir = Configuration.UserProfile;
// check for existing settings in default location
@ -90,7 +87,25 @@ namespace LibationAvalonia
if (setupDialog.IsNewUser)
{
Configuration.SetLibationFiles(Configuration.UserProfile);
ShowSettingsWindow(desktop, setupDialog.Config, OnSettingsCompleted);
setupDialog.Config.Books = Path.Combine(Configuration.UserProfile, nameof(Configuration.Books));
if (setupDialog.Config.LibationSettingsAreValid)
{
var theme
= setupDialog.SelectedTheme.Content is nameof(ThemeVariant.Dark)
? nameof(ThemeVariant.Dark)
: nameof(ThemeVariant.Light);
setupDialog.Config.SetString(theme, nameof(ThemeVariant));
await RunMigrationsAsync(setupDialog.Config);
LibraryTask = Task.Run(() => DbContexts.GetLibrary_Flat_NoTracking(includeParents: true));
AudibleUtilities.AudibleApiStorage.EnsureAccountsSettingsFileExists();
ShowMainWindow(desktop);
}
else
await CancelInstallation();
}
else if (setupDialog.IsReturningUser)
{
@ -130,40 +145,6 @@ namespace LibationAvalonia
AppScaffolding.LibationScaffolding.RunPostMigrationScaffolding(config);
}
private void ShowSettingsWindow(IClassicDesktopStyleApplicationLifetime desktop, Configuration config, Action<IClassicDesktopStyleApplicationLifetime, SettingsDialog, Configuration> OnClose)
{
config.Books ??= Path.Combine(Configuration.UserProfile, "Books");
var settingsDialog = new SettingsDialog();
desktop.MainWindow = settingsDialog;
settingsDialog.RestoreSizeAndLocation(Configuration.Instance);
settingsDialog.Show();
void WindowClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
settingsDialog.Closing -= WindowClosing;
e.Cancel = true;
OnClose?.Invoke(desktop, settingsDialog, config);
}
settingsDialog.Closing += WindowClosing;
}
private async void OnSettingsCompleted(IClassicDesktopStyleApplicationLifetime desktop, SettingsDialog settingsDialog, Configuration config)
{
if (config.LibationSettingsAreValid)
{
await RunMigrationsAsync(config);
LibraryTask = Task.Run(() => DbContexts.GetLibrary_Flat_NoTracking(includeParents: true));
AudibleUtilities.AudibleApiStorage.EnsureAccountsSettingsFileExists();
ShowMainWindow(desktop);
}
else
await CancelInstallation();
settingsDialog.Close();
}
private void ShowLibationFilesDialog(IClassicDesktopStyleApplicationLifetime desktop, Configuration config, Action<IClassicDesktopStyleApplicationLifetime, LibationFilesDialog, Configuration> OnClose)
{
var libationFilesDialog = new LibationFilesDialog();
@ -200,11 +181,23 @@ namespace LibationAvalonia
MessageBoxIcon.Question);
if (continueResult == DialogResult.Yes)
ShowSettingsWindow(desktop, config, OnSettingsCompleted);
{
config.Books = Path.Combine(libationFilesDialog.SelectedDirectory, nameof(Configuration.Books));
if (config.LibationSettingsAreValid)
{
await RunMigrationsAsync(config);
LibraryTask = Task.Run(() => DbContexts.GetLibrary_Flat_NoTracking(includeParents: true));
AudibleUtilities.AudibleApiStorage.EnsureAccountsSettingsFileExists();
ShowMainWindow(desktop);
}
else
await CancelInstallation();
}
else
await CancelInstallation();
}
libationFilesDialog.Close();
}
@ -230,11 +223,11 @@ namespace LibationAvalonia
private static void LoadStyles()
{
ProcessQueueBookFailedBrush = AvaloniaUtils.GetBrushFromResources("ProcessQueueBookFailedBrush");
ProcessQueueBookCompletedBrush = AvaloniaUtils.GetBrushFromResources("ProcessQueueBookCompletedBrush");
ProcessQueueBookCancelledBrush = AvaloniaUtils.GetBrushFromResources("ProcessQueueBookCancelledBrush");
SeriesEntryGridBackgroundBrush = AvaloniaUtils.GetBrushFromResources("SeriesEntryGridBackgroundBrush");
ProcessQueueBookDefaultBrush = AvaloniaUtils.GetBrushFromResources("ProcessQueueBookDefaultBrush");
ProcessQueueBookFailedBrush = AvaloniaUtils.GetBrushFromResources(nameof(ProcessQueueBookFailedBrush));
ProcessQueueBookCompletedBrush = AvaloniaUtils.GetBrushFromResources(nameof(ProcessQueueBookCompletedBrush));
ProcessQueueBookCancelledBrush = AvaloniaUtils.GetBrushFromResources(nameof(ProcessQueueBookCancelledBrush));
SeriesEntryGridBackgroundBrush = AvaloniaUtils.GetBrushFromResources(nameof(SeriesEntryGridBackgroundBrush));
ProcessQueueBookDefaultBrush = AvaloniaUtils.GetBrushFromResources(nameof(ProcessQueueBookDefaultBrush));
HyperlinkVisited = AvaloniaUtils.GetBrushFromResources(nameof(HyperlinkVisited));
}
}

View File

@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
MinWidth="500" MinHeight="450"
Width="500" Height="450"
x:Class="LibationAvalonia.Dialogs.EditReplacementChars"
Title="Illegal Character Replacement"
Icon="/Assets/libation.ico">

View File

@ -3,6 +3,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
Width="800" Height="450"
x:Class="LibationAvalonia.Dialogs.EditTemplateDialog"
xmlns:dialogs="clr-namespace:LibationAvalonia.Dialogs"
Icon="/Assets/libation.ico"

View File

@ -5,6 +5,7 @@
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="500"
x:Class="LibationAvalonia.Dialogs.ImageDisplayDialog"
MinWidth="500" MinHeight="500"
Width="500" Height="520"
Title="Cover"
WindowStartupLocation="CenterOwner"
Icon="/Assets/libation.ico">

View File

@ -8,6 +8,7 @@
Title="Liberated status: Whether the book has been downloaded"
MinHeight="100" MaxHeight="165"
MinWidth="600" MaxWidth="800"
Width="600"
WindowStartupLocation="CenterOwner"
Icon="/Assets/libation.ico">

View File

@ -8,6 +8,7 @@
Title="Liberated status: Whether the book has been downloaded"
MinWidth="400" MinHeight="120"
MaxWidth="400" MaxHeight="120"
Width="400" Height="120"
WindowStartupLocation="CenterOwner"
Icon="/Assets/libation.ico">

View File

@ -5,7 +5,7 @@
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="185"
x:Class="LibationAvalonia.Dialogs.ScanAccountsDialog"
MinWidth="500" MinHeight="160"
MaxWidth="500" MaxHeight="185"
Width="500" Height="200"
Title="Which Accounts?"
WindowStartupLocation="CenterOwner"
Icon="/Assets/libation.ico">

View File

@ -5,6 +5,7 @@
mc:Ignorable="d" d:DesignWidth="950" d:DesignHeight="650"
MinWidth="950" MinHeight="650"
MaxWidth="950" MaxHeight="650"
Width="950" Height="650"
x:Class="LibationAvalonia.Dialogs.SearchSyntaxDialog"
Title="Filter Options"
WindowStartupLocation="CenterOwner"

View File

@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="900" d:DesignHeight="750"
MinWidth="900" MinHeight="700"
Width="900" Height="700"
x:Class="LibationAvalonia.Dialogs.SettingsDialog"
xmlns:controls="clr-namespace:LibationAvalonia.Controls"
Title="Edit Settings"

View File

@ -3,14 +3,16 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="350"
MinWidth="500" MinHeight="350"
MaxWidth="500" MaxHeight="350"
x:Class="LibationAvalonia.Dialogs.SetupDialog"
WindowStartupLocation="CenterScreen"
Width="500" Height="350"
Icon="/Assets/libation.ico"
Title="Welcome to Libation">
<Grid Margin="10" ColumnDefinitions="*" RowDefinitions="*,Auto,Auto">
<Grid
Margin="10"
HorizontalAlignment="Stretch"
RowDefinitions="*,Auto,Auto">
<TextBlock Grid.Row="0" TextWrapping="Wrap" Text="This appears to be your first time using Libation or a previous setup was incomplete.
&#xa;
@ -22,17 +24,47 @@
&#xa;Download your entire library from the &quot;Liberate&quot; tab or
&#xa;liberate your books one at a time by clicking the stoplight." />
<Button
<Grid
Grid.Row="1"
Width="480"
Margin="0,0,0,10"
Click="NewUser_Click">
HorizontalAlignment="Stretch"
ColumnDefinitions="*,Auto"
Margin="0,0,0,10">
<Button
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Center"
Padding="0,20"
Margin="0,0,10,0"
Click="NewUser_Click">
<TextBlock
FontSize="18"
TextAlignment="Center"
Text="NEW USER"/>
</Button>
<Grid
Grid.Column="1"
RowDefinitions="*,*">
<TextBlock
TextAlignment="Center"
Text="NEW USER&#xa;&#xa;Choose Settings"/>
VerticalAlignment="Top"
Text="Theme: " />
</Button>
<ComboBox
Grid.Row="1"
VerticalAlignment="Bottom"
SelectedIndex="0"
SelectedItem="{Binding SelectedTheme, Mode=OneWayToSource}">
<ComboBox.Items>
<ComboBoxItem Content="Light" />
<ComboBoxItem Content="Dark" />
</ComboBox.Items>
</ComboBox>
</Grid>
</Grid>
<Button
Grid.Row="2"

View File

@ -7,10 +7,12 @@ namespace LibationAvalonia.Dialogs
{
public bool IsNewUser { get; private set; }
public bool IsReturningUser { get; private set; }
public ComboBoxItem SelectedTheme { get; set; }
public Configuration Config { get; init; }
public SetupDialog()
{
InitializeComponent();
DataContext = this;
}
public void NewUser_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)

View File

@ -6,6 +6,7 @@
x:Class="LibationAvalonia.Dialogs.TagsBatchDialog"
MinWidth="630" MinHeight="110"
MaxWidth="630" MaxHeight="110"
Width="630" Height="110"
Title="Replace Tags"
WindowStartupLocation="CenterOwner"
Icon="/Assets/libation.ico">

View File

@ -6,6 +6,7 @@
x:Class="LibationAvalonia.Dialogs.TrashBinDialog"
xmlns:controls="clr-namespace:LibationAvalonia.Controls"
MinWidth="630" MinHeight="480"
Width="630" Height="480"
Title="Trash Bin"
WindowStartupLocation="CenterOwner"
Icon="/Assets/libation.ico">

View File

@ -43,8 +43,6 @@ namespace LibationAvalonia
// Migrations which must occur before configuration is loaded for the first time. Usually ones which alter the Configuration
var config = LibationScaffolding.RunPreConfigMigrations();
App.SetupRequired = !config.LibationSettingsAreValid;
//Start as much work in parallel as possible.
var classicLifetimeTask = Task.Run(() => new ClassicDesktopStyleApplicationLifetime());
var appBuilderTask = Task.Run(BuildAvaloniaApp);
@ -55,7 +53,7 @@ namespace LibationAvalonia
return;
if (!App.SetupRequired)
if (config.LibationSettingsAreValid)
{
if (!RunDbMigrations(config))
return;
@ -63,7 +61,7 @@ namespace LibationAvalonia
App.LibraryTask = Task.Run(() => DbContexts.GetLibrary_Flat_NoTracking(includeParents: true));
}
(appBuilderTask.GetAwaiter().GetResult()).SetupWithLifetime(classicLifetimeTask.GetAwaiter().GetResult());
appBuilderTask.GetAwaiter().GetResult().SetupWithLifetime(classicLifetimeTask.GetAwaiter().GetResult());
classicLifetimeTask.Result.Start(null);
}

View File

@ -29,64 +29,61 @@
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SetupDialog));
this.welcomeLbl = new System.Windows.Forms.Label();
this.newUserBtn = new System.Windows.Forms.Button();
this.returningUserBtn = new System.Windows.Forms.Button();
this.SuspendLayout();
welcomeLbl = new System.Windows.Forms.Label();
newUserBtn = new System.Windows.Forms.Button();
returningUserBtn = new System.Windows.Forms.Button();
SuspendLayout();
//
// welcomeLbl
//
this.welcomeLbl.AutoSize = true;
this.welcomeLbl.Location = new System.Drawing.Point(14, 10);
this.welcomeLbl.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.welcomeLbl.Name = "welcomeLbl";
this.welcomeLbl.Size = new System.Drawing.Size(449, 135);
this.welcomeLbl.TabIndex = 0;
this.welcomeLbl.Text = resources.GetString("welcomeLbl.Text");
welcomeLbl.AutoSize = true;
welcomeLbl.Location = new System.Drawing.Point(14, 10);
welcomeLbl.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
welcomeLbl.Name = "welcomeLbl";
welcomeLbl.Size = new System.Drawing.Size(449, 135);
welcomeLbl.TabIndex = 0;
welcomeLbl.Text = resources.GetString("welcomeLbl.Text");
//
// newUserBtn
//
this.newUserBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.newUserBtn.Location = new System.Drawing.Point(18, 156);
this.newUserBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.newUserBtn.Name = "newUserBtn";
this.newUserBtn.Size = new System.Drawing.Size(462, 66);
this.newUserBtn.TabIndex = 2;
this.newUserBtn.Text = "NEW USER\r\n\r\nChoose settings";
this.newUserBtn.UseVisualStyleBackColor = true;
this.newUserBtn.Click += new System.EventHandler(this.newUserBtn_Click);
newUserBtn.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
newUserBtn.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
newUserBtn.Location = new System.Drawing.Point(18, 156);
newUserBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
newUserBtn.Name = "newUserBtn";
newUserBtn.Size = new System.Drawing.Size(462, 66);
newUserBtn.TabIndex = 2;
newUserBtn.Text = "NEW USER";
newUserBtn.UseVisualStyleBackColor = true;
newUserBtn.Click += newUserBtn_Click;
//
// returningUserBtn
//
this.returningUserBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.returningUserBtn.Location = new System.Drawing.Point(18, 228);
this.returningUserBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.returningUserBtn.Name = "returningUserBtn";
this.returningUserBtn.Size = new System.Drawing.Size(462, 66);
this.returningUserBtn.TabIndex = 3;
this.returningUserBtn.Text = "RETURNING USER\r\n\r\nI have previously installed Libation. This is an upgrade or re-" +
"install";
this.returningUserBtn.UseVisualStyleBackColor = true;
this.returningUserBtn.Click += new System.EventHandler(this.returningUserBtn_Click);
returningUserBtn.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
returningUserBtn.Location = new System.Drawing.Point(18, 228);
returningUserBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
returningUserBtn.Name = "returningUserBtn";
returningUserBtn.Size = new System.Drawing.Size(462, 66);
returningUserBtn.TabIndex = 3;
returningUserBtn.Text = "RETURNING USER\r\n\r\nI have previously installed Libation. This is an upgrade or re-install";
returningUserBtn.UseVisualStyleBackColor = true;
returningUserBtn.Click += returningUserBtn_Click;
//
// SetupDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(493, 308);
this.Controls.Add(this.returningUserBtn);
this.Controls.Add(this.newUserBtn);
this.Controls.Add(this.welcomeLbl);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.Name = "SetupDialog";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Welcome to Libation";
this.ResumeLayout(false);
this.PerformLayout();
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
ClientSize = new System.Drawing.Size(493, 308);
Controls.Add(returningUserBtn);
Controls.Add(newUserBtn);
Controls.Add(welcomeLbl);
FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
Name = "SetupDialog";
StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
Text = "Welcome to Libation";
ResumeLayout(false);
PerformLayout();
}
#endregion

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">

View File

@ -142,12 +142,6 @@ namespace LibationWinForms
// if 'new user' was clicked, or if 'returning user' chose new install: show basic settings dialog
config.Books ??= Path.Combine(defaultLibationFilesDir, "Books");
if (new SettingsDialog().ShowDialog() != DialogResult.OK)
{
CancelInstallation();
return;
}
if (config.LibationSettingsAreValid)
return;