Browse Source

Finished news, extension exceptions work

Krzysztof Krysiński 2 years ago
parent
commit
8851f4361a

+ 4 - 1
src/PixiEditor/Data/Localization/Languages/en.json

@@ -573,5 +573,8 @@
   "BUY_NOW": "Buy Now",
   "BUY_NOW": "Buy Now",
   "BUY_SUPPORTER_PACK": "Buy Supporter Pack",
   "BUY_SUPPORTER_PACK": "Buy Supporter Pack",
   "PALETTE_BROWSER_BUY_TEXT": "Buy Supporter Pack and get 21 beautiful palettes!",
   "PALETTE_BROWSER_BUY_TEXT": "Buy Supporter Pack and get 21 beautiful palettes!",
-  "HIDE_NEWS_PANEL": "Hide News panel in startup window"
+
+  "NEWS": "News",
+  "HIDE_NEWS_PANEL": "Hide News panel in startup window",
+  "FAILED_FETCH_NEWS": "Failed to fetch news"
 }
 }

+ 12 - 2
src/PixiEditor/Models/AppExtensions/ExtensionLoader.cs

@@ -6,6 +6,8 @@ using Newtonsoft.Json;
 using PixiEditor.Extensions;
 using PixiEditor.Extensions;
 using PixiEditor.Extensions.Common.Localization;
 using PixiEditor.Extensions.Common.Localization;
 using PixiEditor.Extensions.Metadata;
 using PixiEditor.Extensions.Metadata;
+using PixiEditor.Helpers;
+using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.IO;
 using PixiEditor.Models.IO;
 using PixiEditor.Platform;
 using PixiEditor.Platform;
 
 
@@ -38,9 +40,16 @@ internal class ExtensionLoader
 
 
     public void InitializeExtensions(ExtensionServices pixiEditorApi)
     public void InitializeExtensions(ExtensionServices pixiEditorApi)
     {
     {
-        foreach (var extension in LoadedExtensions)
+        try
+        {
+            foreach (var extension in LoadedExtensions)
+            {
+                extension.Initialize(pixiEditorApi);
+            }
+        }
+        catch (Exception ex)
         {
         {
-            extension.Initialize(pixiEditorApi);
+            Task.Run(async () => await CrashHelper.SendExceptionInfoToWebhook(ex));
         }
         }
     }
     }
 
 
@@ -77,6 +86,7 @@ internal class ExtensionLoader
         catch (Exception ex)
         catch (Exception ex)
         {
         {
             //MessageBox.Show(new LocalizedString("ERROR_LOADING_PACKAGE", packageJsonPath), "ERROR");
             //MessageBox.Show(new LocalizedString("ERROR_LOADING_PACKAGE", packageJsonPath), "ERROR");
+            Task.Run(async () => await CrashHelper.SendExceptionInfoToWebhook(ex));
         }
         }
     }
     }
 
 

+ 0 - 1
src/PixiEditor/Models/Services/NewsFeed/News.cs

@@ -23,7 +23,6 @@ internal record News
     public NewsType NewsType { get; set; } = NewsType.Misc;
     public NewsType NewsType { get; set; } = NewsType.Misc;
     public string Url { get; set; }
     public string Url { get; set; }
     public DateTime Date { get; set; }
     public DateTime Date { get; set; }
-
     public string CoverImageUrl { get; set; }
     public string CoverImageUrl { get; set; }
 
 
     [JsonIgnore]
     [JsonIgnore]

+ 0 - 47
src/PixiEditor/Models/Services/NewsFeed/NewsProvider.cs

@@ -15,53 +15,6 @@ internal class NewsProvider
         await FetchFrom(allNews, "shared.json");
         await FetchFrom(allNews, "shared.json");
         await FetchFrom(allNews, $"{IPlatform.Current.Id}.json");
         await FetchFrom(allNews, $"{IPlatform.Current.Id}.json");
 
 
-        var test = new News()
-        {
-            Title = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, " +
-                    "nisl eget ultricies ultrices, nisl nisl ultricies nisl, nec",
-            Date = DateTime.Now,
-            NewsType = NewsType.BlogPost,
-            CoverImageUrl = "https://clan.cloudflare.steamstatic.com/images/43538089/5f2b5ebdc3ceb5ffb9b9449e706edc397dc74e2b_400x225.png"
-        };
-
-        allNews.Add(test);
-        var test1 = new News()
-        {
-            Title = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, " +
-                    "nisl eget ultricies ultrices, nisl nisl ultricies nisl, nec",
-            Date = DateTime.Now,
-            NewsType = NewsType.Misc,
-            CoverImageUrl = "https://clan.cloudflare.steamstatic.com/images/43538089/1059f4aa3724c973dad343e403b4da129c4e19f4_400x225.png"
-        };
-
-        allNews.Add(test1);
-        var test2 = new News()
-        {
-            Title = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, " +
-                    "nisl eget ultricies ultrices, nisl nisl ultricies nisl, nec",
-            Date = DateTime.Now,
-            NewsType = NewsType.YtVideo
-        };
-        allNews.Add(test2);
-
-        var test3 = new News()
-        {
-            Title = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, " +
-                    "nisl eget ultricies ultrices, nisl nisl ultricies nisl, nec",
-            Date = DateTime.Now,
-            NewsType = NewsType.OfficialAnnouncement
-        };
-        allNews.Add(test3);
-        var test4 = new News()
-        {
-            Title = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, " +
-                    "nisl eget ultricies ultrices, nisl nisl ultricies nisl, nec",
-            Date = DateTime.Now,
-            NewsType = NewsType.NewVersion
-        };
-
-        allNews.Add(test4);
-
         return allNews.OrderByDescending(x => x.Date).Take(20).ToList();
         return allNews.OrderByDescending(x => x.Date).Take(20).ToList();
     }
     }
 
 

+ 19 - 10
src/PixiEditor/Views/Dialogs/HelloTherePopup.xaml

@@ -14,6 +14,7 @@
         xmlns:helpers="clr-namespace:PixiEditor.Helpers"
         xmlns:helpers="clr-namespace:PixiEditor.Helpers"
         xmlns:ui="clr-namespace:PixiEditor.Extensions.UI;assembly=PixiEditor.Extensions"
         xmlns:ui="clr-namespace:PixiEditor.Extensions.UI;assembly=PixiEditor.Extensions"
         xmlns:newsFeed="clr-namespace:PixiEditor.Views.UserControls.NewsFeed"
         xmlns:newsFeed="clr-namespace:PixiEditor.Views.UserControls.NewsFeed"
+        xmlns:gif="http://wpfanimatedgif.codeplex.com"
         mc:Ignorable="d" ShowInTaskbar="False"
         mc:Ignorable="d" ShowInTaskbar="False"
         Title="Hello there!" Height="662" Width="832" MinHeight="500" MinWidth="500"
         Title="Hello there!" Height="662" Width="832" MinHeight="500" MinWidth="500"
         d:DataContext="{d:DesignInstance local:HelloTherePopup}"
         d:DataContext="{d:DesignInstance local:HelloTherePopup}"
@@ -280,16 +281,24 @@
 
 
         <ScrollViewer Grid.Row="1" Grid.Column="1">
         <ScrollViewer Grid.Row="1" Grid.Column="1">
             <Border Padding="5" BorderThickness="3 0 0 0" BorderBrush="{StaticResource MainColor}">
             <Border Padding="5" BorderThickness="3 0 0 0" BorderBrush="{StaticResource MainColor}">
-                <StackPanel Orientation="Vertical">
-                    <TextBlock HorizontalAlignment="Center" Text="News" FontSize="18"/>
-                    <ItemsControl ItemsSource="{Binding Path=News}">
-                        <ItemsControl.ItemTemplate>
-                            <DataTemplate>
-                                <newsFeed:NewsItem Margin="5" News="{Binding Path=.}"/>
-                            </DataTemplate>
-                        </ItemsControl.ItemTemplate>
-                    </ItemsControl>
-                </StackPanel>
+                <Grid>
+                    <Image gif:ImageBehavior.AnimatedSource="/Images/Processing.gif" HorizontalAlignment="Center" VerticalAlignment="Center"
+                           Visibility="{Binding IsFetchingNews, Converter={converters:BoolToVisibilityConverter}}"
+                           Height="50" gif:ImageBehavior.AnimationSpeedRatio="1.5"/>
+                    <TextBlock ui:Translator.Key="FAILED_FETCH_NEWS" Foreground="White" FontSize="20"
+                               VerticalAlignment="Center" TextAlignment="Center"
+                               Visibility="{Binding Path=FailedFetchingNews, Converter={converters:BoolToVisibilityConverter}}"/>
+                    <StackPanel Orientation="Vertical" Visibility="{Binding IsFetchingNews, Converter={converters:InverseBoolToVisibilityConverter}}">
+                        <TextBlock HorizontalAlignment="Center" ui:Translator.Key="NEWS" FontSize="18"/>
+                        <ItemsControl ItemsSource="{Binding Path=News}">
+                            <ItemsControl.ItemTemplate>
+                                <DataTemplate>
+                                    <newsFeed:NewsItem Margin="5" News="{Binding Path=.}"/>
+                                </DataTemplate>
+                            </ItemsControl.ItemTemplate>
+                        </ItemsControl>
+                    </StackPanel>
+                </Grid>
             </Border>
             </Border>
         </ScrollViewer>
         </ScrollViewer>
     </Grid>
     </Grid>

+ 27 - 1
src/PixiEditor/Views/Dialogs/HelloTherePopup.xaml.cs

@@ -25,6 +25,24 @@ internal partial class HelloTherePopup : Window
     public static readonly DependencyProperty RecentlyOpenedEmptyProperty =
     public static readonly DependencyProperty RecentlyOpenedEmptyProperty =
         DependencyProperty.Register(nameof(RecentlyOpenedEmpty), typeof(bool), typeof(HelloTherePopup));
         DependencyProperty.Register(nameof(RecentlyOpenedEmpty), typeof(bool), typeof(HelloTherePopup));
 
 
+    public static readonly DependencyProperty IsFetchingNewsProperty = DependencyProperty.Register(
+        nameof(IsFetchingNews), typeof(bool), typeof(HelloTherePopup), new PropertyMetadata(default(bool)));
+
+    public bool IsFetchingNews
+    {
+        get { return (bool)GetValue(IsFetchingNewsProperty); }
+        set { SetValue(IsFetchingNewsProperty, value); }
+    }
+
+    public static readonly DependencyProperty FailedFetchingNewsProperty = DependencyProperty.Register(
+        nameof(FailedFetchingNews), typeof(bool), typeof(HelloTherePopup), new PropertyMetadata(false));
+
+    public bool FailedFetchingNews
+    {
+        get { return (bool)GetValue(FailedFetchingNewsProperty); }
+        set { SetValue(FailedFetchingNewsProperty, value); }
+    }
+
     public WpfObservableRangeCollection<News> News { get; set; } = new WpfObservableRangeCollection<News>();
     public WpfObservableRangeCollection<News> News { get; set; } = new WpfObservableRangeCollection<News>();
 
 
     public static string VersionText =>
     public static string VersionText =>
@@ -152,16 +170,24 @@ internal partial class HelloTherePopup : Window
 
 
         try
         try
         {
         {
+            IsFetchingNews = true;
             var news = await NewsProvider.FetchNewsAsync();
             var news = await NewsProvider.FetchNewsAsync();
             if (news is not null)
             if (news is not null)
             {
             {
+                IsFetchingNews = false;
                 News.Clear();
                 News.Clear();
                 News.AddRange(news);
                 News.AddRange(news);
             }
             }
+            else
+            {
+                IsFetchingNews = false;
+                FailedFetchingNews = true;
+            }
         }
         }
         catch
         catch
         {
         {
-            // TODO: Display error message
+            IsFetchingNews = false;
+            FailedFetchingNews = true;
         }
         }
     }
     }
 }
 }

+ 3 - 1
src/PixiEditor/Views/UserControls/NewsFeed/NewsItem.xaml

@@ -7,6 +7,7 @@
              xmlns:local="clr-namespace:PixiEditor.Views.UserControls.NewsFeed"
              xmlns:local="clr-namespace:PixiEditor.Views.UserControls.NewsFeed"
              xmlns:xaml="clr-namespace:PixiEditor.Models.Commands.XAML"
              xmlns:xaml="clr-namespace:PixiEditor.Models.Commands.XAML"
              xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
              xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
+             xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
              mc:Ignorable="d" Name="newsItem"
              mc:Ignorable="d" Name="newsItem"
              d:DesignHeight="300" d:DesignWidth="300">
              d:DesignHeight="300" d:DesignWidth="300">
     <Border Background="{StaticResource MainColor}" CornerRadius="5">
     <Border Background="{StaticResource MainColor}" CornerRadius="5">
@@ -14,7 +15,8 @@
             <Grid>
             <Grid>
                 <Border Background="White" Name="Mask" CornerRadius="8 8 0 0"/>
                 <Border Background="White" Name="Mask" CornerRadius="8 8 0 0"/>
                 <StackPanel>
                 <StackPanel>
-                    <Image Margin="-1" Source="{Binding ElementName=newsItem, Path=News.CoverImageUrl}"/>
+                    <Image Cursor="Hand" Margin="-1" Source="{Binding ElementName=newsItem, Path=News.CoverImageUrl}"
+                           MouseDown="CoverImageClicked"/>
                     <StackPanel.OpacityMask>
                     <StackPanel.OpacityMask>
                         <VisualBrush Visual="{Binding ElementName=Mask}" />
                         <VisualBrush Visual="{Binding ElementName=Mask}" />
                     </StackPanel.OpacityMask>
                     </StackPanel.OpacityMask>

+ 6 - 0
src/PixiEditor/Views/UserControls/NewsFeed/NewsItem.xaml.cs

@@ -1,5 +1,6 @@
 using System.Windows;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls;
+using System.Windows.Input;
 using PixiEditor.Models.Services.NewsFeed;
 using PixiEditor.Models.Services.NewsFeed;
 
 
 namespace PixiEditor.Views.UserControls.NewsFeed;
 namespace PixiEditor.Views.UserControls.NewsFeed;
@@ -18,5 +19,10 @@ internal partial class NewsItem : UserControl
     {
     {
         InitializeComponent();
         InitializeComponent();
     }
     }
+
+    private void CoverImageClicked(object sender, MouseButtonEventArgs e)
+    {
+        MiscViewModel.OpenHyperlink(News.Url);
+    }
 }
 }