Archived
1
0

Offline errors fix

This commit is contained in:
Michael Gordeev
2018-08-15 16:57:31 +03:00
parent 8e454c3375
commit 26907c9aac
12 changed files with 172 additions and 113 deletions
+2
View File
@@ -55,6 +55,8 @@ namespace FoxTube
/// <param name="e">Details about the launch request and process.</param> /// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e) protected override void OnLaunched(LaunchActivatedEventArgs e)
{ {
SecretsVault.CheckAuthorization();
Frame rootFrame = Window.Current.Content as Frame; Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content, // Do not repeat app initialization when the Window already has content,
+7 -1
View File
@@ -3,6 +3,7 @@ using System;
using System.Diagnostics; using System.Diagnostics;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.UI; using Windows.UI;
using Windows.UI.Xaml; using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls;
@@ -11,13 +12,18 @@ using Windows.UI.Xaml.Media;
namespace FoxTube namespace FoxTube
{ {
class Methods public static class Methods
{ {
public static MainPage MainPage public static MainPage MainPage
{ {
get { return (Window.Current.Content as Frame).Content as MainPage; } get { return (Window.Current.Content as Frame).Content as MainPage; }
} }
public static void CloseApp()
{
CoreApplication.Exit();
}
public static string GetAgo(DateTime dateTime) public static string GetAgo(DateTime dateTime)
{ {
TimeSpan span = DateTime.Now - dateTime; TimeSpan span = DateTime.Now - dateTime;
+22
View File
@@ -10,6 +10,7 @@ using Google.Apis.Services;
using Google.Apis.YouTube.v3; using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data; using Google.Apis.YouTube.v3.Data;
using Windows.Storage; using Windows.Storage;
using Windows.UI.Popups;
namespace FoxTube namespace FoxTube
{ {
@@ -113,6 +114,8 @@ namespace FoxTube
try { Credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, new[] { Google.Apis.Oauth2.v2.Oauth2Service.Scope.UserinfoProfile, YouTubeService.Scope.YoutubeForceSsl }, "user", CancellationToken.None); } try { Credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, new[] { Google.Apis.Oauth2.v2.Oauth2Service.Scope.UserinfoProfile, YouTubeService.Scope.YoutubeForceSsl }, "user", CancellationToken.None); }
catch { } catch { }
if(Credential != null) if(Credential != null)
{
try
{ {
if (settings.Values["authorized"] == null) if (settings.Values["authorized"] == null)
settings.Values.Add("authorized", true); settings.Values.Add("authorized", true);
@@ -170,6 +173,25 @@ namespace FoxTube
foreach (Subscription s in subResponse.Items) foreach (Subscription s in subResponse.Items)
Subscriptions.Add(s); Subscriptions.Add(s);
} }
}
catch
{
MessageDialog dialog = new MessageDialog("We were unabled to retrieve your account information due to weak internet connection or Google servers' problems. PLease, try again later", "Failed to connect");
dialog.Commands.Add(new UICommand("Try again", (command) =>
{
Authorize();
}));
dialog.Commands.Add(new UICommand("Quit", (command) =>
{
Methods.CloseApp();
}));
dialog.Commands.Add(new UICommand("Close"));
await dialog.ShowAsync();
IsAuthorized = false;
}
AuthorizationStateChanged.Invoke(null, null); AuthorizationStateChanged.Invoke(null, null);
} }
+8
View File
@@ -141,6 +141,10 @@ namespace FoxTube.Pages
loading.Close(); loading.Close();
} }
catch (System.Net.Http.HttpRequestException)
{
loading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
}
catch catch
{ {
loading.Error(); loading.Error();
@@ -175,6 +179,10 @@ namespace FoxTube.Pages
playlistLoading.Close(); playlistLoading.Close();
} }
catch (System.Net.Http.HttpRequestException)
{
playlistLoading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
}
catch catch
{ {
playlistLoading.Error(); playlistLoading.Error();
+42
View File
@@ -57,6 +57,15 @@ namespace FoxTube
trendMore.Clicked += TrendMore_Clicked; trendMore.Clicked += TrendMore_Clicked;
subsMore.Clicked += SubsMore_Clicked; subsMore.Clicked += SubsMore_Clicked;
recLoading.RefreshPage += refreshPage;
subsLoading.RefreshPage += refreshPage;
trendLoading.RefreshPage += refreshPage;
Initialize();
}
private void refreshPage(object sender, RoutedEventArgs e)
{
Initialize(); Initialize();
} }
@@ -195,6 +204,8 @@ namespace FoxTube
} }
async void LoadTrending() async void LoadTrending()
{
try
{ {
VideosResource.ListRequest request = SecretsVault.Service.Videos.List("id"); VideosResource.ListRequest request = SecretsVault.Service.Videos.List("id");
request.MaxResults = 48; request.MaxResults = 48;
@@ -217,19 +228,50 @@ namespace FoxTube
trendLoading.Close(); trendLoading.Close();
trendLoaded = true; trendLoaded = true;
} }
catch (System.Net.Http.HttpRequestException)
{
trendLoading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
}
catch
{
trendLoading.Error();
}
}
void LoadRecommendations() void LoadRecommendations()
{
try
{ {
recLoading.Close(); recLoading.Close();
recLoaded = true; recLoaded = true;
recLoading.Block(); recLoading.Block();
} }
catch (System.Net.Http.HttpRequestException)
{
recLoading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
}
catch
{
recLoading.Error();
}
}
void LoadSubscriptions() void LoadSubscriptions()
{
try
{ {
subsLoading.Close(); subsLoading.Close();
subsLoaded = true; subsLoaded = true;
subsLoading.Block(); subsLoading.Block();
} }
catch (System.Net.Http.HttpRequestException)
{
subsLoading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
}
catch
{
subsLoading.Error();
}
}
} }
} }
+4 -4
View File
@@ -20,8 +20,8 @@
</StackPanel> </StackPanel>
<TextBlock Text="OR" FontSize="20" HorizontalAlignment="Center"/> <TextBlock Text="OR" FontSize="20" HorizontalAlignment="Center"/>
<Button Name="wifiRefresh" Click="wifiRefresh_Click" Content="Refresh page" HorizontalAlignment="Center" Background="Red" Foreground="White" Margin="5"/> <Button Name="wifiRefresh" Click="wifiRefresh_Click" Content="Refresh page" HorizontalAlignment="Center" Background="Red" Foreground="White" Margin="5"/>
<TextBlock Name="wifiException" Foreground="Gray" Text="Exception:" HorizontalAlignment="Center"/> <TextBlock Name="wifiException" Foreground="Gray" Text="Exception:" HorizontalAlignment="Center" IsTextSelectionEnabled="True"/>
<TextBlock Name="wifiMessage" Foreground="Gray" Text="Message:" HorizontalAlignment="Center"/> <TextBlock Name="wifiMessage" Foreground="Gray" Text="Message:" HorizontalAlignment="Center" IsTextSelectionEnabled="True"/>
</StackPanel> </StackPanel>
<StackPanel Name="trouble" Visibility="Collapsed" VerticalAlignment="Center"> <StackPanel Name="trouble" Visibility="Collapsed" VerticalAlignment="Center">
@@ -32,8 +32,8 @@
<Button Name="refresh" Click="wifiRefresh_Click" Content="Refresh page" Margin="5"/> <Button Name="refresh" Click="wifiRefresh_Click" Content="Refresh page" Margin="5"/>
<Button Content="Leave feedback" Background="Red" Foreground="White" Margin="5" Name="feedback" Click="feedback_Click"/> <Button Content="Leave feedback" Background="Red" Foreground="White" Margin="5" Name="feedback" Click="feedback_Click"/>
</StackPanel> </StackPanel>
<TextBlock Name="exception" Foreground="Gray" Text="Exception:" HorizontalAlignment="Center"/> <TextBlock Name="exception" Foreground="Gray" Text="Exception:" HorizontalAlignment="Center" IsTextSelectionEnabled="True"/>
<TextBlock Name="message" Foreground="Gray" Text="Message:" HorizontalAlignment="Center"/> <TextBlock Name="message" Foreground="Gray" Text="Message:" HorizontalAlignment="Center" IsTextSelectionEnabled="True"/>
</StackPanel> </StackPanel>
<FontIcon Name="blockIcon" Visibility="Collapsed" Glyph="&#xE25B;" FontSize="100" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Gray"/> <FontIcon Name="blockIcon" Visibility="Collapsed" Glyph="&#xE25B;" FontSize="100" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Gray"/>
+4 -4
View File
@@ -38,15 +38,15 @@ namespace FoxTube
if (isWifiTrouble) if (isWifiTrouble)
{ {
wifiException.Text = exceptionId; wifiException.Text = $"ID: {exceptionId}";
wifiMessage.Text = details; wifiMessage.Text = $"Details: {details}";
wifiTrouble.Visibility = Visibility.Visible; wifiTrouble.Visibility = Visibility.Visible;
} }
else else
{ {
exception.Text = exceptionId; exception.Text = $"ID: {exceptionId}";
message.Text = details; message.Text = $"Details: {details}";
trouble.Visibility = Visibility.Visible; trouble.Visibility = Visibility.Visible;
} }
+5 -3
View File
@@ -91,9 +91,6 @@ namespace FoxTube
SecretsVault.AuthorizationStateChanged += Vault_AuthorizationStateChanged; SecretsVault.AuthorizationStateChanged += Vault_AuthorizationStateChanged;
SecretsVault.SubscriptionsChanged += SecretsVault_SubscriptionsChanged; SecretsVault.SubscriptionsChanged += SecretsVault_SubscriptionsChanged;
SecretsVault.CheckAuthorization();
if (!SecretsVault.IsAuthorized)
nav.SelectedItem = toHome;
} }
protected override void OnNavigatedTo(NavigationEventArgs e) protected override void OnNavigatedTo(NavigationEventArgs e)
@@ -492,5 +489,10 @@ namespace FoxTube
else else
content.GoBack(); content.GoBack();
} }
public void CloseApp()
{
CoreApplication.Exit();
}
} }
} }
+4
View File
@@ -104,6 +104,10 @@ namespace FoxTube.Pages
loading.Close(); loading.Close();
} }
catch (System.Net.Http.HttpRequestException)
{
loading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
}
catch catch
{ {
loading.Error(); loading.Error();
+4
View File
@@ -168,6 +168,10 @@ namespace FoxTube
loading.Close(); loading.Close();
} }
catch (System.Net.Http.HttpRequestException)
{
loading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
}
catch catch
{ {
loading.Error(); loading.Error();
@@ -148,40 +148,5 @@ namespace FoxTube.Pages.SettingsPages
debugData = meta; debugData = meta;
debugAttached.Visibility = Visibility.Visible; debugAttached.Visibility = Visibility.Visible;
} }
/*
private void feedbackSubmit_Click(object sender, EventArgs e)
{
if (feedbackTitle.Text == "") MessageBox.Show("Please, fill the first field before submitting.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
{
string type()
{
if (feedbackSuggestion.Checked) return "Suggestion";
else return "Problem";
}
try
{
MailMessage msg = new MailMessage();
msg.To.Add("foxgameofficial@gmail.com");
msg.From = new MailAddress("sender@gmail.com");
msg.Subject = "Stream2String feedback";
msg.Body = "Type: " + type() + "\n\nTitle: " + feedbackTitle.Text + "\nDetails: " + feedbackDetails.Text + "\n\n" + feedbackMail.Text;
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.Credentials = new NetworkCredential("sender@gmail.com", "Thisisthepassword07734");
//Send the msg
client.Send(msg);
MessageBox.Show("Thank you for your feedback. You've just helped us to make our program better!", "Congratulations!", MessageBoxButtons.OK, MessageBoxIcon.Information);
proceedFeedback();
Properties.Settings.Default.feedback = true;
Properties.Settings.Default.Save();
}
catch { MessageBox.Show("Unfortunately, we can't send your feedback now. Please, try again later.", "Server connection error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
}
}*/
} }
} }
+4
View File
@@ -193,6 +193,10 @@ namespace FoxTube.Pages
loading.Close(); loading.Close();
} }
catch (System.Net.Http.HttpRequestException)
{
loading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
}
catch catch
{ {
loading.Error(); loading.Error();