11using FluentDL . Activation ;
22using FluentDL . Contracts . Services ;
3+ using FluentDL . Helpers ;
4+ using FluentDL . ViewModels ;
35using FluentDL . Views ;
46
57using Microsoft . UI . Xaml ;
@@ -24,23 +26,32 @@ public ActivationService(ActivationHandler<LaunchActivatedEventArgs> defaultHand
2426
2527 public async Task ActivateAsync ( object activationArgs )
2628 {
27- // Execute tasks before activation.
28- await InitializeAsync ( ) ;
29-
30- // Set the MainWindow Content.
29+ // Show splash screen immediately
30+ var splashScreen = App . GetService < SplashScreenPage > ( ) ;
3131 if ( App . MainWindow . Content == null )
3232 {
33- _shell = App . GetService < ShellPage > ( ) ;
34- App . MainWindow . Content = _shell ?? new Frame ( ) ;
33+ App . MainWindow . Content = splashScreen ;
34+ App . MainWindow . Activate ( ) ;
3535 }
3636
37- // Handle activation via ActivationHandlers.
37+ // Execute tasks before activation
38+ await InitializeAsync ( ) ;
39+
40+ // Initialize shell behind splash screen
41+ _shell = App . GetService < ShellPage > ( ) ;
42+
43+ // Handle activation via ActivationHandlers
3844 await HandleActivationAsync ( activationArgs ) ;
3945
40- // Activate the MainWindow.
46+ // Initialize APIs
47+ await InitAPIs ( ) ;
48+
49+ // Switch from splash screen to shell
50+ App . MainWindow . Content = _shell ?? new Frame ( ) ;
4151 App . MainWindow . Activate ( ) ;
52+ App . MainWindow . Closed += ( s , e ) => QueueSaver . Close ( ) ;
4253
43- // Execute tasks after activation.
54+ // Execute tasks after activation
4455 await StartupAsync ( ) ;
4556 }
4657
@@ -70,4 +81,48 @@ private async Task StartupAsync()
7081 await _themeSelectorService . SetRequestedThemeAsync ( ) ;
7182 await Task . CompletedTask ;
7283 }
84+
85+ private async Task InitAPIs ( )
86+ {
87+ if ( await SettingsViewModel . GetSetting < bool ? > ( SettingsViewModel . FirstRun ) ?? true )
88+ await SettingsViewModel . SetMissingDefaults ( ) ;
89+
90+ await QueueViewModel . UpdateShortcutVisibility ( ) ;
91+ try
92+ {
93+ // Fetch previous command list
94+ await LocalCommands . Init ( ) ;
95+
96+ // Initialize FFMpeg
97+ await FFmpegRunner . Initialize ( ) ;
98+
99+ // Initialize environment variables
100+ await KeyReader . Initialize ( ) ;
101+
102+ // Initialize api objects
103+ var localSettings = App . GetService < ILocalSettingsService > ( ) ;
104+
105+ var qobuzEmail = DPAPIHelper . Decrypt ( await localSettings . ReadSettingAsync < string > ( SettingsViewModel . QobuzEmail ) ?? "" ) ;
106+ var qobuzPassword = DPAPIHelper . Decrypt ( await localSettings . ReadSettingAsync < string > ( SettingsViewModel . QobuzPassword ) ?? "" ) ;
107+ var qobuzId = await localSettings . ReadSettingAsync < string > ( SettingsViewModel . QobuzId ) ;
108+ var qobuzToken = await localSettings . ReadSettingAsync < string > ( SettingsViewModel . QobuzToken ) ;
109+ var qobuzAppId = await localSettings . ReadSettingAsync < string > ( SettingsViewModel . QobuzAppId ) ;
110+ var qobuzAppSecret = await localSettings . ReadSettingAsync < string > ( SettingsViewModel . QobuzAppSecret ) ;
111+ var spotifyClientId = await localSettings . ReadSettingAsync < string > ( SettingsViewModel . SpotifyClientId ) ;
112+ var spotifyClientSecret = await localSettings . ReadSettingAsync < string > ( SettingsViewModel . SpotifyClientSecret ) ;
113+ var deezerArl = await localSettings . ReadSettingAsync < string > ( SettingsViewModel . DeezerARL ) ;
114+ await Task . WhenAll (
115+ Task . Run ( ( ) => QobuzApi . Initialize ( qobuzEmail , qobuzPassword , qobuzId , qobuzToken , qobuzAppId , qobuzAppSecret ) ) ,
116+ Task . Run ( ( ) => SpotifyApi . Initialize ( spotifyClientId , spotifyClientSecret ) ) ,
117+ DeezerApi . InitDeezerClient ( deezerArl )
118+ ) ;
119+ await QueueViewModel . LoadSaveQueue ( ) ;
120+
121+ QueueSaver . Init ( ) ;
122+ }
123+ catch ( Exception e )
124+ {
125+ Debug . WriteLine ( e ) ;
126+ }
127+ }
73128}
0 commit comments