1+ using Bloxstrap . Integrations ;
2+ using Microsoft . Win32 ;
13using System . Reflection ;
24using System . Security . Cryptography ;
35using System . Windows ;
6+ using System . Windows . Interop ;
7+ using System . Windows . Media ;
48using System . Windows . Shell ;
59using System . Windows . Threading ;
6- using Microsoft . Win32 ;
10+ using Wpf . Ui . Appearance ;
11+ using Wpf . Ui . Controls ;
712using Wpf . Ui . Hardware ;
8- using Bloxstrap . Integrations ;
9- using System . Windows . Interop ;
10- using System . Windows . Media ;
1113
1214namespace Bloxstrap
1315{
@@ -45,7 +47,8 @@ public partial class App : Application
4547
4648 public static Bootstrapper ? Bootstrapper { get ; set ; } = null ! ;
4749
48- public FroststrapRichPresence ? _froststrapRPC ;
50+ public FroststrapRichPresence RichPresence { get ; private set ; } = null ! ;
51+
4952 public static bool IsActionBuild => ! String . IsNullOrEmpty ( BuildMetadata . CommitRef ) ;
5053
5154 public static bool IsProductionBuild => IsActionBuild && BuildMetadata . CommitRef . StartsWith ( "tag" , StringComparison . Ordinal ) ;
@@ -58,7 +61,9 @@ public partial class App : Application
5861
5962 public static readonly Dictionary < string , BaseTask > PendingSettingTasks = new ( ) ;
6063
61- public static readonly JsonManager < Settings > Settings = new ( ) ;
64+ // Disambiguate Settings so we use the persistable Settings (Bloxstrap.Models.Persistable.Settings),
65+ // not the auto-generated Properties.Settings which doesn't contain the clicker fields.
66+ public static readonly JsonManager < Bloxstrap . Models . Persistable . Settings > Settings = new ( ) ;
6267
6368 public static readonly JsonManager < State > State = new ( ) ;
6469
@@ -70,11 +75,9 @@ public partial class App : Application
7075
7176 public static readonly GBSEditor GlobalSettings = new ( ) ;
7277
73- public static readonly HttpClient HttpClient = new (
74- new HttpClientLoggingHandler (
75- new HttpClientHandler { AutomaticDecompression = DecompressionMethods . All }
76- )
77- ) ;
78+ public static readonly CookiesManager Cookies = new ( ) ;
79+
80+ public static readonly HttpClient HttpClient = new ( new HttpClientLoggingHandler ( new HttpClientHandler { AutomaticDecompression = DecompressionMethods . All } ) ) ;
7881
7982
8083 private static bool _showingExceptionDialog = false ;
@@ -102,14 +105,6 @@ public static void Terminate(ErrorCode exitCode = ErrorCode.ERROR_SUCCESS)
102105 Environment . Exit ( exitCodeNum ) ;
103106 }
104107
105- public void CreateFroststrapRpcIfNeeded ( )
106- {
107- if ( Settings . Prop . ShowUsingFroststrapRPC && _froststrapRPC == null )
108- {
109- _froststrapRPC = new FroststrapRichPresence ( ) ;
110- }
111- }
112-
113108 public static void SoftTerminate ( ErrorCode exitCode = ErrorCode . ERROR_SUCCESS )
114109 {
115110 int exitCodeNum = ( int ) exitCode ;
@@ -161,6 +156,78 @@ public static void FinalizeExceptionHandling(Exception ex, bool log = true)
161156 Terminate ( ErrorCode . ERROR_INSTALL_FAILURE ) ;
162157 }
163158
159+ public static FroststrapRichPresence ? FrostRPC
160+ {
161+ get => ( Current as App ) ? . RichPresence ;
162+ set
163+ {
164+ if ( Current is App app )
165+ app . RichPresence = value ! ;
166+ }
167+ }
168+
169+ private async Task PreloadAccountManagerAsync ( )
170+ {
171+ const string LOG_IDENT = "App::PreloadAccountManager" ;
172+
173+ try
174+ {
175+ Logger . WriteLine ( LOG_IDENT , "Preloading account manager data..." ) ;
176+
177+ var accountManager = new AccountManager ( ) ;
178+
179+ if ( accountManager . ActiveAccount != null )
180+ {
181+ Logger . WriteLine ( LOG_IDENT , $ "Preloaded active account: { accountManager . ActiveAccount . Username } ") ;
182+
183+ AccountManager . PreloadedInstance = accountManager ;
184+ }
185+
186+ Logger . WriteLine ( LOG_IDENT , "Account manager preloading completed" ) ;
187+ }
188+ catch ( Exception ex )
189+ {
190+ Logger . WriteException ( LOG_IDENT , ex ) ;
191+ }
192+ }
193+
194+ public static void WindowsBackdrop ( )
195+ {
196+ Current . Dispatcher . Invoke ( ( ) =>
197+ {
198+ var backdropType = App . Settings . Prop . SelectedBackdrop ;
199+ ApplyBackdropToAllWindows ( backdropType ) ;
200+ } ) ;
201+ }
202+
203+ private static void ApplyBackdropToAllWindows ( UIBackgroundType backdropType )
204+ {
205+ var wpfBackdrop = backdropType switch
206+ {
207+ UIBackgroundType . None => BackgroundType . None ,
208+ UIBackgroundType . Mica => BackgroundType . Mica ,
209+ UIBackgroundType . Acrylic => BackgroundType . Acrylic ,
210+ UIBackgroundType . Aero => BackgroundType . Aero ,
211+ _ => BackgroundType . None
212+ } ;
213+
214+ foreach ( Window window in Current . Windows )
215+ {
216+ if ( window is UiWindow uiWindow )
217+ {
218+ bool isTransparentBackdrop = ( wpfBackdrop == BackgroundType . Acrylic || wpfBackdrop == BackgroundType . Aero ) ;
219+
220+ uiWindow . AllowsTransparency = isTransparentBackdrop ;
221+
222+ uiWindow . WindowStyle = isTransparentBackdrop
223+ ? WindowStyle . None
224+ : WindowStyle . SingleBorderWindow ;
225+
226+ uiWindow . WindowBackdropType = wpfBackdrop ;
227+ }
228+ }
229+ }
230+
164231 public void ApplyCustomFontToWindow ( Window window )
165232 {
166233 var fontPath = App . Settings . Prop . CustomFontPath ;
@@ -421,6 +488,11 @@ protected override void OnStartup(StartupEventArgs e)
421488 FastFlags . Load ( ) ;
422489 GlobalSettings . Load ( ) ;
423490
491+ _ = PreloadAccountManagerAsync ( ) ;
492+
493+ if ( Settings . Prop . AllowCookieAccess )
494+ Task . Run ( Cookies . LoadCookies ) ;
495+
424496 if ( ! Locale . SupportedLocales . ContainsKey ( Settings . Prop . Locale ) )
425497 {
426498 Settings . Prop . Locale = "nil" ;
@@ -444,7 +516,7 @@ protected override void OnStartup(StartupEventArgs e)
444516
445517 protected override void OnExit ( ExitEventArgs e )
446518 {
447- _froststrapRPC ? . Dispose ( ) ;
519+ RichPresence ? . Dispose ( ) ;
448520 base . OnExit ( e ) ;
449521 }
450522 }
0 commit comments