77using Avalonia . Platform ;
88using Avalonia . Styling ;
99using Ps3DiscDumper ;
10+ using Ps3DiscDumper . Utils ;
1011using UI . Avalonia . Utils . ColorPalette ;
1112using UI . Avalonia . ViewModels ;
1213using UI . Avalonia . Views ;
@@ -33,26 +34,33 @@ public override void OnFrameworkInitializationCompleted()
3334 {
3435 if ( ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop )
3536 {
36- var vm = new MainWindowViewModel ( ) ;
37-
38- var systemFonts = FontManager . Current . SystemFonts ;
39- if ( systemFonts . TryGetGlyphTypeface ( "Segoe Fluent Icons" , FontStyle . Normal , FontWeight . Normal , FontStretch . Normal , out _ ) )
40- vm . CurrentPage . SymbolFontFamily = new ( "Segoe Fluent Icons" ) ;
41- if ( systemFonts . TryGetGlyphTypeface ( "Segoe UI Variable Small" , FontStyle . Normal , FontWeight . Normal , FontStretch . Normal , out _ ) )
42- vm . CurrentPage . SmallFontFamily = new ( "Segoe UI Variable Small" ) ;
43- if ( systemFonts . TryGetGlyphTypeface ( "Segoe UI Variable Display" , FontStyle . Normal , FontWeight . Normal , FontStretch . Normal , out _ ) )
44- vm . CurrentPage . LargeFontFamily = new ( "Segoe UI Variable Display" ) ;
45-
46- var w = new MainWindow { DataContext = vm , } ;
37+ var safeToRun = SecurityEx . IsSafe ( desktop . Args ) ;
38+ Window w ;
39+ ViewModelBase vm ;
40+ if ( safeToRun )
41+ {
42+ var mainViewModel = new MainWindowViewModel ( ) ;
43+ vm = mainViewModel . CurrentPage ;
44+ SetSymbolFont ( vm ) ;
45+ w = new MainWindow { DataContext = mainViewModel } ;
46+ }
47+ else
48+ {
49+ vm = new ErrorStubViewModel ( ) ;
50+ SetSymbolFont ( vm ) ;
51+ w = new ErrorStub { DataContext = vm } ;
52+ }
4753 desktop . MainWindow = w ;
4854 desktop . MainWindow . Activated += OnActivated ;
4955 desktop . MainWindow . Deactivated += OnDeactivated ;
5056 desktop . MainWindow . ActualThemeVariantChanged += OnThemeChanged ;
5157 if ( w . PlatformSettings is { } ps )
5258 ps . ColorValuesChanged += OnPlatformColorsChanged ;
5359
54- vm . CurrentPage . MicaEnabled = isMicaCapable . Value ;
55- vm . CurrentPage . AcrylicEnabled = w . ActualTransparencyLevel == WindowTransparencyLevel . AcrylicBlur ;
60+ vm . MicaEnabled = isMicaCapable . Value ;
61+ vm . AcrylicEnabled = w . ActualTransparencyLevel == WindowTransparencyLevel . AcrylicBlur ;
62+
63+ var systemFonts = FontManager . Current . SystemFonts ;
5664 if ( systemFonts . TryGetGlyphTypeface ( "Segoe UI Variable Text" , FontStyle . Normal , FontWeight . Normal , FontStretch . Normal , out _ ) )
5765 w . FontFamily = new ( "Segoe UI Variable Text" ) ;
5866 else if ( systemFonts . TryGetGlyphTypeface ( "Segoe UI" , FontStyle . Normal , FontWeight . Normal , FontStretch . Normal , out _ ) )
@@ -61,6 +69,17 @@ public override void OnFrameworkInitializationCompleted()
6169 base . OnFrameworkInitializationCompleted ( ) ;
6270 }
6371
72+ private static void SetSymbolFont ( ViewModelBase vm )
73+ {
74+ var systemFonts = FontManager . Current . SystemFonts ;
75+ if ( systemFonts . TryGetGlyphTypeface ( "Segoe Fluent Icons" , FontStyle . Normal , FontWeight . Normal , FontStretch . Normal , out _ ) )
76+ vm . SymbolFontFamily = new ( "Segoe Fluent Icons" ) ;
77+ if ( systemFonts . TryGetGlyphTypeface ( "Segoe UI Variable Small" , FontStyle . Normal , FontWeight . Normal , FontStretch . Normal , out _ ) )
78+ vm . SmallFontFamily = new ( "Segoe UI Variable Small" ) ;
79+ if ( systemFonts . TryGetGlyphTypeface ( "Segoe UI Variable Display" , FontStyle . Normal , FontWeight . Normal , FontStretch . Normal , out _ ) )
80+ vm . LargeFontFamily = new ( "Segoe UI Variable Display" ) ;
81+ }
82+
6483 private void OnActivated ( object ? sender , EventArgs e )
6584 {
6685 if ( sender is not Window w )
@@ -85,10 +104,16 @@ private void OnDeactivated(object? sender, EventArgs e)
85104
86105 internal static void OnThemeChanged ( object ? sender , EventArgs e )
87106 {
88- if ( sender is not Window { DataContext : MainWindowViewModel { CurrentPage : ViewModelBase vm } } window )
107+ Window w ;
108+ ViewModelBase vm ;
109+ if ( sender is Window { DataContext : MainWindowViewModel { CurrentPage : { } vm1 } } w1 )
110+ ( w , vm ) = ( w1 , vm1 ) ;
111+ else if ( sender is Window { DataContext : ViewModelBase vm2 } w2 )
112+ ( w , vm ) = ( w2 , vm2 ) ;
113+ else
89114 return ;
90115
91- if ( window . ActualThemeVariant == ThemeVariant . Light )
116+ if ( w . ActualThemeVariant == ThemeVariant . Light )
92117 {
93118 vm . TintColor = ThemeConsts . LightThemeTintColor ;
94119 vm . TintOpacity = ThemeConsts . LightThemeTintOpacity ;
@@ -97,7 +122,7 @@ internal static void OnThemeChanged(object? sender, EventArgs e)
97122 vm . Layer2GroundedColor = ThemeConsts . LightThemeLayer2Grounded ;
98123 vm . ColorPalette = ThemeConsts . Light ;
99124 }
100- else if ( window . ActualThemeVariant == ThemeVariant . Dark )
125+ else if ( w . ActualThemeVariant == ThemeVariant . Dark )
101126 {
102127 vm . TintColor = ThemeConsts . DarkThemeTintColor ;
103128 vm . TintOpacity = ThemeConsts . DarkThemeTintOpacity ;
@@ -107,8 +132,8 @@ internal static void OnThemeChanged(object? sender, EventArgs e)
107132 vm . ColorPalette = ThemeConsts . Dark ;
108133 }
109134 }
110-
111-
135+
136+
112137 internal static void OnPlatformColorsChanged ( object ? sender , PlatformColorValues e )
113138 {
114139 if ( Current ? . ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime
0 commit comments