Преглед изворни кода

Show loading window on different thread and changed it's design

CPKreuz пре 2 година
родитељ
комит
0a018409c8

+ 4 - 5
src/PixiEditor/App.xaml.cs

@@ -55,8 +55,7 @@ internal partial class App : Application
         }
         #endif
 
-        LoadingWindow loadingWindow = new();
-        loadingWindow.Show();
+        LoadingWindow.ShowInNewThread();
 
         AddNativeAssets();
 
@@ -66,11 +65,11 @@ internal partial class App : Application
         extensionLoader.LoadExtensions();
 
         MainWindow = new MainWindow(extensionLoader);
-        MainWindow.ContentRendered += (sender, args) =>
+        MainWindow.ContentRendered += (_, _) =>
         {
-            loadingWindow.Close();
+            LoadingWindow.Instance.SafeClose();
+            MainWindow.Activate();
         };
-
         MainWindow.Show();
     }
 

+ 17 - 8
src/PixiEditor/Views/LoadingWindow.xaml

@@ -7,12 +7,21 @@
         xmlns:gif="http://wpfanimatedgif.codeplex.com"
         mc:Ignorable="d" ShowInTaskbar="False" WindowStyle="None"
         ResizeMode="NoResize" WindowStartupLocation="CenterScreen"
-        Title="LoadingWindow" Height="200" Width="200">
-    <Grid Background="{StaticResource MainColor}">
-        <Image
-            gif:ImageBehavior.AnimatedSource="/Images/Processing.gif"
-            HorizontalAlignment="Center" VerticalAlignment="Center"
-            Height="50"
-            gif:ImageBehavior.AnimationSpeedRatio="1.5"/>
-    </Grid>
+        Title="LoadingWindow" Height="180" Width="160"
+        Background="Transparent"
+        AllowsTransparency="True"
+        x:Name="Window">
+    <Border Background="{StaticResource AccentColor}"
+            BorderBrush="{StaticResource MainColor}" BorderThickness="1.5"
+            CornerRadius="10">
+        <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
+            <Image
+                gif:ImageBehavior.AnimatedSource="{Binding LoadingImage, ElementName=Window}"
+                Height="70"
+                gif:ImageBehavior.AnimationSpeedRatio="1.5"/>
+            <TextBlock Foreground="White" Text="PixiEditor"
+                       FontFamily="Roboto" FontWeight="900" FontSize="28"
+                       Margin="0,10,0,0"/>
+        </StackPanel>
+    </Border>
 </Window>

+ 31 - 0
src/PixiEditor/Views/LoadingWindow.xaml.cs

@@ -1,12 +1,43 @@
 using System.Windows;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Threading;
 
 namespace PixiEditor.Views;
 
 public partial class LoadingWindow : Window
 {
+    public static LoadingWindow Instance { get; private set; }
+
+    public ImageSource LoadingImage { get; } = new BitmapImage(new Uri("pack://application:,,,/images/processing.gif"));
+    
     public LoadingWindow()
     {
         InitializeComponent();
     }
+
+    public static void ShowInNewThread()
+    {
+        var thread = new Thread(ThreadStart) { IsBackground = true };
+
+        thread.SetApartmentState(ApartmentState.STA);
+        thread.Start();
+    }
+
+    public void SafeClose()
+    {
+        Dispatcher.Invoke(Close);
+    }
+
+    private static void ThreadStart()
+    {
+        Instance = new LoadingWindow();
+        Instance.Show();
+
+        Instance.Closed += (_, _) =>
+            Instance.Dispatcher.InvokeShutdown();
+
+        Dispatcher.Run();
+    }
 }
 

+ 0 - 1
src/PixiEditor/Views/UserControls/SteamOverlay.xaml.cs

@@ -15,7 +15,6 @@ public partial class SteamOverlay : UserControl
     }
 
     private void CreateFadeTimer()
-    
     {
         StopFadeTimer();
         _fadeTimer = new DispatcherTimer(DispatcherPriority.Render) { Interval = TimeSpan.FromSeconds(1f) };