Krzysztof Krysiński пре 1 месец
родитељ
комит
071850d3f1

+ 1 - 1
src/PixiEditor.OperatingSystem/IOperatingSystem.cs

@@ -5,7 +5,7 @@ namespace PixiEditor.OperatingSystem;
 
 public interface IOperatingSystem
 {
-    public static IOperatingSystem Current { get; protected set; }
+    public static IOperatingSystem? Current { get; protected set; }
     public string Name { get; }
 
     public virtual string AnalyticsName => Environment.OSVersion.ToString();

+ 1 - 1
src/PixiEditor.Platform/IPlatform.cs

@@ -4,7 +4,7 @@ namespace PixiEditor.Platform;
 
 public interface IPlatform
 {
-    public static IPlatform Current { get; private set; }
+    public static IPlatform? Current { get; private set; }
     public abstract string Id { get; }
     public abstract string Name { get; }
     public bool PerformHandshake();

+ 29 - 12
src/PixiEditor.UI.Common/Localization/Translator.cs

@@ -32,32 +32,46 @@ public class Translator : Control
     public static readonly AttachedProperty<bool> UseLanguageFlowDirectionProperty =
         AvaloniaProperty.RegisterAttached<Translator, Control, bool>("UseLanguageFlowDirection");
 
-    public static void SetUseLanguageFlowDirection(Control obj, bool value) => obj.SetValue(UseLanguageFlowDirectionProperty, value);
+    public static void SetUseLanguageFlowDirection(Control obj, bool value) =>
+        obj.SetValue(UseLanguageFlowDirectionProperty, value);
+
     public static bool GetUseLanguageFlowDirection(Control obj) => obj.GetValue(UseLanguageFlowDirectionProperty);
 
     static Translator()
     {
-        IObserver<AvaloniaPropertyChangedEventArgs<string>> keyObserver = new AnonymousObserver<AvaloniaPropertyChangedEventArgs<string>>(KeyPropertyChanged);
+        IObserver<AvaloniaPropertyChangedEventArgs<string>> keyObserver =
+            new AnonymousObserver<AvaloniaPropertyChangedEventArgs<string>>(KeyPropertyChanged);
         KeyProperty.Changed.Subscribe(keyObserver);
 
-        IObserver<AvaloniaPropertyChangedEventArgs<LocalizedString>> localizedStringObserver = new AnonymousObserver<AvaloniaPropertyChangedEventArgs<LocalizedString>>(LocalizedStringPropertyChanged);
+        IObserver<AvaloniaPropertyChangedEventArgs<LocalizedString>> localizedStringObserver =
+            new AnonymousObserver<AvaloniaPropertyChangedEventArgs<LocalizedString>>(LocalizedStringPropertyChanged);
         LocalizedStringProperty.Changed.Subscribe(localizedStringObserver);
 
-        IObserver<AvaloniaPropertyChangedEventArgs<object>> enumObserver = new AnonymousObserver<AvaloniaPropertyChangedEventArgs<object>>(EnumPropertyChanged);
+        IObserver<AvaloniaPropertyChangedEventArgs<object>> enumObserver =
+            new AnonymousObserver<AvaloniaPropertyChangedEventArgs<object>>(EnumPropertyChanged);
         EnumProperty.Changed.Subscribe(enumObserver);
 
-        IObserver<AvaloniaPropertyChangedEventArgs<string>> tooltipKeyObserver = new AnonymousObserver<AvaloniaPropertyChangedEventArgs<string>>(TooltipKeyPropertyChanged);
+        IObserver<AvaloniaPropertyChangedEventArgs<string>> tooltipKeyObserver =
+            new AnonymousObserver<AvaloniaPropertyChangedEventArgs<string>>(TooltipKeyPropertyChanged);
         TooltipKeyProperty.Changed.Subscribe(tooltipKeyObserver);
 
-        IObserver<AvaloniaPropertyChangedEventArgs<LocalizedString>> tooltipLocalizedStringObserver = new AnonymousObserver<AvaloniaPropertyChangedEventArgs<LocalizedString>>(TooltipLocalizedStringPropertyChanged);
+        IObserver<AvaloniaPropertyChangedEventArgs<LocalizedString>> tooltipLocalizedStringObserver =
+            new AnonymousObserver<AvaloniaPropertyChangedEventArgs<LocalizedString>>(
+                TooltipLocalizedStringPropertyChanged);
         TooltipLocalizedStringProperty.Changed.Subscribe(tooltipLocalizedStringObserver);
 
-        IObserver<AvaloniaPropertyChangedEventArgs<bool>> useLanguageFlowDirectionObserver = new AnonymousObserver<AvaloniaPropertyChangedEventArgs<bool>>(UseLanguageFlowDirectionPropertyChanged);
+        IObserver<AvaloniaPropertyChangedEventArgs<bool>> useLanguageFlowDirectionObserver =
+            new AnonymousObserver<AvaloniaPropertyChangedEventArgs<bool>>(UseLanguageFlowDirectionPropertyChanged);
         UseLanguageFlowDirectionProperty.Changed.Subscribe(useLanguageFlowDirectionObserver);
     }
 
     private static void UseLanguageFlowDirectionPropertyChanged(AvaloniaPropertyChangedEventArgs<bool> obj)
     {
+        if (ILocalizationProvider.Current == null)
+        {
+            return;
+        }
+
         if (!obj.NewValue.Value)
         {
             obj.Sender.SetValue(Control.FlowDirectionProperty, FlowDirection.LeftToRight);
@@ -72,7 +86,8 @@ public class Translator : Control
 
     private static void OnLanguageChangedFlowDirection(AvaloniaObject objSender)
     {
-        objSender.SetValue(Control.FlowDirectionProperty, ILocalizationProvider.Current?.CurrentLanguage.FlowDirection ?? FlowDirection.LeftToRight);
+        objSender.SetValue(Control.FlowDirectionProperty,
+            ILocalizationProvider.Current?.CurrentLanguage.FlowDirection ?? FlowDirection.LeftToRight);
     }
 
     private static void TooltipLocalizedStringPropertyChanged(AvaloniaPropertyChangedEventArgs<LocalizedString> e)
@@ -159,17 +174,19 @@ public class Translator : Control
 
     private static void UpdateKey(AvaloniaObject d, string key)
     {
-        if(key == null) return;
+        if (key == null) return;
         var parameters = GetLocalizedString(d).Parameters;
         LocalizedString localizedString = new(key, parameters);
 
         var valueObservable = d.GetObservable(ValueProperty);
 
-        ExternalProperty externalProperty = ExternalProperties.FirstOrDefault(x => x.PropertyType.IsAssignableFrom(d.GetType()));
+        ExternalProperty externalProperty =
+            ExternalProperties.FirstOrDefault(x => x.PropertyType.IsAssignableFrom(d.GetType()));
 
         if (d is ICustomTranslatorElement customTranslatorElement)
         {
-            customTranslatorElement.SetTranslationBinding(customTranslatorElement.GetDependencyProperty(), valueObservable);
+            customTranslatorElement.SetTranslationBinding(customTranslatorElement.GetDependencyProperty(),
+                valueObservable);
         }
         else if (externalProperty != null)
         {
@@ -220,7 +237,7 @@ public class Translator : Control
         {
             throw new ArgumentException($"'{d.GetType().Name}' does not support {nameof(Translator)}.Key");
         }
-        #endif
+#endif
 
         d.SetValue(ValueProperty, localizedString.Value);
     }

+ 5 - 1
src/PixiEditor/Initialization/ClassicDesktopEntry.cs

@@ -173,6 +173,9 @@ internal class ClassicDesktopEntry
 
     private void InitPlatform()
     {
+        if (IPlatform.Current != null)
+            return;
+
         var platform = GetActivePlatform();
         IPlatform.RegisterPlatform(platform);
         platform.PerformHandshake();
@@ -222,7 +225,8 @@ internal class ClassicDesktopEntry
 
     private void InitOperatingSystem()
     {
-        IOperatingSystem.RegisterOS(GetActiveOperatingSystem());
+        if (IOperatingSystem.Current == null)
+            IOperatingSystem.RegisterOS(GetActiveOperatingSystem());
     }
 
     private IOperatingSystem GetActiveOperatingSystem()

+ 9 - 5
src/PixiEditor/ViewModels/CrashReportViewModel.cs

@@ -8,6 +8,7 @@ using PixiEditor.Initialization;
 using PixiEditor.Models.Controllers;
 using PixiEditor.Models.Dialogs;
 using PixiEditor.Models.ExceptionHandling;
+using PixiEditor.Platform;
 using PixiEditor.UI.Common.Localization;
 using PixiEditor.Views;
 using PixiEditor.Views.Dialogs;
@@ -82,11 +83,14 @@ internal partial class CrashReportViewModel : Window
     [RelayCommand]
     public void RunInSafeMode()
     {
-        var app = (App)Application.Current;
-        ClassicDesktopEntry entry = new(app.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime);
-        StartupArgs.Args = new List<string> { "--safeMode" };
-        var window = new MainWindow(entry.InitApp(true), null);
-        Application.Current.Run(window);
+        (Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.Shutdown();
+        Process.Start(
+            new ProcessStartInfo
+            {
+                FileName = Process.GetCurrentProcess().MainModule?.FileName ?? string.Empty,
+                Arguments = "--safeMode",
+                UseShellExecute = true
+            });
     }
 
     public bool CanRecoverDocuments()

+ 1 - 1
src/PixiEditor/Views/Dialogs/CrashReportDialog.axaml

@@ -36,7 +36,7 @@
                         Command="{Binding RecoverDocumentsCommand}">
                     Recover files
                 </Button>
-                <Button Margin="5,0,5,0" Width="120"
+                <Button Width="120"
                         Command="{Binding RunInSafeModeCommand}">
                     Safe mode
                 </Button>