Rebased from b99c7ea4 on 10/2/2022. Updated onboarding page to fix URL verification. Added better error handling for 3XX status codes from https check. We now extract the new location from the 300 status code.

fix spacing on onBoarding.xaml
This commit is contained in:
Nathan Hughes 2024-05-01 09:31:11 -05:00
parent b99c7ea433
commit 7bd8d7a4bc
2 changed files with 75 additions and 28 deletions

View File

@ -32,35 +32,46 @@
</Grid.RowDefinitions>
<Grid Background="{StaticResource Color10}">
<Image x:Name="logo" Source="/Assets/OnBoardingLogo.png" Stretch="Uniform" HorizontalAlignment="Center" Height="80" />
<Image
x:Name="logo"
Source="/Assets/OnBoardingLogo.png"
Stretch="Uniform"
HorizontalAlignment="Center"
Height="80" />
</Grid>
<Grid Grid.Row="1" Padding="0 40 0 0">
<StackPanel x:Name="pnlMain" HorizontalAlignment="Center" VerticalAlignment="Top" Width="640">
<TextBlock
x:Name="txtTitle"
Text="Connect to Server" Foreground="White" FontSize="{StaticResource FontL}" Margin="0 0 0 28" FontFamily="{StaticResource JellyfinFamilyFont}" />
<TextBlock FontFamily="{StaticResource JellyfinFamilyFont}"
Text="Host:"
Foreground="{StaticResource Color100}" FontSize="{StaticResource FontM}" />
<TextBox x:Name="txtUrl" Style="{StaticResource PrimaryTextBox}" Margin="0 8 0 8" />
<TextBlock FontFamily="{StaticResource JellyfinFamilyFont}"
Text="ex: 192.168.1.100:8096 or https://myserver.com. The protocol 'http://' and 'https://' will be automatically added."
Foreground="{StaticResource Color90}" FontSize="{StaticResource FontS}"
Margin="0 0 0 28 "/>
<StackPanel
x:Name="pnlMain"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Width="640">
<TextBlock
x:Name="txtTitle"
Text="Connect to Jellyfin Server"
Foreground="White" FontSize="{StaticResource FontL}"
Margin="0 0 0 28" FontFamily="{StaticResource JellyfinFamilyFont}"
HorizontalAlignment="Center" />
<TextBox
x:Name="txtUrl"
Style="{StaticResource PrimaryTextBox}"
Margin="0 8 0 8"
PlaceholderText="ex: 192.168.1.100:8096 or demo.jellyfin.org"/>
<TextBlock
x:Name="txtError"
FontFamily="{StaticResource JellyfinFamilyFont}"
Text="We're unable to connect to the selected server right now. Please ensure it is running and try again"
HorizontalAlignment="Center"
TextAlignment="Center"
TextWrapping="Wrap"
Visibility="Collapsed"
FontSize="{StaticResource FontM}"
Margin="0 -16 0 20"
Foreground="#CF4A4A" />
<Button x:Name="btnConnect" Style="{StaticResource PrimaryButton}" Content="Connect" />
x:Name="txtError"
FontFamily="{StaticResource JellyfinFamilyFont}"
Text="We're unable to connect to the selected server right now. Please ensure it is running and try again"
HorizontalAlignment="Center"
TextAlignment="Center"
TextWrapping="Wrap"
Visibility="Collapsed"
FontSize="{StaticResource FontM}"
Margin="1 1 1 20"
Foreground="#CF4A4A" />
<Button
x:Name="btnConnect"
Style="{StaticResource PrimaryButton}"
Content="Connect" />
</StackPanel>
</Grid>

View File

@ -82,8 +82,10 @@ namespace Jellyfin.Views
{
return false;
}
//add scheme to uri if not included
Uri testUri = new UriBuilder(uriString).Uri;
// check URL exists
HttpWebRequest request;
HttpWebResponse response;
@ -92,9 +94,33 @@ namespace Jellyfin.Views
request = (HttpWebRequest)WebRequest.Create(testUri);
response = (HttpWebResponse)(await request.GetResponseAsync());
}
catch (Exception)
catch (WebException ex)
{
return false;
// Handle web exceptions here
if (ex.Response != null && ex.Response is HttpWebResponse errorResponse)
{
int statusCode = (int)errorResponse.StatusCode;
if (statusCode >= 300 && statusCode <= 308)
{
// Handle Redirect
string newLocation = errorResponse.Headers["Location"];
if (!string.IsNullOrEmpty(newLocation))
{
uriString = newLocation;
return await CheckURLValidAsync(uriString); // Recursively check the new location
}
}
else
{
UpdateErrorMessage(statusCode);
}
return false;
}
else
{
// Handle other exceptions
return false;
}
}
if (response == null || response.StatusCode != HttpStatusCode.OK)
@ -112,7 +138,17 @@ namespace Jellyfin.Views
}
}
// If everything is OK, update the URI before saving it
Central.Settings.JellyfinServer = uriString;
return true;
}
private void UpdateErrorMessage(int statusCode)
{
txtError.Visibility = Visibility.Visible;
txtError.Text = $"Error: {statusCode}";
}
}
}
}